mysql備份表的幾種方法總結(jié)
第一種,小表的備份
1.create table A as select * from B
2.create table A like select * from B
3.分布操作
create table A like B;
insert into A select * from B;
第二種,對整個數(shù)據(jù)庫的備份與恢復
2.1 對整個數(shù)據(jù)庫進行備份
1.創(chuàng)建備份用戶和密碼:zhangsan_backup/zs123
create user 'zhangsan_backup'@'localhost' identified by 'zs123';
2.賦予該用戶有哪些權(quán)限
grant select ,reload,lock tables,replication client,show view,event,process on *.* to 'zhangsan_backup'@'localhost';
3.備份數(shù)據(jù)
#1 mysqldump -uzhangsan_backup -p --master-data=2 --single-transaction --routines --triggers --events bonc_test > e:\\bonc_test2.sql #2 mysqldump -uzhangsan_backup -p bonc_test > e:\\bonc_test.sql
mysql> create user 'zhangsan_backup'@'localhost' identified by 'zs123'; ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement mysql> flush privileges; Query OK, 0 rows affected (0.15 sec) mysql> create user 'zhangsan_backup'@'localhost' identified by 'zs123'; Query OK, 0 rows affected (0.02 sec) mysql> grant select ,reload,lock tables,replication client,show view,event,process on *.* to 'zhangsan_backup'@'localho st'; Query OK, 0 rows affected (0.02 sec) C:\Windows\system32>mysqldump -uzhangsan_backup -p --master-data=2 --single-transaction --routines --triggers --events bonc_test > e:\\bonc_test2.sql Enter password: ***** C:\Windows\system32>
注意如果在操作中報:mysqldump: Error: Binlogging on server not active的錯誤,則在windows中的my.ini文件中最后面新增:
#備份數(shù)據(jù)庫
log-bin=mysql-bin
server-id=1
然后重新啟動服務。即可。
2.2 對整個數(shù)據(jù)庫進行恢復
#1.先創(chuàng)建一個數(shù)據(jù)庫
create database bak_bonc_test;
#2.進行恢復數(shù)據(jù)
mysql -uroot -p bak_bonc_test <e:\\bonc_test2.sql
#3.查看:
第三種,對某個數(shù)據(jù)表進行備份
3.1 對整個數(shù)據(jù)表進行備份
庫:bonc_test 表: user_login_tb
mysqldump -uzhangsan_backup -p --master-data=2 --single-transaction --routines --triggers --events bonc_test user_login_tb > e:\\user_login_tb.sql
3.2 對整個數(shù)據(jù)表進行恢復
#先刪除bak_bonc_test 庫中 user_login_tb的這個表
#對其進行恢復: source e:\\user_login_tb.sql;
四.第4種,制定時間點的備份和恢復和實時二進制日志備份
五.使用xtrabackup進行備份
小結(jié)
到此這篇關(guān)于mysql的備份表的幾種方法總結(jié)的文章就介紹到這了,更多相關(guān)mysql的備份表內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
MySQL中distinct和count(*)的使用方法比較
這篇文章主要針對MySQL中distinct和count(*)的使用方法比較,對兩者之間的使用方法、效率進行了詳細分析,感興趣的小伙伴們可以參考一下2015-11-11MySQL數(shù)據(jù)庫安裝方法與圖形化管理工具介紹
這篇文章介紹了MySQL數(shù)據(jù)庫安裝方法與圖形化管理工具,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2022-05-05Lost connection to MySQL server during query的解決
經(jīng)常在執(zhí)行sql語句時,會發(fā)現(xiàn)這個問題,一般就是連接mysql數(shù)據(jù)庫不穩(wěn)定2008-06-06