侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

mysql数据库命令大全---完全备份和恢复

2024-05-14 星期二 / 0 评论 / 0 点赞 / 98 阅读 / 2860 字

数据完全备份mysqldump -uroot -pabc123 --databases school > /opt/school.sql删除库mysql> drop database school;查

数据完全备份

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

数据表备份

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

广告 广告

评论区