I am somewhat out of my depth here but hopefully I can provide enough information to be of use…
I have just updated my Ubuntu OS from 18.04.5 LTS to 20.04.1 LTS, part of which involved the updating of MySQL from (I think) v5.7.32 to v8.0.22. After the OS update MySQL fails to start, and looking at its logfile it appears to be down to a ‘Data Dictionary’ update in relation to Roundcube’s database:
2021-01-04T11:40:49.066536Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.22-0ubuntu0.20.04.3) starting as process 30440
2021-01-04T11:40:49.075527Z 1 [System] [MY-011012] [Server] Starting upgrade of data directory.
2021-01-04T11:40:49.075597Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-01-04T11:40:50.759379Z 1 [ERROR] [MY-012592] [InnoDB] Operating system error number 2 in a file operation.
2021-01-04T11:40:50.759584Z 1 [ERROR] [MY-012593] [InnoDB] The error means the system cannot find the path specified.
2021-01-04T11:40:50.759771Z 1 [ERROR] [MY-012216] [InnoDB] Cannot open datafile for read-only: ‘./roundcube/carddav_addressbooks.ibd’ OS error: 71
2021-01-04T11:40:50.759958Z 1 [Warning] [MY-012019] [InnoDB] Ignoring tablespace roundcube/carddav_addressbooks
because it could not be opened.
2021-01-04T11:40:50.760185Z 1 [ERROR] [MY-012592] [InnoDB] Operating system error number 2 in a file operation.
2021-01-04T11:40:50.760383Z 1 [ERROR] [MY-012593] [InnoDB] The error means the system cannot find the path specified.
2021-01-04T11:40:50.760581Z 1 [ERROR] [MY-012216] [InnoDB] Cannot open datafile for read-only: ‘./roundcube/carddav_contacts.ibd’ OS error: 71
2021-01-04T11:40:50.760781Z 1 [Warning] [MY-012019] [InnoDB] Ignoring tablespace roundcube/carddav_contacts
because it could not be opened.
2021-01-04T11:40:50.761018Z 1 [ERROR] [MY-012592] [InnoDB] Operating system error number 2 in a file operation.
2021-01-04T11:40:50.761228Z 1 [ERROR] [MY-012593] [InnoDB] The error means the system cannot find the path specified.
2021-01-04T11:40:50.761436Z 1 [ERROR] [MY-012216] [InnoDB] Cannot open datafile for read-only: ‘./roundcube/carddav_group_user.ibd’ OS error: 71
2021-01-04T11:40:50.761675Z 1 [Warning] [MY-012019] [InnoDB] Ignoring tablespace roundcube/carddav_group_user
because it could not be opened.
2021-01-04T11:40:50.761834Z 1 [ERROR] [MY-012592] [InnoDB] Operating system error number 2 in a file operation.
2021-01-04T11:40:50.761973Z 1 [ERROR] [MY-012593] [InnoDB] The error means the system cannot find the path specified.
2021-01-04T11:40:50.762114Z 1 [ERROR] [MY-012216] [InnoDB] Cannot open datafile for read-only: ‘./roundcube/carddav_groups.ibd’ OS error: 71
2021-01-04T11:40:50.762255Z 1 [Warning] [MY-012019] [InnoDB] Ignoring tablespace roundcube/carddav_groups
because it could not be opened.
2021-01-04T11:40:50.762420Z 1 [ERROR] [MY-012592] [InnoDB] Operating system error number 2 in a file operation.
2021-01-04T11:40:50.762569Z 1 [ERROR] [MY-012593] [InnoDB] The error means the system cannot find the path specified.
2021-01-04T11:40:50.762717Z 1 [ERROR] [MY-012216] [InnoDB] Cannot open datafile for read-only: ‘./roundcube/carddav_migrations.ibd’ OS error: 71
2021-01-04T11:40:50.762866Z 1 [Warning] [MY-012019] [InnoDB] Ignoring tablespace roundcube/carddav_migrations
because it could not be opened.
2021-01-04T11:40:50.763041Z 1 [ERROR] [MY-012592] [InnoDB] Operating system error number 2 in a file operation.
2021-01-04T11:40:50.763181Z 1 [ERROR] [MY-012593] [InnoDB] The error means the system cannot find the path specified.
2021-01-04T11:40:50.763321Z 1 [ERROR] [MY-012216] [InnoDB] Cannot open datafile for read-only: ‘./roundcube/carddav_xsubtypes.ibd’ OS error: 71
2021-01-04T11:40:50.763462Z 1 [Warning] [MY-012019] [InnoDB] Ignoring tablespace roundcube/carddav_xsubtypes
because it could not be opened.
2021-01-04T11:40:50.787032Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-01-04T11:40:52.850454Z 1 [ERROR] [MY-011006] [Server] Got error 197 from SE while migrating tablespaces.
2021-01-04T11:40:52.853184Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
2021-01-04T11:40:52.853689Z 0 [ERROR] [MY-010119] [Server] Aborting
With MySQL failing to start this obviously prevents Roundcube, and my other services with SQL databases, from functioning.
Is there any other information I can provide that would help diagnose/solve the issue?
Author: Fu Xiang
Now living in Zhuhai, mainly responsible for the maintenance of Oracle, MySQL, mongoDB and Redis.
Source of this article: original submission
* Produced by the Aikesheng open source community, original content is not allowed to be used without authorization, please contact the editor and indicate the source for reprinting.
1. Background
The current zabbix system mysql version 5.6, the data volume is about 1.5T, there are some large tables partitioned by day, the operation of adding fields will be very time-consuming, I have encountered adding a field to a history table of several hundred GB. Using the pt-osc tool, ran
It was not finished in 2 days; in order to use the immediate addition function of mysql 8.0, I decided to upgrade to mysql 8.0.
2. Upgrade process
Because the amount of data is relatively large, the data logic export and import method will be very slow to upgrade. It is not recommended, so the In-Place method is used to upgrade. According to the upgrade path provided by the official document, you need to upgrade from 5.6 to 5.7, and then upgrade to 8.0. .
The upgrade from 5.6 to 5.7.35 is very smooth. When upgrading from 5.7.35 to 8.0.25, the upgrade fails with an error message such as
Down:
2021-07-20T07:33:18.138368Z 1 [ERROR] [MY-011006] [Server] Got error 197 from SE
while migrating tablespaces.
2021-07-20T07:33:18.145105Z 0 [ERROR] [MY-010020] [Server] Data Dictionary
initialization failed.
2021-07-20T07:33:18.145502Z 0 [ERROR] [MY-010119] [Server] Aborting
2021-07-20T07:33:40.435143Z 0 [System] [MY-010910] [Server]
/usr/local/mysql/bin/mysqld: Shutdown complete (mysqld 8.0.25) MySQL Community
Server - GPL.
Judging from the error message alone, it seems that the tablespace migration failed, and the data dictionary could not be initialized, causing mysql to fail to start. This raises a question: Why is it okay to upgrade to 5.7?
3. Resolution process
In the case that the error message is not obvious, I dropped a few mysql 8.0 minor version upgrade tests, and finally got a valuable error message in 8.0.15:
2021-07-20T12:25:06.672826Z 1 [ERROR] [MY-011014] [Server] Found partially
upgraded DD. Aborting upgrade and deleting all DD tables. Start the upgrade
process again.
2021-07-20T12:25:06.773766Z 1 [Warning] [MY-012351] [InnoDB] Tablespace 7314,
name 'zabbix/#sql-ib104-715696445', file './zabbix/#sql-ib104-715696445.ibd' is
missing!
2021-07-20T12:25:06.834751Z 0 [ERROR] [MY-010020] [Server] Data Dictionary
initialization failed.
Before 8.0, the data dictionary information was distributed in three places: the server layer, the system tables under the mysql library, and the InnoDB internal system tables. The data dictionary was stored separately, and DDL was not atomic.
After 8.0, all metadata information is stored in InnoDB dictionary table and stored in a separate table space mysql.ibd. DDL is atomic.
Because the data dictionary management and storage methods have changed, upgrading to 8.0 data dictionary requires migration and conversion, so 5.6->5.7 is no problem, 5.7->8.0 is caused by the missing ./zabbix/#sql-ib104-715696445.ibd file Upgrade failed.
The #sql-ib104-715696445.ibd file does not exist in the zabbix database directory of the current environment, there is only one frm file starting with #sql-
[root@GZ-DB-6CU552YR4V zabbix]# ls -l ./#sql*
-rw-rw---- 1 mysql mysql 8808 5 9 2020 ./#sql-8427_2008.frm
[root@GZ-DB-6CU552YR4V zabbix]#
The frm file can be parsed through mysqlfrm and dbsake. This article is parsed through dbsake:
./dbsake frmdump ./#sql-8427_2008.frm
-- Table structure for table `#sql-8427_2008`
-- Created with MySQL Version xxxxxx
CREATE TABLE `#sql-8427_2008` (
`eventid` bigint(20) unsigned NOT NULL,
`source` int(11) NOT NULL DEFAULT '0',
`object` int(11) NOT NULL DEFAULT '0',
`objectid` bigint(20) unsigned NOT NULL DEFAULT '0',
`clock` int(11) NOT NULL DEFAULT '0',
`value` int(11) NOT NULL DEFAULT '0',
`acknowledged` int(11) NOT NULL DEFAULT '0',
`ns` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`eventid`),
KEY `events_1` (`source`,`object`,`objectid`,`clock`),
KEY `events_2` (`source`,`object`,`clock`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin ROW_FORMAT=COMPRESSED;
How did this seemingly strange file come about? There are two ways to perform ddl operations on the table:
ALTER TABLE (ALGORITHM=COPY)
ALTER TABLE (ALGORITHM=INPLACE)
The ALGORITHM=INPLACE method is online ddl. If it exits abnormally during the operation, an orphan intermediate table prefixed by #sql-ib will be generated, accompanied by a different name frm file prefixed by #sql-.
For ALTER TABLE (ALGORITHM=COPY) mode ddl, if it exits abnormally during the operation, an orphan temporary table prefixed with #sql- will be generated, accompanied by a frm file with the same name prefixed by #sql-.
To query whether there are orphan tables in the database, you can query the data dictionary INFORMATION_SCHEMA.INNODB_SYS_TABLES.
For the current upgrade failure environment, query the data dictionary INFORMATION_SCHEMA.INNODB_SYS_TABLES according to Tablespace 7314 in the error message, and found that there is no table starting with #sql, but there are related records in information_schema.INNODB_SYS_DATAFILES, INFORMATION_SCHEMA.INNODB_SYS_TABLESPACES, that is to say, the data dictionary Inconsistency between the recorded metadata information:
root@3306 (none)> SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE NAME LIKE '%#sql%';
Empty set (0.01 sec)
root@3306 (none)> SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES whereSPACE=7314;
Empty set (0.00 sec)
[root@3306][(none)]> select * from information_schema.INNODB_SYS_DATAFILES where space=7314;
+-------+-----------------------------------+
| SPACE | PATH |
+-------+-----------------------------------+
| 7314 | ./zabbix/#sql-ib104-715696445.ibd |
+-------+-----------------------------------+
1 row in set (0.01 sec)
[root@3306][(none)]> SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESPACES WHERE SPACE =7314;
+-------+-----------------------------+------+-------------+------------+--------
---+---------------+------------+---------------+-----------+----------------+
| SPACE | NAME | FLAG | FILE_FORMAT | ROW_FORMAT |
PAGE_SIZE | ZIP_PAGE_SIZE | SPACE_TYPE | FS_BLOCK_SIZE | FILE_SIZE |
ALLOCATED_SIZE |
+-------+-----------------------------+------+-------------+------------+--------
---+---------------+------------+---------------+-----------+----------------+
| 7314 | zabbix/#sql-ib104-715696445 | 41 | Barracuda | Compressed |
16384 | 8192 | Single | 0 | 0 | 0
|
+-------+-----------------------------+------+-------------+------------+--------
---+---------------+------------+---------------+-----------+----------------+
1 row in set (0.01 sec)
How to clean up the orphan table? Refer to official documents:
https://dev.mysql.com/doc/refman/5.7/en/innodb-troubleshooting-datadict.html
The premise of the solution given is that INFORMATION_SCHEMA.INNODB_SYS_TABLES has relevant metadata information, which is obviously different from the current environment, so the orphan intermediate table is cleaned up by DROP TABLE #mysql50##sql-ib104-715696445
defeat. It is not possible to delete the table, is it feasible to delete the database? The general steps are as follows:
- create database zabbix_new;
- alter table zabbix.xxxxxx rename to zabbix_new.xxxxxx;
- drop database zabbix;
- SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESPACES WHERE SPACE =7314;
After testing, even if the zabbix library is deleted, the residual metadata #sql-ib104-715696445.ibd still exists.
The data dictionary is stored in the shared tablespace ibdata1. To solve this problem, the only way to solve this problem is to bypass the ibdata1 file. The following two solutions are thought of:
3.1. Logical export and import upgrade to mysql 8.0
Commonly used tools are mysqldump and mydumper, among which mydumper supports concurrency by table, which can greatly improve efficiency
3.2. Transfer table space + In-Place upgrade to mysql 8.0
Because there is no other machine to provide and the disk space is not sufficient, a single machine and multiple instances are used for table space transmission. The general steps are as follows:
- Export user information and zabbix metadata
mysqldump -uroot -p -B mysql -E -R --triggers --hex-blob --set-gtid-purged=off -- single-transaction --master-data=2 >zabbix-metadata-01.sql
mysqldump -uroot -p -B zabbix -E -R --triggers --hex-blob --no-data --set-gtid- purged=off --single-transaction --master-data=2 >zabbix-metadata-02.sql
- Initialize a 5.7 version 3307 port instance and start
- Load user information and zabbix metadata
mysql -h127.0.0.1 -P3307 -uroot -p < zabbix-metadata-01.sql
mysql> flush privileges;
mysql -h127.0.0.1 -P3307 -uroot -p < zabbix-metadata-02.sql
- New instance zabbix library discards table space
mysql -uroot -p -NBe "select concat('alter table ',TABLE_NAME,' discard tablespace;') from information_schema.TABLES where TABLE_SCHEMA='zabbix'";
use zabbix;
set foreign_key_checks=0;
alter table xxxxxx discard tablespace;
- Close the original mysql instance cleanly, and move the ibd file under the zabbix library to the corresponding path of the new instance. If the space is sufficient, it is best to keep the original file through the cp method
mv /data/3306/zabbix/*.ibd /data/3307/zabbix/
- Importing the table space, this step is also time-consuming, because you need to modify the space id of the page in the ibd file to be consistent with the data dictionary space id, etc.
alter table xxxxxx import tablespace;
When importing the table space, the row format defined by the data dictionary needs to be consistent with the row format recorded in the ibd file, otherwise an error will be reported:
ERROR 1808 (HY000): Schema mismatch (Table has ROW_TYPE_DYNAMIC row format, .ibd file has ROW_TYPE_COMPACT row format.)
Modify the row format through alter table xxxxxx row_format=compact, the ibd file from mv in step 5 will be deleted, resulting in data loss, so mv must first go to the ibd file and then modify the row format
mv /data/3307/zabbix/acknowledges.ibd /data/3307/zabbix/acknowledges.ibd.bak alter table acknowledges row_format=compact;
mv /data/3307/zabbix/acknowledges.ibd.bak /data/3307/zabbix/acknowledges.ibd alter table acknowledges import tablespace;
- In-Place way to upgrade the new instance to 8.0
Because of loadshading issue, one of the table in my database got currupted.
I dropped the table and now I want to create the table again.
I’m getting this error:
ERROR 1813: Tablespace for table ‘
zorkif
.sys_user_accounts
‘ exists. Please DISCARD the tablespace before IMPORT.
SQL Statement:
CREATE TABLE `zorkif`.`sys_user_accounts` (
`UserID` INT NOT NULL AUTO_INCREMENT ,
PRIMARY KEY (`UserID`) ,
UNIQUE INDEX `UserID_UNIQUE` (`UserID` ASC)
)
What is tablespace and how to discard this tablespace?
Is there any command I have to run in query?
How to deal with this issue?
asked Apr 15, 2013 at 6:20
Sizzling CodeSizzling Code
5,83517 gold badges78 silver badges135 bronze badges
4
This works for me, but I use this in local server.
Open the directory where xampp is installed, for example
C:/xampp/mysql/data/...
Select the folder (it’s like a database name) of the tablespace that you want to remove, then delete the file with extension idb
. Delete only one file corresponding to the table that you want to create/remove.
In my case my file is karyawan.idb
,
Hope this works for you.
crockeea
21.6k10 gold badges48 silver badges99 bronze badges
answered Feb 21, 2014 at 4:12
1
It took me quite a while to fix this issue on one of my production dbs. The following steps actually solved the problem pretty cleanly:
-> deactivate your app/page - any requests to your db (if you dont have a service mode in your app - build one :P)
-> mysqldump your db (optionally with --routines=true);
-> kill the folder with db name
-> create schema db name;
-> drop schema db name;
-> restart mysql (service mysql restart - or similar depending on your os)
-> create schema db name;
-> mysql import your previously created dump;
answered Dec 27, 2016 at 22:34
1
Step 1: Backup mysql/database/*.ibd to another folder
Step 2: Delete all mysql ib_logfile*
Step 3: Restart mysql service
Step 4: Login into mysql from shell
Step 5: Run:
- use database;
- ALTER TABLE table_name DISCARD TABLESPACE;
(Repeat for all tables that has problem with tablespace)
Step 6: Copy *.ibd from backup folder to mysql/database/ folder
Step 7: Repeat step 3,4 with running query:
- use database;
- ALTER TABLE table_name IMPORT TABLESPACE;
answered Sep 7, 2017 at 3:24
Trying to drop the tablespace can give you other errors. For me, I got the following error:
DROP TABLESPACE `tablename`
Error Code: 1478. Table storage engine 'InnoDB' does not support the create option 'TABLESPACE or LOGFILE GROUP'
My solution was to drop the database. This will remove any tablespaces related to it and allow you to create the tables again.
answered Jun 18, 2013 at 4:47
ArisAris
4,4661 gold badge39 silver badges36 bronze badges
The following works on MariaDB 10.3.12:
- create another table with the same name in another database
- sudo cp -p otherdb/tablename.frm problemdb/tablename.frm
- drop table problemdb.tablename
Everything should work and be clean after this.
answered Feb 5, 2019 at 0:06
Robert DRobert D
1,77014 silver badges18 bronze badges
Open the directory where MAMP is installed, for example
Macintosh ▸ Applications ▸ MAMP ▸ db ▸ …
Select the folder (it’s like a database name) of the tablespace that you want to remove, then delete the file with extension idb. Delete only one file corresponding to the table that you want to create/remove.
For Example file :
Macintosh ▸ Applications ▸ MAMP ▸ db ▸ mysql57 ▸ example_db ▸ amc_customer.ibd
Try this.
It’s work for me.
answered Apr 29, 2019 at 6:50
SAVeSAVe
8166 silver badges22 bronze badges
0
In my case even after I deleted table before Import, I could not discard TABLESPACE because mysql was saying that no TABLESPACE exists, if that’s the case it’s because indexes of that table remains so you need to delete those indexes
DELETE FROM innodb_index_stats WHERE table_name='table_name_here';
After that Discard tablespace error is not occurred anymore and I could successfully import table
answered Oct 3, 2019 at 8:52
Berk CanBerk Can
1332 silver badges8 bronze badges
Before creating this table run this query for removing the TABLESPACE
DROP TABLESPACE `zorkif`.`sys_user_accounts`
TABLESPACE can contain one or more data files, providing storage space for tables.
answered Apr 15, 2013 at 6:25
Yogesh SutharYogesh Suthar
30.3k18 gold badges71 silver badges100 bronze badges
1
Steps to resolve this matter:
- export your schema to backup file
- drop schema
- modify your SQL script exported, adding the ‘create table’ you need
- create the same schema
- import your schema from backup file
answered Mar 23, 2016 at 13:01
0
if you encounter this error on your local host, just go to the
xamp folder, move to mysql folder, move to data folder, inside the data folder you will see the list of database based on the database name, select the folder of the database that is giving you error, the the particular table name that is give you the error and re-import your database.
Just solve this on my system now
answered Mar 22, 2017 at 22:59
If you’re on a Mac, go to Applications->XAMPP->xamppfiles->var-mysql look for your database name. You might have to give ‘read&write’ access to ‘everyone’ in privileges. Thereafter, delete the relevant .idb file. Restart XAMPP and you should be good to go.
answered Aug 23, 2018 at 14:28