标签:san enter tables base 备份还原 arc sql 新建 efault
1、表备份
# 备份表 dcs 为 duoceshi mysql> create table duoceshi like dcs; mysql> show tables; +-------------------+ | Tables_in_student | +-------------------+ | dcs | | duoceshi | +-------------------+ mysql> desc duoceshi; +-------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+----------------+ | id | int(1) | NO | PRI | NULL | auto_increment | | name | varchar(10) | YES | | NULL | | | sex | char(2) | YES | | NULL | | +-------+-------------+------+-----+---------+----------------+
# 把表 dcs 中的数据备份到表 duoceshi 中 mysql> insert into duoceshi select * from dcs; mysql> select * from dcs; +----+-----------+------+ | id | name | sex | +----+-----------+------+ | 1 | zhangsan1 | m | | 2 | lisi1 | m | | 3 | zhangsan2 | m | +----+-----------+------+ mysql> select * from duoceshi; +----+-----------+------+ | id | name | sex | +----+-----------+------+ | 1 | zhangsan1 | m | | 2 | lisi1 | m | | 3 | zhangsan2 | m | +----+-----------+------+
# 备份表 dcs 中的 id,name 两个字段数据到表 duoceshi 中 mysql> insert into duoceshi(id,name) select id,name from dcs; mysql> select * from dcs; +----+-----------+------+ | id | name | sex | +----+-----------+------+ | 1 | zhangsan1 | m | | 2 | lisi1 | m | | 3 | zhangsan2 | m | +----+-----------+------+ mysql> select * from duoceshi; +----+-----------+------+ | id | name | sex | +----+-----------+------+ | 1 | zhangsan1 | NULL | | 2 | lisi1 | NULL | | 3 | zhangsan2 | NULL | +----+-----------+------+
2、数据库备份还原
# 将数据库备份到 /zhengying 目录下的 student_copy.sql 文件中 [root@localhost /]# mysqldump -uroot -p student > /zhengying/student_copy.sql Enter password: ......
# 新建数据库 stu_db mysql> create database stu_db; mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | cms | | mysql | | stu_db | | test | +--------------------+ # 还原数据库数据到 stu_db 数据库中 [root@localhost /]# mysql -uroot -p stu_db < /zhengying/student_copy.sql Enter password: ...... # 再次进入 MySQL 数据库 [root@localhost /]# mysql -u root -p Enter password: ...... # 进入 stu_db 库中 mysql> use stu_db; # 查看 stu_db 库的表,验证表是否还原成功 mysql> show tables; +------------------+ | Tables_in_stu_db | +------------------+ | dcs | | duoceshi | | t | | t_course | | t_student | | v_stu | +------------------+ # 查看 dcs 表中数据,验证表数据是否还原成功 mysql> select * from dcs; +----+-----------+------+ | id | name | sex | +----+-----------+------+ | 1 | zhangsan1 | m | | 2 | lisi1 | m | | 3 | zhangsan2 | m | +----+-----------+------+
标签:san enter tables base 备份还原 arc sql 新建 efault
原文地址:https://www.cnblogs.com/ZhengYing0813/p/12678524.html