关于 Docker 启动 MySQL 参考:Docker 启动 MySQL
查看数据库
1 | # 1. 进入容器 |
备份 所有数据库
语法:root@65cde980ee00:/# mysqldump -hhost -Pport -uusername -ppassword --all-databases > /备份路径/备份文件
1 | ------------------------docker exec -it mysql01 bash |
备份 指定数据库
语法:root@65cde980ee00:/# mysqldump -hhost -Pport -uusername -ppassword --databases db1 [db2] [db3] ... > /备份路径/备份文件
1 | #===> 备份一个数据库,有“CREATE DATABASE” |
备份 指定数据库 的所有表
语法:root@65cde980ee00:/# mysqldump -hhost -Pport -uusername -ppassword db > /备份路径/备份文件
1 | #===> 备份数据库 order_bff_cmdb 的所有表 |
备份 指定数据库 的指定表
语法:root@65cde980ee00:/# mysqldump -hhost -Pport -uusername -ppassword db table1 [table2] [table3] ... > /备份路径/备份文件
1 | #===> 备份数据库 order_bff_cmdb 的 api_user 表 |
备份问题:gtid,statistics
语法:mysqldump -hhost -Pport -uusername -ppassword --databases db1 --set-gtid-purged=OFF --column-statistics=0 > /root/db1.sql
1、GTID:可使用--set-gtid-purged=OFF
2、mysqldump: Couldn’t execute … Unknown table ‘column_statistics’ in information_schema (1109):可使用--column-statistics=0
错误问题:
1 | root@f938e9ba4247:/# mysqldump -hhost -uusername -ppassword --databases db1 > /root/db1.sql |
关于 docker cp
从容器拿出来
docker cp mysql01:/home . #===> 容器 mysql02:/home 目录 拷贝到当前目录(/app/docker/mysql/)
放进容器
docker cp home mysql02:/home #===> 把当前 home 目录 拷贝到 mysql02:/home 下面
1 | Connecting to 192.168.1.1:22... |
还原
语法:mysql -uroot -p < /home/home/order_bff_cmdb.sql #===> 导入整个数据库
语法:mysql -uroot -p order_bff_cmdb < /home/home/order_bff_cmdb.api_user.sql #===> 导入表,需要指定数据库
1 | # 1. 进入容器 |