Skip to content

备份mysql数据

新机器

bash
mysql -u root -p


show databases;



##删除数据库
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| LikeGirlv520       |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.02 sec)

mysql> drop database LikeGirlv520;
Query OK, 11 rows affected (0.04 sec)

mysql>

老机器

bash
##检查
mysql> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| LikeGirlv520       |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.00 sec)

mysql> USE LikeGirlv520;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> SHOW TABLES;
+------------------------+
| Tables_in_LikeGirlv520 |
+------------------------+
| IPerror                |
| about                  |
| article                |
| diySet                 |
| leavSet                |
| leaving                |
| login                  |
| loveImg                |
| lovelist               |
| text                   |
| warning                |
+------------------------+
11 rows in set (0.00 sec)

mysql>

备份:

bash
[root@wiki ~]# mysqldump -u root -p --databases LikeGirlv520 > LikeGirlv520_backup.sql
Enter password: 
[root@wiki ~]# ll LikeGirlv520_backup.sql -h
-rw-r--r-- 1 root root 20K Jun  9 12:32 LikeGirlv520_backup.sql
[root@wiki ~]#

新机器

bash
[root@localhost ~]#mysql -u root -p < /root/LikeGirlv520_backup.sql
Enter password: 


mysql> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| LikeGirlv520       |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.00 sec)

mysql> USE LikeGirlv520;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> SHOW TABLES;
+------------------------+
| Tables_in_LikeGirlv520 |
+------------------------+
| IPerror                |
| about                  |
| article                |
| diySet                 |
| leavSet                |
| leaving                |
| login                  |
| loveImg                |
| lovelist               |
| text                   |
| warning                |
+------------------------+
11 rows in set (0.00 sec)

mysql>

验证

本次,经实际测试,这个方式是可以正常备份项目数据的,完美。😜

image-20250613211943742

声明

作者:One

版权:此文章版权归 One 所有,如有转载,请注明出处!

链接:可点击右上角分享此页面复制文章链接

上次更新时间:

最近更新