MySQL数据库备份与恢复
数据库常用备份方案
数据库备份方案:
- 全量备份
- 增量备份
- 差异备份
备份方案 | 特点 |
---|---|
全量备份 | 全量备份就是指对某一个时间点上的所有数据或应用进行的一个完全拷贝。 数据恢复快。 备份时间长 |
增量备份 | 增量备份是指在一次全备份或上一次增量备份后,以后每次的备份只需备份 与前一次相比增加和者被修改的文件。这就意味着,第一次增量备份的对象 是进行全备后所产生的增加和修改的文件 第二次增量备份的对象是进行第一次增量 备份后所产生的增加和修改的文件,如此类推 没有重复的备份数据 备份时间短 恢复数据时必须按一定的顺序进行 |
差异备份 | 备份上一次的完全备份后发生变化的所有文件 差异备份是指在一次全备份后到进行差异备份的这段时间内 对那些增加或者修改文件的备份。在进行恢复时 我们只需对第一次全量备份和最后一次差异备份进行恢复 |
MySQL备份工具mysqldump
语法
mysqldump [OPTIONS] database [tables …]
mysqldump [OPTIONS] --all-databases [OPTIONS]
mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3…]
常用的选项:
-uUSERNAME //指定数据库用户名
-hHOST //指定服务器主机,请使用ip地址
-pPASSWORD //指定数据库用户的密码
-P# //指定数据库监听的端口,这里的#需用实际的端口号代替,如-P3307
//备份整个数据库(全量备份)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| test |
+--------------------+
5 rows in set (0.00 sec)
mysql> use test;
Database changed
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| test1 |
| test2 |
+----------------+
2 rows in set (0.00 sec)
[root@139 ~]# vim .my.cnf
[mysqldump]
user=root
password=123456
[root@139 ~]# mysqldump --all-databases > all-20220728.sql
[root@139 ~]# ls
all-20220728.sql anaconda-ks.cfg
//备份test库里的表
[root@139 ~]# mysqldump test test1 test2 > test_table-20220727.sql
[root@139 ~]# ls
all-20220728.sql anaconda-ks.cfg test_table-20220727.sql
//备份test库
[root@139 ~]# mysqldump --databases test > test_db-20220728.sql
[root@139 ~]# ls
all-20220728.sql anaconda-ks.cfg test_db-20220728.sql test_table-20220727.sql
MySQL数据恢复
//误删test数据库
mysql> drop database test;
Query OK, 2 rows affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
//恢复test数据库
[root@139 ~]# mysql -uroot -p123456 < test_db-20220728.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@139 ~]# mysql -uroot -p123456 -e "show databases;"
mysql: [Warning] Using a password on the command line interface can be insecure.
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| test |
+--------------------+
//恢复test库里的表
mysql> show tables;
Empty set (0.00 sec)
mysql> source test_table-20220727.sql
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected, 1 warning (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.01 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 10 rows affected (0.00 sec)
Records: 10 Duplicates: 0 Warnings: 0
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected, 1 warning (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| test1 |
| test2 |
+----------------+
2 rows in set (0.00 sec)
或者
mysql> show tables;
Empty set (0.00 sec)
mysql> quit
Bye
[root@139 ~]# mysql -uroot -p123456 test < test_table-20220727.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@139 ~]# mysql -uroot -p123456 -e "use test;show tables;"
mysql: [Warning] Using a password on the command line interface can be insecure.
+----------------+
| Tables_in_test |
+----------------+
| test1 |
| test2 |
+----------------+
//恢复整个数据库
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| performance_schema |
| sys |
+--------------------+
3 rows in set (0.00 sec)
mysql> source all-20220728.sql
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
.....
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| test |
+--------------------+
5 rows in set (0.00 sec)
差异备份与恢复
MySQL差异备份
开启MySQL服务器的二进制日志功能
[root@139 ~]# vim /etc/my.cnf
server-id=1
log-bin=mysql_bin
[root@139 ~]# service mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
数据库进行完全备份
[root@139 ~]# mysqldump --single-transaction --flush-logs --master-data=2 --all-databases --delete-master-logs > all-202207.sql
[root@139 ~]# ls
all-202207.sql anaconda-ks.cfg
给表修改内容
mysql> delete from test1 where id = 8;
Query OK, 1 row affected (0.00 sec)
mysql> delete from test1 where id = 3;
Query OK, 1 row affected (0.00 sec)
mysql> delete from test1 where id = 5;
Query OK, 1 row affected (0.00 sec)
mysql> insert into test1(name,age) value('ll',22);
Query OK, 1 row affected (0.00 sec)
mysql> select * from test1;
+----+-------+------+
| id | name | age |
+----+-------+------+
| 1 | one | 20 |
| 2 | two | 21 |
| 4 | four | 21 |
| 6 | six | 20 |
| 7 | seven | 23 |
| 9 | nine | 24 |
| 10 | ten | 26 |
| 11 | ll | 22 |
+----+-------+------+
8 rows in set (0.00 sec)
MySQL差异备份恢复
误删数据
mysql> drop database test;
Query OK, 2 rows affected (0.01 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
刷新创建新的二进制日志文件
[root@139 mysql_data]# ll -d mysql*
drwxr-x---. 2 mysql mysql 4096 Jul 28 21:17 mysql
-rw-r-----. 1 mysql mysql 1375 Jul 28 21:32 mysql_bin.000002
-rw-r-----. 1 mysql mysql 19 Jul 28 21:24 mysql_bin.index
-rw-r-----. 1 mysql mysql 6 Jul 28 21:22 mysql.pid
[root@139 mysql_data]# mysqladmin -uroot -p123456 flush-logs
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
[root@139 mysql_data]# ll -d mysql*
drwxr-x---. 2 mysql mysql 4096 Jul 28 21:17 mysql
-rw-r-----. 1 mysql mysql 1422 Jul 28 21:33 mysql_bin.000002
-rw-r-----. 1 mysql mysql 154 Jul 28 21:33 mysql_bin.000003
-rw-r-----. 1 mysql mysql 38 Jul 28 21:33 mysql_bin.index
-rw-r-----. 1 mysql mysql 6 Jul 28 21:22 mysql.pid
先恢复完全备份
[root@139 ~]# mysql -uroot -p123456 < all-202207.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@139 ~]# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.38-log MySQL Community Server (GPL)
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
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 |
| sys |
| test |
+--------------------+
5 rows in set (0.00 sec)
mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| test1 |
| test2 |
+----------------+
2 rows in set (0.00 sec)
mysql> select * from test1;
+----+-------+------+
| id | name | age |
+----+-------+------+
| 1 | one | 20 |
| 2 | two | 21 |
| 3 | three | 22 |
| 4 | four | 21 |
| 5 | five | 25 |
| 6 | six | 20 |
| 7 | seven | 23 |
| 8 | keven | 19 |
| 9 | nine | 24 |
| 10 | ten | 26 |
+----+-------+------+
10 rows in set (0.00 sec)
再恢复差异备份
//查看日志查找误删操作
mysql> show binlog events in 'mysql_bin.000002';
+------------------+------+----------------+-----------+-------------+---------------------------------------+
| Log_name | Pos | Event_type | Server_id | End_log_pos | Info |
+------------------+------+----------------+-----------+-------------+---------------------------------------+
| mysql_bin.000002 | 4 | Format_desc | 1 | 123 | Server ver: 5.7.38-log, Binlog ver: 4 |
| mysql_bin.000002 | 123 | Previous_gtids | 1 | 154 | |
| mysql_bin.000002 | 154 | Anonymous_Gtid | 1 | 219 | SET @@SESSION.GTID_NEXT= 'ANONYMOUS' |
| mysql_bin.000002 | 219 | Query | 1 | 291 | BEGIN |
| mysql_bin.000002 | 291 | Table_map | 1 | 343 | table_id: 140 (test.test1) |
| mysql_bin.000002 | 343 | Delete_rows | 1 | 390 | table_id: 140 flags: STMT_END_F |
| mysql_bin.000002 | 390 | Xid | 1 | 421 | COMMIT /* xid=482 */ |
| mysql_bin.000002 | 421 | Anonymous_Gtid | 1 | 486 | SET @@SESSION.GTID_NEXT= 'ANONYMOUS' |
| mysql_bin.000002 | 486 | Query | 1 | 558 | BEGIN |
| mysql_bin.000002 | 558 | Table_map | 1 | 610 | table_id: 140 (test.test1) |
| mysql_bin.000002 | 610 | Delete_rows | 1 | 657 | table_id: 140 flags: STMT_END_F |
| mysql_bin.000002 | 657 | Xid | 1 | 688 | COMMIT /* xid=483 */ |
| mysql_bin.000002 | 688 | Anonymous_Gtid | 1 | 753 | SET @@SESSION.GTID_NEXT= 'ANONYMOUS' |
| mysql_bin.000002 | 753 | Query | 1 | 825 | BEGIN |
| mysql_bin.000002 | 825 | Table_map | 1 | 877 | table_id: 140 (test.test1) |
| mysql_bin.000002 | 877 | Delete_rows | 1 | 923 | table_id: 140 flags: STMT_END_F |
| mysql_bin.000002 | 923 | Xid | 1 | 954 | COMMIT /* xid=484 */ |
| mysql_bin.000002 | 954 | Anonymous_Gtid | 1 | 1019 | SET @@SESSION.GTID_NEXT= 'ANONYMOUS' |
| mysql_bin.000002 | 1019 | Query | 1 | 1091 | BEGIN |
| mysql_bin.000002 | 1091 | Table_map | 1 | 1143 | table_id: 140 (test.test1) |
| mysql_bin.000002 | 1143 | Write_rows | 1 | 1187 | table_id: 140 flags: STMT_END_F |
| mysql_bin.000002 | 1187 | Xid | 1 | 1218 | COMMIT /* xid=486 */ |
| mysql_bin.000002 | 1218 | Anonymous_Gtid | 1 | 1283 | SET @@SESSION.GTID_NEXT= 'ANONYMOUS' |
| mysql_bin.000002 | 1283 | Query | 1 | 1375 | drop database test |
| mysql_bin.000002 | 1375 | Rotate | 1 | 1422 | mysql_bin.000003;pos=4 |
+------------------+------+----------------+-----------+-------------+---------------------------------------+
25 rows in set (0.00 sec)
//使用mysqlbinlog恢复差异备份
[root@139 ~]# mysqlbinlog --stop-position=1283 /opt/mysql_data/mysql_bin.000002 |mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@139 ~]# mysql -uroot -p123456 -e "select * from test.test1;"
mysql: [Warning] Using a password on the command line interface can be insecure.
+----+-------+------+
| id | name | age |
+----+-------+------+
| 1 | one | 20 |
| 2 | two | 21 |
| 4 | four | 21 |
| 6 | six | 20 |
| 7 | seven | 23 |
| 9 | nine | 24 |
| 10 | ten | 26 |
| 11 | ll | 22 |
+----+-------+------+
MySQL多实例部署
//下载二进制格式mysql包
[root@139]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz -C /opt/
//解压软件包
[root@139 opt]# tar xf mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
[root@139 opt]# ls
mysql-5.7.38-linux-glibc2.12-x86_64
//创建用户
[root@139 opt]# useradd -M -r -s /sbin/nologin mysql
[root@139 opt]# id mysql
uid=995(mysql) gid=992(mysql) groups=992(mysql)
//创建软连接
[root@139 opt]# ln -sv mysql-5.7.38-linux-glibc2.12-x86_64/ mysql
'mysql' -> 'mysql-5.7.38-linux-glibc2.12-x86_64/'
[root@139 opt]# ll
total 0
lrwxrwxrwx. 1 root root 36 Jul 26 18:34 mysql -> mysql-5.7.38-linux-glibc2.12-x86_64/
drwxr-xr-x. 9 root root 129 Jul 26 18:30 mysql-5.7.38-linux-glibc2.12-x86_64
//修改属主和属组
[root@139 opt]# chown -R mysql.mysql mysql
[root@139 opt]# chown -R mysql.mysql mysql-5.7.38-linux-glibc2.12-x86_64/
[root@139 opt]# ll
total 0
lrwxrwxrwx. 1 mysql mysql 36 Jul 26 18:34 mysql -> mysql-5.7.38-linux-glibc2.12-x86_64/
drwxr-xr-x. 9 mysql mysql 129 Jul 26 18:30 mysql-5.7.38-linux-glibc2.12-x86_64
//配置环境变量
[root@139 opt]# cd mysql
[root@139 mysql]# ls
bin docs include lib LICENSE man README share support-files
[root@139 mysql]# echo 'export PATH=$PATH:/opt/mysql/bin' >/etc/profile.d/mysql.sh
[root@139 mysql]# source /etc/profile.d/mysql.sh
[root@139 mysql]# which mysql
/opt/mysql/bin/mysql
[root@139 mysql]# ln -s /opt/mysql/include /usr/include/mysql
[root@139 mysql]# ll /usr/include/
total 0
lrwxrwxrwx. 1 root root 18 Jul 26 18:39 mysql -> /opt/mysql/include
[root@139 mysql]# echo '/opt/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
[root@139 mysql]# cat /etc/ld.so.conf.d/mysql.conf
/opt/mysql/lib
[root@139 mysql]# vim /etc/man_db.conf
MANDATORY_MANPATH /opt/mysql/man
//创建实例数据存放的目录
[root@139 ~]# mkdir -p /opt/mysql_data/{3306,3307,3308}
[root@139 ~]# ls /opt/mysql_data/
3306 3307 3308
[root@139 ~]# chown -R mysql.mysql /opt/mysql_data/
[root@139 ~]# ll /opt/mysql_data/
total 0
drwxr-xr-x. 2 mysql mysql 6 Jul 28 21:53 3306
drwxr-xr-x. 2 mysql mysql 6 Jul 28 21:53 3307
drwxr-xr-x. 2 mysql mysql 6 Jul 28 21:53 3308
//初始化实例
[root@139 ~]# mysqld --initialize --datadir=/opt/mysql_data/3306 --user=mysql
2022-07-28T13:55:54.038954Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-07-28T13:55:54.248843Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-07-28T13:55:54.277926Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-07-28T13:55:54.336678Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: ff7b7003-0e7c-11ed-a488-000c2994f252.
2022-07-28T13:55:54.338575Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-07-28T13:55:54.457929Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-07-28T13:55:54.458029Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-07-28T13:55:54.458506Z 0 [Warning] CA certificate ca.pem is self signed.
2022-07-28T13:55:54.505499Z 1 [Note] A temporary password is generated for root@localhost: RT=R5y)qtfgS
[root@139 ~]# echo "RT=R5y)qtfgS" > 3306
[root@139 ~]# mysqld --initialize --datadir=/opt/mysql_data/3307 --user=mysql
2022-07-28T13:56:30.073682Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-07-28T13:56:30.226436Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-07-28T13:56:30.259318Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-07-28T13:56:30.315416Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 14ed5bb5-0e7d-11ed-a53b-000c2994f252.
2022-07-28T13:56:30.316100Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-07-28T13:56:30.422984Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-07-28T13:56:30.423028Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-07-28T13:56:30.423392Z 0 [Warning] CA certificate ca.pem is self signed.
2022-07-28T13:56:30.513751Z 1 [Note] A temporary password is generated for root@localhost: a<nCVxF/#6;G
[root@139 ~]# echo "a<nCVxF/#6;G" >3307
[root@139 ~]# mysqld --initialize --datadir=/opt/mysql_data/3308 --user=mysql
2022-07-28T13:56:48.465821Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-07-28T13:56:48.656873Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-07-28T13:56:48.689024Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-07-28T13:56:48.748491Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 1fea05ae-0e7d-11ed-a875-000c2994f252.
2022-07-28T13:56:48.749098Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-07-28T13:56:48.919387Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-07-28T13:56:48.919420Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-07-28T13:56:48.919712Z 0 [Warning] CA certificate ca.pem is self signed.
2022-07-28T13:56:48.962207Z 1 [Note] A temporary password is generated for root@localhost: p2wtoygOV7<f
[root@139 ~]# echo "p2wtoygOV7<f" >3308
//安装perl
[root@139 ~]# dnf -y install perl
//配置文件配置
[root@139 ~]# vim /etc/my.cnf
[mysqld_multi]
mysqld = /opt/mysql/bin/mysqld_safe
mysqladmin = /opt/mysql/bin/mysqladmin
[mysqld3306]
datadir = /opt/mysql_data/3306
port = 3306
socket = /tmp/mysql3306.sock
pid-file = /opt/mysql_data/3306/mysql_3306.pid
log-error=/var/log/3306.log
[mysqld3307]
datadir = /opt/mysql_data/3307
port = 3307
socket = /tmp/mysql3307.sock
pid-file = /opt/mysql_data/3307/mysql_3307.pid
log-error=/var/log/3307.log
[mysqld3308]
datadir = /opt/mysql_data/3308
port = 3308
socket = /tmp/mysql3308.sock
pid-file = /opt/mysql_data/3308/mysql_3308.pid
log-error=/var/log/3308.log
//启动实例
[root@139 ~]# mysqld_multi start 3306
[root@139 ~]# mysqld_multi start 3307
[root@139 ~]# mysqld_multi start 3308
[root@139 ~]# ss -antl|grep 330
LISTEN 0 80 *:3306 *:*
LISTEN 0 80 *:3307 *:*
LISTEN 0 80 *:3308 *:*
//初始化密码
[root@139 ~]# mysql -uroot -p'RT=R5y)qtfgS' -S /tmp/mysql3306.sock
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.38
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
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> set password = password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> quit
Bye
[root@139 ~]# cat 3307
a<nCVxF/#6;G
[root@139 ~]# mysql -uroot -p'a<nCVxF/#6;G' -S /tmp/mysql3307.sock -e "set password = password('123456');" --connect-expired-password
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@139 ~]# cat 3308
p2wtoygOV7<f
[root@139 ~]# mysql -uroot -p'p2wtoygOV7<f' -S /tmp/mysql3308.sock -e "set password = password('123456');" --connect-expired-password
mysql: [Warning] Using a password on the command line interface can be insecure.