第二步,停掉MySQL
[root@serv01 ~]# /etc/init.d/mysqld stop Shutting down MySQL... SUCCESS!
第三步,创建备份目录,并修改拥有者和所属组
[root@serv01 ~]# mkdir /databackup [root@serv01 ~]# chown mysql.mysql /databackup/ -R [root@serv01 ~]# ll /databackup/ -d drwxr-xr-x. 2 mysql mysql 4096 Sep 10 17:46 /databackup/ [root@serv01 ~]# cd /databackup/
第四步,冷备(使用tar命令)
[root@serv01 databackup]# tar -cvPzf mysql01.tar.gz
第五步,测试冷备的数据是否正常,我们删除掉data下的所有数据
[root@serv01 databackup]# rm -rf /usr/local/mysql/data/*
第六步,删除所有数据后数据库不能启动
[root@serv01 databackup]# /etc/init.d/mysqld start Starting MySQL.. ERROR! The server quit without updating PID file (/usr/local/mysql/data/serv01.host.com.pid).
第七步,恢复数据(使用tar命令)
[root@serv01 databackup]# tar -xvPf mysql01.tar.gz
第八步,启动MySQL,然后登录MySQL,查看数据是否丢失,如果数据正常代表冷备成功
[root@serv01 databackup]# /etc/init.d/mysqld start Starting MySQL.. SUCCESS! [root@serv01 ~]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.5.29-log Source distribution Copyright (c) 2000, 2012, 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> use larrydb; Database changed mysql> select * from class; +------+--------+ | cid | cname | +------+--------+ | 1 | linux | | 2 | oracle | +------+--------+ 2 rows in set (0.00 sec) mysql> select * from stu; +------+---------+------+ | sid | sname | cid | +------+---------+------+ | 1 | larry01 | 1 | | 2 | larry02 | 2 | +------+---------+------+ 2 rows in set (0.00 sec)
我的邮箱:wgbno27@163.com 新浪微博:@justdb 微信公众平台:JustOracle(微信号:justoracle) 数据库技术交流群:336882565(加群时验证 From CSDN XXX) All is well 2013年11月2日 By Larry Wen
@Wentasy |