[root@hf-01 ~]# mysqldump -uroot -p'hanfeng' mysql > /tmp/mysqlbak.sql
Warning: Using a password on the command line interface can be insecure.
[root@hf-01 ~]#
[root@hf-01 ~]# mysql -uroot -p'hanfeng' -e "create database mysql2"
Warning: Using a password on the command line interface can be insecure.
[root@hf-01 ~]#
[root@hf-01 ~]# mysql -uroot -p'hanfeng' mysql < /tmp/mysqlbak.sql
Warning: Using a password on the command line interface can be insecure.
[root@hf-01 ~]#
[root@hf-01 ~]# mysql -uroot -p'hanfeng' mysql2
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.6.35 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
mysql> select database();
+------------+
| database() |
+------------+
| mysql2 |
+------------+
1 row in set (0.00 sec)
mysql>
[root@hf-01 ~]# mysqldump -uroot -phanfeng mysql user > /tmp/user.sql
Warning: Using a password on the command line interface can be insecure.
[root@hf-01 ~]# less /tmp/user.sql 查看备份表
[root@hf-01 ~]# mysql -uroot -phanfeng mysql2 < /tmp/user.sql
Warning: Using a password on the command line interface can be insecure.
[root@hf-01 ~]#
[root@hf-01 ~]# mysqldump -uroot -phanfeng -A > /tmp/mysql_all.sql
Warning: Using a password on the command line interface can be insecure.
[root@hf-01 ~]#
[root@hf-01 ~]# less /tmp/mysql_all.sql
[root@hf-01 ~]# mysqldump -uroot -phanfeng -d mysql2 > /tmp/mysql.sql
Warning: Using a password on the command line interface can be insecure.
[root@hf-01 ~]#
[root@hf-01 ~]# less /tmp/mysql.sql