mysql數據庫命令大全---完全備份和恢復
阿新 • • 發佈:2018-09-08
per ado 登錄mysql score 表格 select 恢復數據庫 數據 完全備份 數據完全備份
[root@localhost ~]# mysqldump -uroot -pabc123 --databases school > /opt/school.sql
刪除庫mysql> drop database school;
查看數據庫mysql> show databases;
+--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+
還原數據庫
mysql> source /opt/school.sql mysql> show databases; #查看數據庫確認 +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | school | | sys | +--------------------+ 方法二:此方法需要重新創建庫名 mysqldump -uroot -pabc123 school > /opt/school.sql mysql> create database school; mysql> source /opt/school.sql; mysql> show tables; +------------------+ | Tables_in_school | +------------------+ | info | +------------------+ 1 row in set (0.00 sec) mysql> select * from info; +----+------+-------+ | id | name | score | +----+------+-------+ | 1 | ll | 88 | | 2 | tl | 68 | | 3 | ww | 44 | | 4 | pw | 55 | +----+------+-------+
方法三:不進入mysql數據庫恢復數據
恢復數據mysql -uroot -pabc123 < /opt/school.sql
數據表備份[root@localhost ~]# mysqldump -uroot -pabc123 school info > /opt/info.sql
刪除表格(模擬數據表損壞)
mysql> drop table info;
還原備份數據表mysql> source /opt/info.sql
查看表格
mysql> show tables; +------------------+ | Tables_in_school | +------------------+ | info | +------------------+
與數據庫一樣,也可以不登錄mysql恢復數據表mysql -uroot -pabc123 school < /opt/info.sql
總結:無論是恢復數據庫還是恢復數據表,都應該先查看一下備份文件,看裏面有無自動創建數據庫或數據表的命令,再考慮是否在備份時創建數據庫和數據表!
查看備份文件
vim school.sql
mysql數據庫命令大全---完全備份和恢復