1.恢复:导入元数据:DDL。
[root@mysql1 ~]# mysqldbimport --server=root:rootroot@localhost:3306:/tmp/mysql.sock --drop-first --skip-gtid --import=definitions --format=sql test.sql
WARNING: Using a password on the command line interface can be insecure.
# Source on localhost: ... connected.
# Importing definitions from test.sql.
CAUTION: The following warning messages were included in the import file:
# WARNING: Using a password on the command line interface can be insecure.
# WARNING: A partial export from a server that has GTIDs enabled will by default include the GTIDs of all transactions,
#even those that changed suppressed parts of the database. If you don''t want to generate the GTID statement, use the --skip-gtid option. To export all databases, use the --all and --export=both options.
#...done.
mysql> use test;
mysql> show tables;
+-----------------------+
| Tables_in_test |
+-----------------------+
| mf_advisorshareholder |
| t2 |
| t3 |
| test1 |
| test2 |
| test3 |
| test4 |
| test5 |
| test6 |
+-----------------------+
9 rows in set (0.00 sec)
mysql> select * from t2;
Empty set (0.00 sec)
发现表结构数据进来了。
2.DML 导入。
mysqldbimport --server=root:rootroot@localhost:3306:/tmp/mysql.sock --import=both --skip-gtid --bulk-insert --format=sql test_data.sql
[root@mysql1 ~]# mysqldbimport --server=root:rootroot@localhost:3306:/tmp/mysql.sock --import=both --skip-gtid --bulk-insert --format=sql test_data.sql
WARNING: Using a password on the command line interface can be insecure.
# Source on localhost: ... connected.
# Importing definitions and data from test_data.sql.
CAUTION: The following warning messages were included in the import file:
# WARNING: Using a password on the command line interface can be insecure.
# WARNING: A partial export from a server that has GTIDs enabled will by default include the GTIDs of all transactions,
#even those that changed suppressed parts of the database. If you don''t want to generate the GTID statement, use the --skip-gtid option. To export all databases, use the --all and --export=both options.
#...done.
导入成功,检查数据,发现有104条,说明导入成功。
mysql> select count(*) from t2;
+----------+
| count(*) |
+----------+
| 104 |
+----------+
1 row in set (0.00 sec)
检查表已经有数据了。
3.总结
mysqldbexport和mysqldbimport 是成对使用的,当让如果导出了DDL/DML,也可以通过mysql工具直接执行。以导入DDL和DML;