前言
配置mysql主从复制时,要用到mysqldump工具。本文初步熟悉此工具的必要用法,便于快速部署mysql主从复制。
结论
1,mysqldump --all-databases导出全部数据库
2,drop database无法删除performance_schema
3,/mysql -u root -p
部署明细
1,创建测试表
[root@mygirl ~]# /usr/local/mysql/bin/mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.5.58-log MySQL Community Server (GPL)
Copyright (c) 2000, 2017, 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> show databases;
+--------------------+
Database
+--------------------+
information_schema
mysql
newdb
newzxy
performance_schema
test
+--------------------+
6 rows in set (0.00 sec)
mysql> use newzxy;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> create table t_newtab(a int);
Query OK, 0 rows affected (0.04 sec)
mysql> insert into t_newtab values(1);
Query OK, 1 row affected (0.01 sec)
2,导出全部数据库
[root@mygirl ~]# /usr/local/mysql/bin/mysqldump --all-databases -u root -p >fulldbdump.db
Enter password:
-- Warning: Skipping the data of table mysql.event. Specify the --events option explicitly.
[root@mygirl ~]# ll fulldbdump.db
-rw-r--r--. 1 root root 1613359 Jan 1 16:07 fulldbdump.db
3,删除全部数据库,可见无法删除数据库performance_schema
mysql> show databases;
+--------------------+
Database
+--------------------+
information_schema
mysql
newdb
newzxy
performance_schema
test
+--------------------+
6 rows in set (0.00 sec)
mysql> drop database mysql;
Query OK, 24 rows affected, 2 warnings (0.03 sec)
mysql> drop database newdb;
Query OK, 2 rows affected, 2 warnings (0.02 sec)
mysql> drop database newzxy;
Query OK, 2 rows affected, 2 warnings (0.01 sec)
mysql> drop database test;
Query OK, 2 rows affected, 2 warnings (0.03 sec)
mysql> drop database information_schema;
ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'information_schema'
mysql> drop database performance_schema;
Query OK, 17 rows affected, 2 warnings (0.00 sec)
4,导入全部数据库
[root@mygirl ~]# /usr/local/mysql/bin/mysql -u root -p
Enter password:
[root@mygirl ~]#
5,验证数据库导入是否正确
[root@mygirl ~]# /usr/local/mysql/bin/mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 5.5.58-log MySQL Community Server (GPL)
Copyright (c) 2000, 2017, 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> show databases;
+--------------------+
Database
+--------------------+
information_schema
mysql
newdb
newzxy
test
+--------------------+
5 rows in set (0.00 sec)
mysql> use newzxy;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
+------------------+
Tables_in_newzxy
+------------------+
t_big
t_newtab
+------------------+
2 rows in set (0.00 sec)
领取专属 10元无门槛券
私享最新 技术干货