当前位置:   article > 正文

MySQL数据库冷备份_mysql冷备份

mysql冷备份

进入数据库 
  [root@localhost ~]# mysql -u root -p
创建库
 mysql> create database auth; (Query OK, 1 row affected (0.00 sec)

切换到库
mysql> use auth;  (Database changed

创建表

mysql> create table users (user_name char(16) not null,user_passwd char(48) default '');

Query OK, 0 rows affected (0.01 sec)

插入数据记录
mysql> insert into users values('zhangsan',password('123456'));
Query OK, 1 row affected (0.01 sec)

mysql> insert into users values('lisi',password('123456'));
Query OK, 1 row affected (0.00 sec)

物理冷备份与恢复:

[root@localhost ~]# systemctl stop mysqld
[root@localhost ~]# mkdir /backup

[root@localhost ~]# cd /usr/local/mysql/

[root@localhost mysql]# ls
bin      data  include  man     mysql-test  scripts  sql-bench
COPYING  docs  lib      my.cnf  README      share    support-files

[root@localhost mysql]# tar zcvf /backup/pb.tar.gz /usr/local/mysql/data/  (压缩到backup/pb.tar.gz )


[root@localhost mysql]# ls
bin      data  include  man     mysql-test  scripts  sql-bench
COPYING  docs  lib      my.cnf  README      share    support-files
[root@localhost mysql]# 
[root@localhost mysql]# 
[root@localhost mysql]# 
[root@localhost mysql]# rm -rf data/
[root@localhost mysql]# ls
bin      docs     lib  my.cnf      README   share      support-files
COPYING  include  man  mysql-test  scripts  sql-bench


[root@localhost mysql]# cd /backup
[root@localhost backup]# 
[root@localhost backup]# 
[root@localhost backup]# 
[root@localhost backup]# ls
pb.tar.gz
[root@localhost backup]# 
[root@localhost backup]# 
[root@localhost backup]# tar zxvf pb.tar.gz 

[root@localhost backup]# ls
pb.tar.gz  usr
[root@localhost backup]# cd usr

[root@localhost usr]# ls
local

[root@localhost usr]# cd local/
[root@localhost local]# ls
mysql

[root@localhost local]# cd mysql/
[root@localhost mysql]# ls
data


[root@localhost mysql]# mv data/ /usr/local/mysql/

[root@localhost mysql]# cd /usr/local/mysql/
[root@localhost mysql]# 
[root@localhost mysql]# 
[root@localhost mysql]# ls
bin      data  include  man     mysql-test  scripts  sql-bench
COPYING  docs  lib      my.cnf  README      share    support-files
[root@localhost mysql]# 
[root@localhost mysql]# 
[root@localhost mysql]# systemctl start mysqld


[root@localhost mysql]# mysql -u root -p
Enter password:

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
+--------------------+
1 row in set (0.00 sec)

mysql>  Ctrl-C -- exit!
Aborted
 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/594386
推荐阅读
相关标签
  

闽ICP备14008679号