mysql数据库备份与恢复,mysql多实例部署

mysql数据库备份与恢复,mysql多实例部署

1: 数据库备份

备份是数据安全的最后一道防线,对于任何数据丢失的场景,备份虽然不一定能恢复百分之百的数据(取决于备份周期),但至少能将损失降到最低。衡量备份恢复有两个重要的指标:恢复点目标(RPO)和恢复时间目标(RTO),前者重点关注能恢复到什么程度,而后者则重点关注恢复需要多长时间

2:冷备份

最简单的备份方式就是,关闭MySQL服务器,然后将data目录下面的所有文件进行拷贝保存,需要恢复时,则将目录拷贝到需要恢复的机器即可。这种方式确实方便,但是在生产环境中基本没什么作用。因为所有的机器都是要提供服务的,即使是Slave有时候也需要提供只读服务,所以关闭MySQL停服备份是不现实的。

3:热备份

与冷备份相对应的一个概念是热备份,所谓热备份是在不影响MySQL对外服务的情况下,进行备份,热备份是这篇文章讨论的重点。

##数据库常用备份方案
数据库备份方案:

全量备份
增量备份
差异备份

备份方案特点
全量备份全量备份就是指对某一个时间点上的所有数据或应用进行的一个完全拷贝。
数据恢复快。
备份时间长
增量备份增量备份是指在一次全备份或上一次增量备份后,以后每次的备份只需备份
与前一次相比增加和者被修改的文件。这就意味着,第一次增量备份的对象是进行全备后所产生的增加和修改的文件;第二次增量备份的对象是进行第一次增量备份后所产生的增加和修改的文件,如此类推。
没有重复的备份数据
备份时间短
恢复数据时必须按一定的顺序进行
差异备份备份上一次的完全备份后发生变化的所有文件。
差异备份是指在一次全备份后到进行差异备份的这段时间内
对那些增加或者修改文件的备份。在进行恢复时,我们只需对第一次全量备份和最后一次差异备份进行恢复。

4: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                |
| nian               |
+--------------------+
5 rows in set (0.00 sec)

mysql> use nian;
Database changed
mysql> show tables;
+----------------------+
| Tables_in_wangqingge |
+----------------------+
| xuan                 |
+----------------------+
3 rows in set (0.00 sec)

[root@localhost ~]# ls
anaconda-ks.cfg
[root@localhost ~]# mysqldump -uroot -p -h127.0.0.1 --all-databases > all-2022-07-28.sql
Enter password:
[root@localhost ~]# ls
all-2022-07-28.sql  anaconda-ks.cfg

备份库和表


//备份wangqingge库的wangqing表和guohui表
[root@localhost ~]# mysqldump -uroot -p -h127.0.0.1 nian xuan > table-2022-07-28.sql
Enter password:
[root@localhost ~]# ls
all2022-07-28.sql  anaconda-ks.cfg  table2022-07-28.sql




//备份wangqingge库
[root@localhost ~]# mysqldump -uroot -p -h127.0.0.1 --databases  nian > nian2022-07-28.sql
Enter password:
[root@localhost ~]# ls
all2022-07-28.sql  table2022-07-28.sql
anaconda-ks.cfg       nian2022-07-28.sql

删除库


mysql> drop database nian;
Query OK, 3 rows affected (0.02 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

恢复库

[root@localhost ~]# ls
all2022-07-28.sql  table2022-07-28.sql
anaconda-ks.cfg       nian2022-07-28.sql
[root@localhost ~]# mysql -uroot -p -h127.0.0.1 < nian2022-07-28.sql.sql
Enter password:
[root@localhost ~]# mysql -uroot -p -h127.0.0.1 -e 'show databases;'
Enter password:
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
|nian                |
+--------------------+

恢复表

mysql> use nian;
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> source table2022-07-28.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)

mysql> show tables;
+----------------------+
| Tables_in_wangqingge |
+----------------------+
| nian                 |
+----------------------+
3 rows in set (0.00 sec)

5:差异备份

开启mysql服务器的二进制文件

[root@localhost ~]#  vim /etc/my.cnf
root@localhost ~]# systemctl restart mysqld.service
server-id=1
log-bin=mysql_bin

差异备份开始必须从全量开始所以先对数据库进行全量备份


[root@localhost ~]# 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 2
Server version: 5.7.39-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              |
| nian               |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.00 sec)

mysql> use nian
Database changed
mysql> show tables;
+----------------+
| Tables_in_nian |
+----------------+
| xuan           |
+----------------+
1 row in set (0.00 sec)

mysql> select * from xuan;
+----+----------+------+
| id | name     | age  |
+----+----------+------+
|  1 | zhangsan |   20 |
|  2 | lisi     |   21 |
+----+----------+------+
2 rows in set (0.00 sec)




[root@localhost ~]# mysqldump -uroot -p123456   --all-databases  > all20220728.sql
mysqldump: [Warning] Using a password on the command line interface can be insecure.
[root@localhost ~]# ls
公共  视频  文档  音乐  all20220728.sql  hh6gp
模板  图片  下载  桌面  anaconda-ks.cfg  initial-setup-ks.cfg
[root@localhost ~]#

增加新内容


mysql> insert xuan(name ,age) values ('wangwu',23);
Query OK, 1 row affected (0.00 sec)

mysql> insert xuan(name ,age) values ('xuanning',24);
Query OK, 1 row affected (0.00 sec)

mysql> insert xuan(name ,age) values ('xuan',25);
Query OK, 1 row affected (0.00 sec)

mysql> insert xuan(name ,age) values ('nianxia',26);
Query OK, 1 row affected (0.00 sec)

mysql> insert xuan(name ,age) values ('xia',27);
Query OK, 1 row affected (0.01 sec)


mysql> delete from xuan where name = 'nianxia';
Query OK, 1 row affected (0.00 sec)

mysql> delete from xuan where name = 'xuan';
Query OK, 1 row affected (0.00 sec)

mysql> delete from xuan where name = 'xuanning';
Query OK, 1 row affected (0.00 sec)

mysql> delete from xuan where name = 'wangwu';
Query OK, 1 row affected (0.00 sec)

mysql>

删除数据库模拟误删




mysql> drop database nian;
Query OK, 1 row affected (0.01 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

刷新创建的二进制文件



[root@localhost ~]# ll /var/lib/mysql
总用量 122960
-rw-r-----. 1 mysql mysql       56 7月  29 09:05 auto.cnf
-rw-------. 1 mysql mysql     1676 7月  29 09:05 ca-key.pem
-rw-r--r--. 1 mysql mysql     1112 7月  29 09:05 ca.pem
-rw-r--r--. 1 mysql mysql     1112 7月  29 09:05 client-cert.pem
-rw-------. 1 mysql mysql     1676 7月  29 09:05 client-key.pem
-rw-r-----. 1 mysql mysql      282 7月  29 09:38 ib_buffer_pool
-rw-r-----. 1 mysql mysql 12582912 7月  29 09:55 ibdata1
-rw-r-----. 1 mysql mysql 50331648 7月  29 09:55 ib_logfile0
-rw-r-----. 1 mysql mysql 50331648 7月  29 09:05 ib_logfile1
-rw-r-----. 1 mysql mysql 12582912 7月  29 09:47 ibtmp1
drwxr-x---. 2 mysql mysql     4096 7月  29 09:05 mysql
-rw-r-----. 1 mysql mysql     3521 7月  29 09:55 mysql_bin.000001
-rw-r-----. 1 mysql mysql       19 7月  29 09:38 mysql_bin.index
srwxrwxrwx. 1 mysql mysql        0 7月  29 09:38 mysql.sock
-rw-------. 1 mysql mysql        5 7月  29 09:38 mysql.sock.lock
drwxr-x---. 2 mysql mysql     8192 7月  29 09:05 performance_schema
-rw-------. 1 mysql mysql     1680 7月  29 09:05 private_key.pem
-rw-r--r--. 1 mysql mysql      452 7月  29 09:05 public_key.pem
-rw-r--r--. 1 mysql mysql     1112 7月  29 09:05 server-cert.pem
-rw-------. 1 mysql mysql     1676 7月  29 09:05 server-key.pem
drwxr-x---. 2 mysql mysql     8192 7月  29 09:05 sys
[root@localhost ~]# mysqladmin -uroot -p123456 flush-logs
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
[root@localhost ~]# ll /var/lib/mysql
总用量 122964
-rw-r-----. 1 mysql mysql       56 7月  29 09:05 auto.cnf
-rw-------. 1 mysql mysql     1676 7月  29 09:05 ca-key.pem
-rw-r--r--. 1 mysql mysql     1112 7月  29 09:05 ca.pem
-rw-r--r--. 1 mysql mysql     1112 7月  29 09:05 client-cert.pem
-rw-------. 1 mysql mysql     1676 7月  29 09:05 client-key.pem
-rw-r-----. 1 mysql mysql      282 7月  29 09:38 ib_buffer_pool
-rw-r-----. 1 mysql mysql 12582912 7月  29 09:55 ibdata1
-rw-r-----. 1 mysql mysql 50331648 7月  29 09:55 ib_logfile0
-rw-r-----. 1 mysql mysql 50331648 7月  29 09:05 ib_logfile1
-rw-r-----. 1 mysql mysql 12582912 7月  29 09:47 ibtmp1
drwxr-x---. 2 mysql mysql     4096 7月  29 09:05 mysql
-rw-r-----. 1 mysql mysql     3568 7月  29 09:57 mysql_bin.000001
-rw-r-----. 1 mysql mysql      154 7月  29 09:57 mysql_bin.000002
-rw-r-----. 1 mysql mysql       38 7月  29 09:57 mysql_bin.index
srwxrwxrwx. 1 mysql mysql        0 7月  29 09:38 mysql.sock
-rw-------. 1 mysql mysql        5 7月  29 09:38 mysql.sock.lock
drwxr-x---. 2 mysql mysql     8192 7月  29 09:05 performance_schema
-rw-------. 1 mysql mysql     1680 7月  29 09:05 private_key.pem
-rw-r--r--. 1 mysql mysql      452 7月  29 09:05 public_key.pem
-rw-r--r--. 1 mysql mysql     1112 7月  29 09:05 server-cert.pem
-rw-------. 1 mysql mysql     1676 7月  29 09:05 server-key.pem
drwxr-x---. 2 mysql mysql     8192 7月  29 09:05 sys
[root@localhost ~]#

恢复全量备份


mysql> source all20220728.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 binlog events in 'mysql_bin.000001';
+------------------+------+----------------+-----------+-------------+-------------------------------------------------------------------------------------------------------+
| Log_name         | Pos  | Event_type     | Server_id | End_log_pos | Info                                                                                                  |
+------------------+------+----------------+-----------+-------------+-------------------------------------------------------------------------------------------------------+
| mysql_bin.000001 |    4 | Format_desc    |         1 |         123 | Server ver: 5.7.39-log, Binlog ver: 4                                                                 |
| mysql_bin.000001 |  123 | Previous_gtids |         1 |         154 |                                                                                                       |
| mysql_bin.000001 |  154 | Anonymous_Gtid |         1 |         219 | SET @@SESSION.GTID_NEXT= 'ANONYMOUS'                                                                  |
| mysql_bin.000001 |  219 | Query          |         1 |         382 | use `nian`; create table xuan(id int not null  primary key  auto_increment,name varchar(50) ,age int) |
.................
.................
                |
| mysql_bin.000001 | 3282 | Delete_rows    |         1 |        3333 | table_id: 109 flags: STMT_END_F                                                                       |
| mysql_bin.000001 | 3333 | Xid            |         1 |        3364 | COMMIT /* xid=1707 */                                                                                 |
| mysql_bin.000001 | 3364 | Anonymous_Gtid |         1 |        3429 | SET @@SESSION.GTID_NEXT= 'ANONYMOUS'                                                                  |
| mysql_bin.000001 | 3429 | Query          |         1 |        3521 | drop database nian                                                                                    |
| mysql_bin.000001 | 3521 | Rotate         |         1 |        3568 | mysql_bin.000002;pos=4                                                                                |
+------------------+------+----------------+-----------+-------------+-------------------------------------------------------------------------------------------------------+
62 rows in set (0.00 sec)

mysql> drop table xuan;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye
[root@localhost ~]# mysqlbinlog --stop-position=3429 /var/lib/mysql/mysql_bin.000001 |mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@localhost ~]# 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 22
Server version: 5.7.39-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> use nian
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_nian |
+----------------+
| xuan           |
+----------------+
1 row in set (0.00 sec)

mysql> select * from xuan;
+----+----------+------+
| id | name     | age  |
+----+----------+------+
|  1 | zhangsan |   20 |
|  2 | lisi     |   21 |
+----+----------+------+
2 rows in set (0.00 sec)

6:mysql多实例部署

配置用户和组并解压二进制程序至/usr/local下


[root@localhost src]# ls
debug  kernels  mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
[root@localhost src]# useradd -M -s /sbin/nologin  mysql
[root@localhost src]#  tar xf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz  -C /usr/local/
[root@localhost src]# ls /usr/local/
bin  games    lib    libexec                              sbin   src
etc  include  lib64  mysql-5.7.37-linux-glibc2.12-x86_64  share
[root@localhost src]# cd /usr/local/
[root@localhost local]# ln -sv mysql-5.7.37-linux-glibc2.12-x86_64/ mysql
'mysql' -> 'mysql-5.7.37-linux-glibc2.12-x86_64/'
[root@localhost local]# ll
总用量 0
drwxr-xr-x. 2 root root   6 6月  22 2021 bin
drwxr-xr-x. 2 root root   6 6月  22 2021 etc
drwxr-xr-x. 2 root root   6 6月  22 2021 games
drwxr-xr-x. 2 root root   6 6月  22 2021 include
drwxr-xr-x. 2 root root   6 6月  22 2021 lib
drwxr-xr-x. 3 root root  17 3月   6 20:08 lib64
drwxr-xr-x. 2 root root   6 6月  22 2021 libexec
lrwxrwxrwx. 1 root root  36 7月  29 10:17 mysql -> mysql-5.7.37-linux-glibc2.12-x86_64/
drwxr-xr-x. 9 root root 129 7月  29 10:16 mysql-5.7.37-linux-glibc2.12-x86_64
drwxr-xr-x. 2 root root   6 6月  22 2021 sbin
drwxr-xr-x. 5 root root  49 3月   6 20:08 share
drwxr-xr-x. 2 root root   6 6月  22 2021 src
[root@localhost local]# chown -R  mysql.mysql /usr/local/mysql
[root@localhost local]# chown -R  mysql.mysql /usr/local/mysql-5.7.37-linux-glibc2.12-x86_64/
[root@localhost local]#



配置环境变量



[root@localhost local]# . /etc/profile.d/mysql.sh
[root@localhost local]# echo $PATH
/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@localhost local]#

配置库,头文件,man手册


[root@localhost mysql]# ln -s  /usr/local/mysql/include  /usr/include/mysql
[root@localhost mysql]# vim /etc/man_db.conf
[root@localhost mysql]# echo '/var/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
[root@localhost mysql]#

创建各实例数据存放的目录


[root@localhost mysql]# mkdir -p /opt/data/{3306,3307,3308}
[root@localhost mysql]# chown -R mysql.mysql /opt/data/
[root@localhost mysql]# tree /opt/data/
/opt/data/
├── 3306
├── 3307
└── 3308

3 directories, 0 files
[root@localhost mysql]#

初始化各实例


[root@localhost mysql]# mysqld --initialize --datadir=/opt/data/3306 --user=mysql
2022-07-29T02:32:16.172580Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-07-29T02:32:16.342927Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-07-29T02:32:16.375399Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-07-29T02:32:16.380444Z 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: a949c4c3-0ee6-11ed-98c5-000c295a7a3f.
2022-07-29T02:32:16.381650Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-07-29T02:32:17.215420Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-07-29T02:32:17.215468Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-07-29T02:32:17.215944Z 0 [Warning] CA certificate ca.pem is self signed.
2022-07-29T02:32:17.334379Z 1 [Note] A temporary password is generated for root@localhost: pTQ>mqW#5eYO
[root@localhost ~]# echo pTQ>mqW#5eYO > 3306
[root@localhost ~]# mysqld --initialize --datadir=/opt/data/3307 --user=mysql
2022-07-29T02:32:45.744364Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-07-29T02:32:45.935764Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-07-29T02:32:45.976976Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-07-29T02:32:45.987912Z 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: baef8286-0ee6-11ed-9c7d-000c295a7a3f.
2022-07-29T02:32:45.988515Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-07-29T02:32:46.497957Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-07-29T02:32:46.497981Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-07-29T02:32:46.498380Z 0 [Warning] CA certificate ca.pem is self signed.
2022-07-29T02:32:46.596717Z 1 [Note] A temporary password is generated for root@localhost: ,pho#>l3fXgv
[root@localhost ~]# echo ,pho#>l3fXgv  > 3307
[root@localhost ~]# mysqld --initialize --datadir=/opt/data/3308 --user=mysql
2022-07-29T02:33:07.189023Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-07-29T02:33:07.370105Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-07-29T02:33:07.426352Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-07-29T02:33:07.431012Z 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: c7b7778d-0ee6-11ed-9ef0-000c295a7a3f.
2022-07-29T02:33:07.454831Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-07-29T02:33:07.951485Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-07-29T02:33:07.951511Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-07-29T02:33:07.951876Z 0 [Warning] CA certificate ca.pem is self signed.
2022-07-29T02:33:08.054224Z 1 [Note] A temporary password is generated for root@localhost: #!*yu+Ahk8g4
[root@localhost ~]# echo  #!*yu+Ahk8g4 > 3308

[root@localhost ~]#

安装perl


[root@localhost ~]# yum -y install perl

配置配置文件/etc/my.cnf

[root@localhost ~]# vim /etc/my.cnf
[root@localhost ~]# cat /etc/my.cnf
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin

[mysqld3306]
datadir = /opt/data/3306
port = 3306
socket = /tmp/mysql3306.sock
pid-file = /opt/data/3306/mysql_3306.pid
log-error=/var/log/3306.log

[mysqld3307]
datadir = /opt/data/3307
port = 3307
socket = /tmp/mysql3307.sock
pid-file = /opt/data/3307/mysql_3307.pid
log-error=/var/log/3307.log

[mysqld3308]
datadir = /opt/data/3308
port = 3308
socket = /tmp/mysql3308.sock
pid-file = /opt/data/3308/mysql_3308.pid
log-error=/var/log/3308.log


启动各实例

[root@localhost ~]# mysqld_multi start 3306

[root@localhost ~]# mysqld_multi start 3307

[root@localhost ~]# mysqld_multi start 3308




初始化密码


[root@localhost ~]# mysql -uroot -p'pTQ>mqW#5eYO' -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.37

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> exit
Bye

[root@localhost ~]# mysql -uroot -p',pho#>l3fXgv' -S /tmp/mysql3307.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.37

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> exit
Bye

[root@localhost ~]# mysql -uroot -p'#!*yu+Ahk8g4' -S /tmp/mysql3308.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.37

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> exit
Bye
[root@localhost ~]#

初始化报错如下

[root@localhost ~]# mysql -uroot -p'pTQ>mqW#5eYO' -S /tmp/mysql3306.sock
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory

则执行以下命令即可

yum -y install libncurses.so.5*

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值