mysql> show variables like 'innodb%version';
+----------------+--------+
| Variable_name | Value |
+----------------+--------+
| innodb_version | 5.6.36 |
+----------------+--------+
1 row in set (0.01 sec)
mysql> show variables like 'datadir';
+---------------+--------------------+
| Variable_name | Value |
+---------------+--------------------+
| datadir | /data/mysql_data6/ |
+---------------+--------------------+
1 row in set (0.00 sec)
* 目的实例 MySQL
mysql> show variables like 'innodb%version';
+----------------+--------+
| Variable_name | Value |
+----------------+--------+
| innodb_version | 5.7.18 |
+----------------+--------+
1 row in set (0.00 sec)
mysql> show variables like 'datadir';
+---------------+--------------------+
| Variable_name | Value |
+---------------+--------------------+
| datadir | /data/mysql_data7/ |
+---------------+--------------------+
1 row in set (0.01 sec)
* 源实例 MySQL 迁移的数据库与表信息
mysql> select database();
+------------+
| database() |
+------------+
| mytest |
+------------+
1 row in set (0.00 sec)
mysql> show create table users;
+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| users | CREATE TABLE `users` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`sex` enum('M','F') NOT NULL DEFAULT 'M',
`age` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 |
+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.01 sec)
mysql> select * from users;
+----+-------+-----+-----+
| id | name | sex | age |
+----+-------+-----+-----+
| 1 | tom | M | 25 |
| 2 | jak | F | 38 |
| 3 | sea | M | 43 |
| 4 | lisea | M | 36 |
+----+-------+-----+-----+
4 rows in set (0.00 sec)
mysql> create database mytest character set utf8mb4;
Query OK, 1 row affected (0.03 sec)
mysql> use mytest;
Database changed
mysql> CREATE TABLE `users` (
-> `id` bigint(20) NOT NULL AUTO_INCREMENT,
-> `name` varchar(255) NOT NULL,
-> `sex` enum('M','F') NOT NULL DEFAULT 'M',
-> `age` int(11) NOT NULL DEFAULT '0',
-> PRIMARY KEY (`id`)
-> ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 row_format=compact;
Query OK, 0 rows affected (0.59 sec)
mysql> system ls -l /data/mysql_data7/mytest/
total 64
-rw-r----- 1 mysql mysql 67 Jul 18 05:21 db.opt
-rw-r----- 1 mysql mysql 8648 Jul 18 05:21 users.frm
-rw-r----- 1 mysql mysql 49152 Jul 18 05:21 users.ibd
* 目的MySQL实例丢弃表空间
mysql> alter table users discard tablespace;
Query OK, 0 rows affected (0.01 sec)
mysql> system ls -l /data/mysql_data7/mytest/
total 16
-rw-r----- 1 mysql mysql 67 Jul 18 05:21 db.opt
-rw-r----- 1 mysql mysql 8648 Jul 18 05:21 users.frm
[root@MySQL ~]# chown -v mysql.mysql /data/mysql_data7/mytest/users.{cfg,ibd}
changed ownership of `/data/mysql_data7/mytest/users.cfg' to mysql:mysql
changed ownership of `/data/mysql_data7/mytest/users.ibd' to mysql:mysql
mysql> select * from users;
+----+-------+-----+-----+
| id | name | sex | age |
+----+-------+-----+-----+
| 1 | tom | M | 25 |
| 2 | jak | F | 38 |
| 3 | sea | M | 43 |
| 4 | lisea | M | 36 |
+----+-------+-----+-----+
4 rows in set (0.00 sec)
4. 注意问题
* MySQL 5.6数据迁移到MySQL5.7时,如果创建目的表时不指定row_format,import表数据时会报错,原因在于MySQL 5.6中是Antelope,在MySQL 5.7中是Barracuda,主要是在表压缩和行的动态格式上有所改变。