物理备份的方法:
冷备份(脱机备份)∶是在关闭数据库的时候进行的。
热备份(联机备份)︰数据库处于运行状态,依赖于数据库的日志文件。
温备份:数据库锁定表格(不可写入但可读)的状态下进行备份操作。
备份方式 | 完全备份 | 差异备份 | 增量备份 |
---|---|---|---|
完全备份时的状态 | 表1、表2 | 表1、表2 | 表1、表2 |
第一次添加内容 | 创建表3 | 创建表3 | 创建表3 |
备份内容 | 表1、表2 、表3 | 表3 | 表3 |
第二次添加内容 | 创建表4 | 创建表4 | 创建表4 |
备份内容 | 表1、表2 、表3、表4 | 表3、表4 | 表4 |
物理冷备:
备份时数据库处于关闭状态,直接打包数据库文件备份速度快,恢复时也是最简单的
专用备份工具mydump或mysqlhotcopy
mysqldump常用的逻辑备份工具
mysqlhotcopy仅拥有备份MyISAM和ARCHIVE表
启用二进制日志进行增量备份
进行增量备份,需要刷新二进制日志
第三方工具备份
免费的MySQL热备份软件Percona XtraBackup
完全备份是对整个数据库的备份、数据库结构和文件结构的备份
完全备份保存的是备份完成时刻的数据库
完全备份是增量备份的基础
完全备份是对整个数据库的备份、数据库结构和文件结构的备份
完全备份保存的是备份完成时刻的数据库
完全备份是增量备份的基础
yum -y install xz
打包文件夹 /usr/local/mysql/data/
systemctl stop mysqld
mkdir /backup
tar zxvf /backup/mysql_all-$(date + %F).tar.gz /usr/local/mysq/data/
##/usr/local/mysql/data备份压缩
对比打包前后的文件大小,可以看到压缩的备份文件占用空间很小
du -sh /backup/mysql-2020-12-24.tar.gz
du -sh /usr/local/mysq/data/
若数据库文件丢失,可以解压缩备份文件,相当于做了数据恢复操作
mkdir /restore
tar zxvf /backup/mysql_all-2020-12-24.tar.gz -C /restore/ ##时间节点可能不一样
mv /restore/usr/local/mysql/data/ /usr/local/mysql/ ##将备份数据移动到到/usr/local/mysql中
systemctl start mysqld ##启动mysql数据库
mysqldump -u 用户名 -p [密码] [选项] [数据库名] [数据表名] > /备份路径/备份文件名
示例:
mysqldump -uroot -p123456 imployee_salary IT_salary IT_desc > /opt/salary.sql
即对库imployee_salary中的表IT_salary、IT_desc进行备份,备份文件是 /opt/salary.sql
mysqldump -u 用户名 -p [密码] [选项] [数据库名] > /备份路径/备份文件名
示例:
mysqldump -uroot -p123456 imployee_salary > /opt/salary2.sql
即对库imployee_salary进行备份,备份文件是 /opt/salary2.sql
mysqldump -u 用户名 -p [密码] [选项] --databases 库名1 库名2... > /备份路径/备份文件名
示例:
mysqldump -uroot -p123456 imployee_salary test > /opt/salary3.sql
mysqldump -u 用户名 -p [密码] [选项] --all-databases > /备份路径/备份文件名
示例:
mysqldump -uroot -p123456 --all-databases > /opt/salary4.sql
mysqldump -u 用户名 -p [密码] -d 数据库名 表名 > /备份路径/备份文件名
示例:
mysqldump -uroot -p123456 -d imployee_salary IT_salary IT_desc > /opt/salary5.sql
[root@localhost ~]# mysqladmin -uroot -p password 'abc123' '//设置登录密码'
[root@localhost ~]# mysql -uroot -pabc123
...
mysql> create database auth; '//创建auth 这个数据库'
mysql> use auth; '//进入auth 这个数据库'
mysql> create table users (user_name CHAR(16) NOT NULL, user_passwd CHAR(48) DEFAULT '', PRIMARY KEY (user_name));
Database changed
mysql> insert into users(user_name,user_passwd) values('zhangsan', password('123456'));
Query OK, 1 row affected, 1 warning (0.00 sec)
mysql> insert into users values('lisi', password('123456'));
Query OK, 1 row affected, 1 warning (0.00 sec)
mysql> select * from users;
+-----------+-------------------------------------------+
| user_name | user_passwd |
+-----------+-------------------------------------------+
| lisi | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| zhangsan | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+-----------+-------------------------------------------+
2 rows in set (0.00 sec)
[root@localhost ~]# mysqldump -u root -p --databases auth > /opt/auth.sql '//备份auth数据库'
Enter password: '//输入数据库的登录密码 abc123'
[root@localhost ~]# cd /opt/
[root@localhost opt]# grep -v "^--" auth.sql | grep -v "^/" | grep -v "^$" '//查看备份文件'
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `auth` /*!40100 DEFAULT CHARACTER SET utf8 */;
USE `auth`;
DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
`user_name` char(16) NOT NULL,
`user_passwd` char(48) DEFAULT '',
PRIMARY KEY (`user_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
LOCK TABLES `users` WRITE;
INSERT INTO `users` VALUES ('lisi','*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9'),('zhangsan','*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9');
UNLOCK TABLES;
source命令 '//需要登录到数据库'
mysql命令 '//不需要登录到数据库'
登录到 MySQL 数据库
执行 source 备份sql脚本的路径(绝对路径)
mysql > source /备份路径/备份文件名 '//使用绝对路径'
mysql -u 用户名 -p[密码] 库名 < /备份路径/备份文件名
'//当数据库被删除后,恢复时需要先创建数据库名,不然会报错'
或者
mysql -u 用户名 -p[密码] < /备份路径/备份文件名
'//该命令不需要指定数据库,误删除后也不需要再创建数据库名'
[root@localhost ~]# cd /opt
[root@localhost opt]# ll '//查看数据库备份文件'
总用量 8
-rw-r--r--. 1 root root 2094 12月 24 16:34 auth.sql
drwxr-xr-x. 2 root root 6 3月 26 2015 rh
-rw-r--r--. 1 root root 1957 12月 24 16:34 user1.sql
[root@localhost opt]#
[root@localhost ~]# mysql -u root -p -e 'drop database auth' '//删除数据库auth'
Enter password: '//输入登录密码'
[root@localhost ~]# mysql -u root -p -e 'show databases' '//查看数据库,发现auth数据库已被删除'
Enter password:
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
[root@localhost ~]# mysql -u root -p < /opt/auth.sql
Enter password:
[root@localhost ~]# mysql -u root -p -e 'show databases'
mysql -u 用户名 -p[密码] 库名 < /备份路径/备份文件名
[root@localhost ~]# mysqldump -uroot -pabc123 auth users > /opt/user1.sql
mysqldump: [Warning] Using a password on the command line interface can be insecure.
[root@localhost ~]# cd /opt/
[root@localhost opt]# ll
总用量 8
-rw-r--r--. 1 root root 2094 12月 24 16:06 auth.sql
drwxr-xr-x. 2 root root 6 3月 26 2015 rh
-rw-r--r--. 1 root root 1957 12月 24 16:19 user1.sql
[root@localhost ~]# mysql -uroot -pabc123
...
mysql> use auth; //使用auth数据库
Database changed
mysql> show tables; //查看auth库中包含的表
+----------------+
| Tables_in_auth |
+----------------+
| users |
+----------------+
1 row in set (0.00 sec)
mysql> select * from users; //查看表里的内容
+-----------+-------------------------------------------+
| user_name | user_passwd |
+-----------+-------------------------------------------+
| lisi | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| zhangsan | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+-----------+-------------------------------------------+
2 rows in set (0.00 sec)
mysql> drop table users; //删除users表
Query OK, 0 rows affected (0.00 sec)
mysql> select * from users;
ERROR 1146 (42S02): Table 'auth.users' doesn't exist
[root@localhost ~]# mysql -uroot -pabc123 auth < /opt/user1.sql
[root@localhost ~]# mysql -uroot -pabc123
...
mysql> use auth;
Database changed
mysql> show tables;
+----------------+
| Tables_in_auth |
+----------------+
| users |
+----------------+
1 row in set (0.00 sec)
mysql> select * from users;
+-----------+-------------------------------------------+
| user_name | user_passwd |
+-----------+-------------------------------------------+
| lisi | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| zhangsan | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+-----------+-------------------------------------------+
2 rows in set (0.00 sec)
1.二进制日志保存了所有更新或者可能更新数据的操作。
2.二进制日志在启动mysql服务器后开始记录,并在文件达到二进制日志所设置的最大值或者接受到flush logs命令后重新创建新的日志文件
3.只需要定时执行 flush logs 方法重新创建新的日志文件,生成二进制的文件序列,并及时把这些日志文件保存到安全的存储位置,即可完成一个时间段的增量备份
[root@localhost ~]# vi /etc/my.cnf
[client]
port = 3306
default-character-set = utf8
socket = /usr/local/mysql/mysql.sock
[mysql]
port = 3306
default-character-set = utf8
socket = /usr/local/mysql/mysql.sock
[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
character_set_server = utf8
pid-file = /usr/local/mysql/mysqld.pid
socket = /usr/local/mysql/mysql.sock
server-id = 1
log-bin=/usr/local/mysql/data/mysql-bin //添加该配置,开启二进制日志功能
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES
[root@localhost ~]# systemctl restart mysqld
[root@localhost ~]# ll /usr/local/mysql/data/
总用量 122924
drwxr-x---. 2 mysql mysql 54 12月 24 17:17 auth
-rw-r-----. 1 mysql mysql 56 12月 23 01:08 auto.cnf
-rw-r-----. 1 mysql mysql 414 12月 24 17:46 ib_buffer_pool
-rw-r-----. 1 mysql mysql 12582912 12月 24 17:46 ibdata1
-rw-r-----. 1 mysql mysql 50331648 12月 24 17:46 ib_logfile0
-rw-r-----. 1 mysql mysql 50331648 12月 23 01:08 ib_logfile1
-rw-r-----. 1 mysql mysql 12582912 12月 24 17:46 ibtmp1
drwxr-x---. 2 mysql mysql 4096 12月 23 01:08 mysql
-rw-r-----. 1 mysql mysql 154 12月 24 17:46 mysql-bin.000001 //日志文件已生成
-rw-r-----. 1 mysql mysql 39 12月 24 17:46 mysql-bin.index
drwxr-x---. 2 mysql mysql 8192 12月 23 01:08 performance_schema
drwxr-x---. 2 mysql mysql 8192 12月 23 01:08 sys
[root@localhost ~]# mkdir /opt/bak_sql
使用mysqldump 备份auth库的users表
[root@localhost ~]# mysqldump -u root -p auth users >/opt/bak_sql/auth_users-$(date +%F).sql
//注意括号中%F 的F必须是大写的
[root@localhost ~]# ll /opt/bak_sql
总用量 4
-rw-r--r--. 1 root root 1961 12月 24 19:57 auth_users-2020-12-24.sql
使用mysqldump 备份auth库的users表
[root@localhost ~]# mysqldump -u root -p --databases auth > /opt/bak_sql/auth-$(date +%F).sql
[root@localhost ~]# ll /opt/bak_sql
总用量 8
-rw-r--r--. 1 root root 2098 12月 24 19:58 auth-2020-12-24.sql
-rw-r--r--. 1 root root 1961 12月 24 19:57 auth_users-2020-12-24.sql
[root@localhost ~]# ll /usr/local/mysql/data/
...
-rw-r-----. 1 mysql mysql 154 12月 24 17:46 mysql-bin.000001
[root@localhost ~]# mysqladmin -uroot -pabc123 flush-logs
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
[root@localhost ~]# ll /usr/local/mysql/data/
...
-rw-r-----. 1 mysql mysql 201 12月 24 20:04 mysql-bin.000001
-rw-r-----. 1 mysql mysql 154 12月 24 20:04 mysql-bin.000002 //新生成的二进制文件
mysql> insert into users values('chenmou', password('123456'));
mysql> insert into users values('yangguo', password('123456'));
mysql> insert into users values('ningque', password('123456'));
mysql> insert into users values('yeyou', password('123456'));
[root@localhost ~]# mysqladmin -uroot -pabc123 flush-logs
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
[root@localhost ~]# ll /usr/local/mysql/data/
...
-rw-r-----. 1 mysql mysql 201 12月 24 20:04 mysql-bin.000001
-rw-r-----. 1 mysql mysql 1427 12月 25 00:01 mysql-bin.000002 //保存本次操作的数据
-rw-r-----. 1 mysql mysql 154 12月 25 00:01 mysql-bin.000003 //新生成的日志文件
[root@localhost data]# mysqlbinlog --no-defaults --base64-output=decode-rows -v /usr/local/mysql/data/mysql-bin.000002
//使用64位解码器查看日志
[root@localhost data]# cp mysql-bin.000002 /opt/bak_sql/
[root@localhost data]# ls /opt/bak_sql/
auth-2020-12-24.sql auth_users-2020-12-24.sql mysql-bin.000003
mysqlbinlog [--no-defaults] 增量备份文件 | mysql -u 用户名 -p
mysqlbinlog [--no-defaults] --stop-datetime='年-月-日 小时:分钟:秒' 二进制日志 | mysql -u 用户名 -p 密码
mysqlbinlog [--no-defaults] --start-datetime='年-月-日 小时:分钟:秒' 二进制日志 | mysql -u 用户名 -p 密码
mysqlbinlog [--no-defaults] --start-datetime='年-月-日 小时:分钟:秒' --stop-datetime='年-月-日小时:分钟:秒' 二进制日志 | mysql -u 用户名 -p 密码
mysqlbinlog --stop-position='操作id' 二进制日志 | mysql -u 用户名 -p 密码
mysqlbinlog --start-position='操作id' 二进制日志 | mysql -u 用户名 -p 密码
(1)查看数据库与表的内容
[root@localhost ~]# mysql -uroot -pabc123
...
mysql> use auth;
Database changed
mysql> select * from users;
+-----------+-------------------------------------------+
| user_name | user_passwd |
+-----------+-------------------------------------------+
| chenmou | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| lisi | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| ningque | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| yangguo | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| yeyou | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| zhangsan | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+-----------+-------------------------------------------+
6 rows in set (0.00 sec)
(2)由于我们在之前已经进行了完全备份与增量备份,所以我们可以直接进行模拟误操作:删除 users 表
[root@localhost ~]# mysql -u root -p -e 'drop table auth.users'
Enter password:
[root@localhost ~]# mysql -u root -p -e 'select * from auth.users'
Enter password:
ERROR 1146 (42S02) at line 1: Table 'auth.users' doesn't exist
(3)恢复操作
先恢复完全备份
[root@localhost ~]# mysql -u root -p auth < /opt/bak_sql/auth_users-2020-12-24.sql
Enter password:
[root@localhost ~]# mysql -u root -p -e 'select * from auth.users'
Enter password:
+-----------+-------------------------------------------+
| user_name | user_passwd |
+-----------+-------------------------------------------+
| lisi | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| zhangsan | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+-----------+-------------------------------------------+
再恢复增量备份
[root@localhost ~]# mysqlbinlog --no-defaults /opt/bak_sql/mysql-bin.000002 | mysql -u root -p
Enter password:
[root@localhost ~]# mysql -u root -p -e'select * from auth.users'
Enter password:
+-----------+-------------------------------------------+
| user_name | user_passwd |
+-----------+-------------------------------------------+
| chenmou | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| lisi | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| ningque | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| yangguo | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| yeyou | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| zhangsan | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+-----------+-------------------------------------------+
[root@localhost ~]# mysqladmin -uroot -pabc123 flush-logs //先进行二进制文件分割
[root@localhost ~]# ll /usr/local/mysql/data/
...
-rw-r-----. 1 mysql mysql 154 12月 25 01:27 mysql-bin.000005 //新生成的二进制编号为5
[root@localhost ~]# mysql -uroot -pabc123
...
mysql> use auth;
mysql> insert into users values('shunce', password('123456'));
mysql> delete from users where user_name='yeyou'; //误操作删除了该表中的数据
mysql> insert into users values('xunyu', password('123456'));
mysql> select * from users;
+-----------+-------------------------------------------+
| user_name | user_passwd |
+-----------+-------------------------------------------+
| chenmou | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| lisi | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| ningque | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| shunce | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| xunyu | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| yangguo | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| zhangsan | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+-----------+-------------------------------------------+
7 rows in set (0.00 sec)
查看日志得
[root@localhost ~]# mysqlbinlog --no-defaults --base64-output=decode-rows -v /usr/local/mysql/data/mysql-bin.000005
...
BEGIN
/*!*/;
# at 291
#201225 1:33:47 server id 1 end_log_pos 344 CRC32 0xa03426c5 Table_map: `auth`.`users` mapped to number 222
# at 344
#201225 1:33:47 server id 1 end_log_pos 429 CRC32 0x3b0b632c Write_rows: table id 222 flags: STMT_END_F
### INSERT INTO `auth`.`users`
### SET
### @1='shunce'
### @2='*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9'
# at 429
#201225 1:33:47 server id 1 end_log_pos 460 CRC32 0x3960a0dc Xid = 112
COMMIT/*!*/;
# at 460
#201225 1:36:34 server id 1 end_log_pos 525 CRC32 0x34a56ff0 Anonymous_GTID last_committed=1 sequence_number=2rbr_only=yes
/*!50718 SET TRANSACTION ISOLATION LEVEL READ COMMITTED*//*!*/;
SET @@SESSION.GTID_NEXT= 'ANONYMOUS'/*!*/;
# at 525
#201225 1:36:34 server id 1 end_log_pos 597 CRC32 0x9da7f4e2 Query thread_id=18 exec_time=0 error_code=0
SET TIMESTAMP=1608831394/*!*/;
BEGIN
/*!*/;
# at 597
#201225 1:36:34 server id 1 end_log_pos 650 CRC32 0xebc35266 Table_map: `auth`.`users` mapped to number 222
# at 650
#201225 1:36:34 server id 1 end_log_pos 734 CRC32 0xbc048847 Delete_rows: table id 222 flags: STMT_END_F
### DELETE FROM `auth`.`users`
### WHERE
### @1='yeyou'
### @2='*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9'
# at 734
#201225 1:36:34 server id 1 end_log_pos 765 CRC32 0x479205b1 Xid = 114
COMMIT/*!*/;
# at 765
#201225 1:37:09 server id 1 end_log_pos 830 CRC32 0xf2faf11d Anonymous_GTID last_committed=2 sequence_number=3rbr_only=yes
/*!50718 SET TRANSACTION ISOLATION LEVEL READ COMMITTED*//*!*/;
SET @@SESSION.GTID_NEXT= 'ANONYMOUS'/*!*/;
# at 830
#201225 1:37:09 server id 1 end_log_pos 902 CRC32 0x88940503 Query thread_id=18 exec_time=0 error_code=0
SET TIMESTAMP=1608831429/*!*/;
BEGIN
/*!*/;
# at 902
#201225 1:37:09 server id 1 end_log_pos 955 CRC32 0xb69735e9 Table_map: `auth`.`users` mapped to number 222
# at 955
#201225 1:37:09 server id 1 end_log_pos 1039 CRC32 0xf1e87994 Write_rows: table id 222 flags: STMT_END_F
### INSERT INTO `auth`.`users`
### SET
### @1='xunyu'
### @2='*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9'
# at 1039
#201225 1:37:09 server id 1 end_log_pos 1070 CRC32 0x3f5b606f Xid = 115
COMMIT/*!*/;
...
[root@localhost ~]# mysqlbinlog --no-defaults --base64-output=decode-rows -v /usr/local/mysql/data/mysql-bin.000005 > /opt/bak.txt
//也可以将日志文件导成txt文本,方便查看
[root@localhost ~]# vi /opt/bak.txt
[root@localhost ~]# mysqlbinlog --no-defaults --stop-datetime='2020-12-25 1:36:34' /usr/local/mysql/data/mysql-bin.000005 | mysql -u root -pabc123
[root@localhost ~]# mysqlbinlog --no-defaults --start-datetime='2020-12-25 1:37:09' /usr/local/mysql/data/mysql-bin.000005 | mysql -u root -pabc123
[root@localhost ~]# mysql -u root -p -e 'select * from auth.users'
Enter password:
+-----------+-------------------------------------------+
| user_name | user_passwd |
+-----------+-------------------------------------------+
| chenmou | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| lisi | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| ningque | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| yangguo | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| yeyou | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| shunce | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| xunyu | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| zhangsan | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+-----------+-------------------------------------------+
[root@localhost ~]# mysqlbinlog --no-defaults --stop-position='650' /usr/local/mysql/data/mysql-bin.000005 | mysql -u root -pabc123
[root@localhost ~]# mysqlbinlog --no-defaults --start-position='955' /usr/local/mysql/data/mysql-bin.000005 | mysql -u root -pabc123
[root@localhost ~]# mysql -u root -p -e 'select * from auth.users'
Enter password:
+-----------+-------------------------------------------+
| user_name | user_passwd |
+-----------+-------------------------------------------+
| chenmou | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| lisi | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| ningque | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| yangguo | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| yeyou | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| shunce | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| xunyu | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| zhangsan | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+-----------+-------------------------------------------+
(1)MySQL中使用mysqldump工具备份,它生成的是SQL脚本文件
(2)MySQL没有提供增量备份的工具,需要借助二进制日志文件进行操作