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
 

你可能感兴趣的:(摘要,数据库,mysql,服务器)