Detailed description of InnoDB shared tablespace to independent tablespace and problems encountered
Zhang Ying posted on
CATEGORY Directory: MySQL
Recently, the MySQL InnoDB Storage engine was optimized to convert the shared tablespace into an independent tablespace. I didn't think so much at the beginning, so I had to promote it in a short time. So I want to optimize it and see how it works. Describes a conversion process.
1. Check whether the table space is shared or independent.
View copy print?
- Mysql> show variables like '% per_table % ';
- + ----------------------- + ------- +
- | Variable_name | value |
- + ----------------------- + ------- +
- | Innodb_file_per_table | off |
- + ----------------------- + ------- +
- 1 row in SET (0.00 Sec)
If it is off, it is definitely not an independent tablespace. If it is on, it is not necessarily an independent tablespace. The most direct method is to view the files on the hard disk, independent tablespace, and each table corresponds to a space.
- [Root @ localhost TG] # ll
- Total usage 64
- -RW ----. 1 MySQL 65 December 30 20:09 dB. Opt
- -RW ----. 1 MySQL 8658 December 30 23:17 GB. FRM
- -RW ----. 1 MySQL 8658 December 30 23:19 QR. FRM
- -RW ----. 1 MySQL 8658 December 30 23:19 QY. FRM
- -RW ----. 1 MySQL 8658 December 30 23:19 TG. FRM
- -RW ----. 1 MySQL 8658 December 30 23:19 xcy. FRM
TG is a database name, which contains InnoDB. In this case, the table space is shared.
2. Stop MySQL.
- /Etc/init. d/mysqld stop
3. modify the configuration file of my. CNF.
- InnoDB-file-per-table = 1
4. Back up databases using the InnoDB Engine
- Mysqldump-u Tg-P Tg>/home/6fan/TG. SQL;
5. Delete InnoDB databases and log files.
View copy print?
- CD/var/lib/MySQL // database file location
- Rm-f ib * // delete logs and Space
- Rm-rf tg // Delete the database folder using the InnoDB Engine
If the InnoDB database folder is not deleted, the InnoDB engine cannot be started. I checked the error log. As follows:
111231 20:54:44 InnoDB: Log File./ib_logfile0 did not exist: new to be created
InnoDB: Setting log file./ib_logfile0 size to 512 MB
InnoDB: Database physically writes the file full: Wait...
InnoDB: Progress in MB: 100 200 300 400 500
111231 20:54:50 InnoDB: Log File./ib_logfile1 did not exist: new to be created
InnoDB: Setting log file./ib_logfile1 size to 512 MB
InnoDB: Database physically writes the file full: Wait...
InnoDB: Progress in MB: 100 200 300 400 500
InnoDB: Cannot initialize created log files because
InnoDB: data files are created upt, or new data files were
InnoDB: created when the database was started previous
InnoDB: time but the database was not shut down
InnoDB: normally after that.
111231 20:54:55 [Error] plugin 'innodb' init function returned error.
111231 20:54:55 [Error] plugin 'innodb' registry as a storage engine failed.
111231 20:54:55 [note] event schedents: loaded 0 events
6. Start MySQL
- /Etc/init. d/mysqld start
7. Import the database
- Mysql-u root-P
8. Check whether the conversion is complete.
View copy print?
- // Query after entering MySQL
- Mysql> show variables like '% per_table % ';
- + ----------------------- + ------- +
- | Variable_name | value |
- + ----------------------- + ------- +
- | Innodb_file_per_table | on |
- + ----------------------- + ------- +
- 1 row in SET (0.00 Sec)
- // View files in the database directory
- [Root @ localhost TG] # ll
- Total usage 544
- -RW ----. 1 MySQL 65 December 31 22:48 dB. Opt
- -RW ----. 1 MySQL 8658 December 31 22:49 GB. FRM
- -RW ----. 1 MySQL 98304 December 31 22:49 GB. IBD
- -RW ----. 1 MySQL 8658 December 31 22:49 QR. FRM
- -RW ----. 1 MySQL 98304 December 31 22:49 QR. IBD
- -RW ----. 1 MySQL 8658 December 31 22:49 QY. FRM
- -RW ----. 1 MySQL 98304 December 31 22:49 QY. IBD
- -RW ----. 1 MySQL 8658 December 31 22:49 TG. FRM
- -RW ----. 1 MySQL 98304 December 31 22:49 TG. IBD
- -RW ----. 1 MySQL 8658 December 31 22:49 xcy. FRM
- -RW ----. 1 MySQL 98304 December 31 22:49 xcy. IBD
From this we can see that each table has a. IBD file, and the root shared tablespace is different. The configuration is complete here.