49.MySQL-Utilities工具包之-mysqldbimport导入DDL/DML

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;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值