MySQL數據庫備份和恢復

MySQL數據庫備份和恢復

1、如果您沒有修改MySQL的root用戶的密碼,可在本機登錄CactiEZ中文版V10或以SSH方式登錄CactiEZ中文版V10。

未修改密碼備份MySQL數據庫方法:
# mysqldump cacti > cacti.20110330.sql
# ls
cacti.20110330.sql
說明:mysqldump是MySQL數據庫導出命令,cacti是數據庫名,cacti.20110330.sql是導出後的文件名。

已修改密碼備份MySQL數據庫方法:
# mysqldump -u root -p cacti > cacti.20110330.sql
Enter password:
# ls cacti.20110330.sql
cacti.20110330.sql
說明:-u表示指定用戶名,-p表示該用戶需要使用密碼。輸入回車後,在Enter password:後輸入root用戶的密碼,輸入時不顯示密碼或星號。


PS:比如Cacti的數據庫備份

1、數據庫備份:

mysqldump -u root -p cacti > 2017.2.13.sql (密碼:cactifansdb  默認數據庫密碼)
2、圖片備份
tar -cvf rra-2017.2.9.tar /var/www/html/rra   (圖片壓縮)


2、MySQL數據庫恢復方法
未修改密碼恢復MySQL數據庫方法:
# mysql cacti < cacti.20110330.sql
如果有任何報錯,請按以下步驟登錄MySQL,刪除原有庫,新建庫,再導入:
# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 83
Server version: 5.1.47 Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> drop database cacti;
Query OK, 66 rows affected (0.12 sec)

mysql> create database cacti;
Query OK, 1 row affected (0.00 sec)

mysql> exit
Bye
# mysql cacti < cacti.20110330.sql

已修改密碼恢復MySQL數據庫方法:
# mysql -u root -p cacti < cacti.20110330.sql
Enter password:
如果有任何報錯,請按以下步驟登錄MySQL,刪除原有庫,新建庫,再導入:
# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 83
Server version: 5.1.47 Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> drop database cacti;
Query OK, 66 rows affected (0.12 sec)

mysql> create database cacti;
Query OK, 1 row affected (0.00 sec)

mysql> exit
Bye
# mysql cacti < cacti.20110330.sql


PS:Cacti數據庫還原

1、數據庫還原

mysql cacti < 2017.2.13.sql

2、圖片還原

cp -rv ./root/rra-2017.2.9.tar /var/www/html/rra

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章