副问题[/!--empirenews.page--]
一、mysqldump器材先容
mysqldump 是个mysql数据库自带的呼吁行器材,单线程执行,可以用来备份和还原数据。可以天生 CSV、TXT、XML名目标文件输出。
查察辅佐文档
二、操作mysqldump举办数据库备份
1. 数据库操纵
(1) 备份全部数据库
- mysqldump -h 主机IP -uroot -p --all-database > /data/dball.sql
(2) 备份多个数据库
- mysqldump -h 主机IP -uroot -p db1 db2 db3 >/data/db123.sql
(3) 备份单数据库
- mysqldump -h 主机IP -uroot -p db >/data/db.sql
2. 数据库中表操纵
(1) 备份数据库中多张表
- mysqldump -h 主机IP -uroot -p db table1 table2 >/data/db_table12.sql
(2) 备份数据库中一张表
- mysqldump -h 主机IP -uroot -p db table >/data/db_table.sql
(3) 按照where举办备份
- mysqldump -h 主机IP -uroot -p db table --where " 查询前提" >/data/db_table.sql
(4) 备份数据中,忽略某张表
- mysqldump -h 主机IP -uroot -p db --ignore-table=logtable --ignore-table=historytable >/data/db_table.sql
3. 数据库只导出表布局或数据,正常环境下导出表布局和数据都存在
(1) 只导出表布局,不导出数据
- mysqldump -h主机IP -d-uroot -p 数据库名 > db.sql
(2) 只导出数据,不导出表布局
- mysqldump -h主机IP -t -uroot -p 数据库名 > db.sql
4. 通用备份呼吁
- mysqldump -h -uroot -p --default-character-set=utf-8 --set-gtid-purged=OFF --lock-tables=false -R -E --databases db | gzip > /root/db.sql.gz
- --default-character-set=utf-8 指定字符集
- --set-gtid-purged=OFF 从头出产GTID,而不消原本的
- --lock-tables 不锁表
- -R Dump stored routines (functions and procedures)
- -E Dump events
- gzip 对备份举办压缩
三、操作mysqldump举办数据库还原
第一种:
- mysqldump -h 主机IP -uroot -p db < /root/db.sql
第二种:source 呼吁
- [root@izbp10lvzs7171weegqj8xz ~]# mysql -uroot -p
- mysql: [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 62669
- Server version: 5.7.23-log MySQL Community Server (GPL)
-
- Copyright (c) 2000, 2018, 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.
-
- 21: root@localhost:[(none)]> use test;
- Database changed
- 21: root@localhost:[test]> source /root/db.sql
(编辑:河北网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|