MySQL备份工具之mysqlhotcopy(2)

[root@tong2 ~]# ll /var/lib/mysql/{mysql,tong} -d
drwxr-xr-x. 2 mysql mysql 4096 Jan  5 15:29 /var/lib/mysql/mysql
drwxr-xr-x. 2 mysql mysql 4096 Jan  5 15:29 /var/lib/mysql/tong
[root@tong2 ~]#

5.备份数据库中某一个表

[root@tong2 ~]# mysqlhotcopy -u root -p system mysql./user*/ /opt/

[root@tong2 ~]# ll /opt/mysql/
total 20
-rw-r--r--. 1 mysql mysql 10684 Jan  4 16:49 user.frm
-rw-r--r--. 1 mysql mysql  784 Jan  4 16:49 user.MYD
-rw-r--r--. 1 mysql mysql  2048 Jan  4 16:49 user.MYI

[root@tong2 ~]# ll /var/lib/mysql/mysql/user.*
-rw-r--r--. 1 mysql mysql 10684 Jan  4 16:49 /var/lib/mysql/mysql/user.frm
-rw-r--r--. 1 mysql mysql  784 Jan  4 16:49 /var/lib/mysql/mysql/user.MYD
-rw-r--r--. 1 mysql mysql  2048 Jan  4 16:49 /var/lib/mysql/mysql/user.MYI
[root@tong2 ~]#

6.恢复数据

[root@tong2 ~]# rm -rf /var/lib/mysql/tong
[root@tong2 ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 29
Server version: 5.6.21-log MySQL Community Server (GPL)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database          |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test              |
+--------------------+
4 rows in set (0.00 sec)

mysql> exit
Bye

[root@tong2 ~]# cp -arp /opt/tong /var/lib/mysql/        --将备份的数据移到mysql数据根目录
[root@tong2 ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 30
Server version: 5.6.21-log MySQL Community Server (GPL)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> \u tong
Database changed
mysql> show tables;
+----------------+
| Tables_in_tong |
+----------------+
| t              |
+----------------+
2 rows in set (0.00 sec)

mysql> exit
Bye

[root@tong2 ~]#

MySQL备份和恢复具体实施

MySQL备份:mylvmbackup介绍与使用

Linux下通过mysqldump备份MySQL数据库成sql文件

Linux中使用mysqldump对MySQL数据库进行定时备份

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/9b9948c57c6da12b6f6b646b5a010262.html