【mysql】数据备份与恢复
1、数据库的备份与恢复
1 .1 备份整个数据库:
[root@localhost ~]# mysqldump -uroot -p school > /opt/school.sqlbak
//school是数据库
Enter password: (数据库密码)
恢复整个数据库方法一:
mysql> create database school;
mysql> use school;
mysql> source /opt/school.sqlbak;
恢复整个数据库方法二:
[root@localhost opt]#mysql -uroot -p </opt/school.sqlbak;
Enter password:
1.2 备份多个数据库:
[root@localhost opt]# mysqldump -uroot -p --databases school comany >/opt/school_comany.sqlbak
//school和comany都是数据库
Enter password:(数据库密码)
恢复多个数据库方法一:
mysql> create database school;
mysql> use school;
mysql> source /opt/school_comany.sqlbak;
恢复方法二:
[root@localhost opt]#mysql -uroot -p </opt/school_comany.sqlbak;
Enter password:
2、表的备份与恢复
[root@localhost opt]# mysqldump -uroot -p school teacher > /opt/rowteach.sqlbak;
//school是数据库teacher是表
Enter password:
恢复表方法一:
mysql> use school;
mysql> source /opt/rowteach.sqlbak;
恢复方法二:
[root@localhost opt]#mysql -uroot -p </opt/rowteach.sqlbak
Enter password:
3、对所有库进行备份
[root@localhost opt]# mysqldump -uroot -p --all-databases >/opt/all.sqlbak
Enter password:
恢复方法一:
mysql> source /opt/all.sqlbak;
恢复方法二:
[root@localhost opt]#mysql -uroot -p </opt/all.sqlbak
Enter password:
标签:opt,school,恢复,数据库,数据备份,uroot,mysql,sqlbak
From: https://www.cnblogs.com/SHUN-ReRound/p/18678880