mysql单表备份语句 +多表
生活随笔
收集整理的這篇文章主要介紹了
mysql单表备份语句 +多表
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
mysql單表備份語句
mysql單表備份
SELECT CONCAT("mysqldump -uroot -p123456 ",table_schema," ",table_name," >/tmp/",table_schema,"_",table_name,".sql") FROM information_schema.tables WHERE table_schema NOT IN('sys','performance','information_schema') INTO OUTFILE '/tmp/bak.sh';INTO COUTFILE '/tmp.bak.sh'; --將查詢結果輸出保存到一個文件中
FIELDS TERMINATED BY "," ENCLOSED BY '"'; -- 以逗號分割,引號包裹
多表備份
mysqldump -rp2p_sit -p --database p2p_sit --tables tablename1 tablename2 > ~/p2p_init.sql
查詢整個數據庫中所有的庫對應的表明
select table_schema, table_name from information_schema.tables;查詢world和school庫下所有的表明
select table_schema, table_name from information_schema.tables where table_name = 'world' union all select table_schema, table_name from information_schema.tables where table_name = 'school';查詢整個數據庫中所有的庫對應的表明,每個庫顯示一行
select table_schema, group_concat(table_name) from information_schema.tables group by table_schema;統計每個庫下的表的個數
select table_schema, count(table_name) from information_schema.tables group by table_name;統計每個庫的真實數據量 (感覺有問題)
# 每個表的數據量=AVG_ROW_LENGTH*TABLE_ROWS+INDEX_LENGTH SELECT sum(AVG_ROW_LENGTH*TABLE_ROWS+INDEX_LENGTH)/1024/1024 as total_nb from information_schema.tables;Concat拼接命令
select concat(user,"@","'",host,"'") from mysql.user;對數據庫下的單張表進行單獨備份
# world庫下的city表 mysqldump -uroot -p****** world city > /tmp/world_city.sql對整個數據庫下的1000張表進行單獨備份,排除sys,performance,information_schema。
select concat("mysqldump -uroot -p******",table_schema," ",table_name," >/tmp/",table_schema,"_",table_name,".sql") from information_schema.tables where table_schema not in ("sys","performance","information_schema") into outfile '/tmp/bak.sh';總結
以上是生活随笔為你收集整理的mysql单表备份语句 +多表的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql导入本地sql脚本的两种方式
- 下一篇: mysql单表备份语句