MySQL进阶内容

mysql进阶内容

二进制格式mysql安装

//先去官网下载二进制格式的mysql软件包
[root@localhost ~]# https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz
[root@localhost ~]# ls
anaconda-ks.cfg  mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz

//创建用户和组
[root@localhost ~]# useradd -r -M -s /sbin/nologin mysql
[root@localhost ~]# id mysql
uid=989(mysql) gid=985(mysql) groups=985(mysql)

解压软件到/usr/local/
[root@localhost ~]# tar xf mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@localhost ~]# cd /usr/local/
[root@localhost local]# ls
bin  etc  games  include  lib  lib64  libexec  mysql-5.7.33-linux-glibc2.12-x86_64  sbin  share  src
[root@localhost local]# mv mysql-5.7.33-linux-glibc2.12-x86_64/ mysql/
[root@localhost local]# ls
bin  etc  games  include  lib  lib64  libexec  mysql  sbin  share  src

//修改/usr/local/mysql/的属主和属组
[root@localhost local]# chown -R mysql.mysql /usr/local/mysql
[root@localhost local]# ll /usr/local/mysql -d
drwxr-xr-x. 9 mysql mysql 129 May  4 23:36 /usr/local/mysql

//添加环境变量
[root@localhost ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@localhost ~]# . /etc/profile.d/mysql.sh
[root@localhost ~]# echo $PATH
/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

//建立数据存放目录
[root@localhost ~]# mkdir /opt/data
[root@localhost ~]# chown -R mysql.mysql /opt/data/
[root@localhost ~]# ll /opt/
total 0
drwxr-xr-x. 2 mysql mysql 6 May  4 23:46 data

//初始化数据库
[root@localhost ~]# mysqld --initialize --user=mysql --datadir=/opt/data
2021-05-05T03:51:04.549146Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-05-05T03:51:05.543018Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-05-05T03:51:05.653495Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-05-05T03:51:05.735039Z 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: 1e5080cf-ad55-11eb-82bb-000c2956e00d.
2021-05-05T03:51:05.737275Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-05-05T03:51:06.372303Z 0 [Warning] CA certificate ca.pem is self signed.
2021-05-05T03:51:06.608291Z 1 [Note] A temporary password is generated for root@localhost: ey>!gIN&Q2cY
//记住最后一行的这个临时密码,后面会用到

//生成配置文件
[root@localhost ~]# vim /etc/my.cnf
[mysqld]						//服务端的进程是mysqld
basedir = /usr/local/mysql		//程序的位置
datadir = /opt/data				//数据存放位置
socket = /tmp/mysql.sock		//本地套接字
port = 3306						//默认端口号
pid-file = /opt/data/mysql.pid	//进程文件
user = mysql					//用户
skip-name-resolve				//跳过域名解析

//配置服务启动脚本
[root@localhost ~]# cd /usr/local/mysql/
[root@localhost mysql]# ls
bin  docs  include  lib  LICENSE  man  README  share  support-files
[root@localhost mysql]# cd support-files/
[root@localhost support-files]# ls
magic  mysqld_multi.server  mysql-log-rotate  mysql.server
[root@localhost support-files]# cp mysql.server /etc/init.d/mysqld
[root@localhost support-files]# ll /etc/init.d/mysqld 
-rwxr-xr-x. 1 root root 10576 May  5 00:31 /etc/init.d/mysqld
[root@localhost support-files]# vim /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/opt/data

//启动服务
[root@localhost ~]# service mysqld start
[root@localhost ~]# ss -antl
State              Recv-Q             Send-Q                         Local Address:Port                         Peer Address:Port             Process             
LISTEN             0                  128                                  0.0.0.0:22                                0.0.0.0:*                                    
LISTEN             0                  80                                         *:3306                                    *:*                                    
LISTEN             0                  128                                     [::]:22                                   [::]:*                                   
//设置开机自动启动
[root@localhost ~]# chkconfig mysqld on
 
 //修改密码
 [root@localhost ~]# yum -y install ncurses-compat-libs	//安装一下这个包
 
[root@localhost ~]# mysql -uroot -p'ey>!gIN&Q2cY'
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.33

Copyright (c) 2000, 2021, 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> 
mysql> set password = password('asd123321');
Query OK, 0 rows affected, 1 warning (0.00 sec)

//给头文件做一个软连接
[root@localhost ~]# ln -s /usr/local/mysql/include /usr/include/mysql

//配置系统搜索库文件的路径
[root@localhost ~]# vim /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
[root@localhost ~]# ldconfig		//重新读取配置文件

mysql配置文件

mysql`的配置文件为`/etc/my.cnf

配置文件查找次序:若在多个配置文件中均有设定,则最后找到的最终生效

/etc/my.cnf --> /etc/mysql/my.cnf --> --default-extra-file=/PATH/TO/CONF_FILE --> ~/.my.cnf

mysql常用配置文件参数:

参数 说明
port = 3306 设置监听端口
socket = /tmp/mysql.sock 指定套接字文件位置
basedir = /usr/local/mysql 指定MySQL的安装路径
datadir = /data/mysql 指定MySQL的数据存放路径
pid-file = /data/mysql/mysql.pid 指定进程ID文件存放路径
user = mysql 指定MySQL以什么用户的身份提供服务
skip-name-resolve 禁止MySQL对外部连接进行DNS解析 使用这一选项可以消除MySQL进行DNS解析的时间。 若开启该选项,则所有远程主机连接授权都要使用IP地址方 式否则MySQL将无法正常处理连接请求

mysql数据库备份与恢复

数据库常用备份方案

数据库备份方案:

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

mysql备份工具mysqldump

//语法:
    mysqldump [OPTIONS] database [tables ...]
    mysqldump [OPTIONS] --all-databases [OPTIONS]
    mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
    
//常用的OPTIONS:
    -uUSERNAME      //指定数据库用户名
    -hHOST          //指定服务器主机,请使用ip地址
    -pPASSWORD      //指定数据库用户的密码
    -P#             //指定数据库监听的端口,这里的#需用实际的端口号代替,如-P3307

//备份整个数据库(全备)
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| liuaodan           |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.00 sec)

mysql> use liuaodan;
Database changed
mysql> show tables;
+--------------------+
| Tables_in_liuaodan |
+--------------------+
| aabb               |
| liuaodan           |
| xxbb               |
+--------------------+
3 rows in set (0.00 sec)
[root@localhost ~]# ls
anaconda-ks.cfg
[root@localhost ~]# mysqldump -uroot -p  --all-databases > all-20210505.sql
Enter password: 
[root@localhost ~]# ls
all-20210505.sql  anaconda-ks.cfg

//备份liuaodan库的liuaodan表和xxbb表
[root@localhost ~]# mysqldump -uroot -p liuaodan liuaodan xxbb > table-20210505.sql
Enter password: 
[root@localhost ~]# ls
all-20210505.sql  anaconda-ks.cfg  table-20210505.sql

//备份liuaodan库
[root@localhost ~]# mysqldump -uroot -p --databases liuaodan > lad-20210505.sql
Enter password: 
[root@localhost ~]# ls
all-20210505.sql  anaconda-ks.cfg  lad-20210505.sql  table-20210505.sql

//删除liuaodan数据库
mysql> drop database liuaodan;
Query OK, 3 rows affected (0.00 sec)

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

mysql数据恢复

//恢复liuaodan数据库
[root@localhost ~]# ls
all-20210505.sql  anaconda-ks.cfg  lad-20210505.sql  table-20210505.sql
[root@localhost ~]# mysql -uroot -p < lad-20210505.sql 
Enter password: 
[root@localhost ~]# mysql -uroot -p -e 'show databases;'
Enter password: 
+--------------------+
| Database           |
+--------------------+
| information_schema |
| liuaodan           |
| mysql              |
| performance_schema |
| sys                |
+--------------------+

//恢复kuaile数据库的liuaodan表和xxbb表
mysql> create database kuaile;
Query OK, 1 row affected (0.00 sec)

mysql> use kuaile;
Database changed
mysql> source table-20210505.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)

mysql> show tables;
+------------------+
| Tables_in_kuaile |
+------------------+
| liuaodan         |
| xxbb             |
+------------------+
2 rows in set (0.00 sec)

//模拟删除整个数据库
mysql> show tables;
+------------------+
| Tables_in_kuaile |
+------------------+
| liuaodan         |
| xxbb             |
+------------------+
2 rows in set (0.00 sec)

mysql> drop database liuaodan;
Query OK, 3 rows affected (0.00 sec)

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

//恢复整个数据库
[root@localhost ~]# mysql -uroot -p < all-20210505.sql 
Enter password: 
[root@localhost ~]# mysql -uroot -p -e 'show databases;'
Enter password: 
+--------------------+
| Database           |
+--------------------+
| information_schema |
| kuaile             |
| liuaodan           |
| mysql              |
| performance_schema |
| sys                |
+--------------------+

差异备份与恢复

mysql差异备份

开启MySQL服务器的二进制日志功能

[mysqld]
basedir = /usr/local/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
user = mysql
pid-file = /tmp/mysql.pid
skip-name-resolve

server-id=1         //设置服务器标识符
log-bin=mysql_bin    //开启二进制日志功能

[root@localhost ~]# service mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!

对数据库进行完全备份

//完全备份
[root@localhost ~]# mysqldump -uroot -p --single-transaction --flush-logs --master-data=2 --all-databases --delete-master-logs > all-202105070913.sql
Enter password: 

//增加新内容
mysql> insert student(name,age) values('hehe',20),('xixi',50);
Query OK, 2 rows affected (0.01 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> select * from student;
+----+-------------+------+
| id | name        | age  |
+----+-------------+------+
|  1 | tom         |   20 |
|  2 | jerry       |   23 |
|  3 | wangqing    |   25 |
|  4 | sean        |   28 |
|  5 | zhangshan   |   26 |
|  7 | lisi        |   50 |
|  8 | chenshuo    |   10 |
|  9 | wangwu      |  100 |
| 10 | qiuyi       |   15 |
| 11 | qiuxiaotian |   20 |
| 12 | hehe        |   20 |
| 13 | xixi        |   50 |
+----+-------------+------+
12 rows in set (0.00 sec)

mysql> update student set age = 40 where name = 'xixi';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from student;
+----+-------------+------+
| id | name        | age  |
+----+-------------+------+
|  1 | tom         |   20 |
|  2 | jerry       |   23 |
|  3 | wangqing    |   25 |
|  4 | sean        |   28 |
|  5 | zhangshan   |   26 |
|  7 | lisi        |   50 |
|  8 | chenshuo    |   10 |
|  9 | wangwu      |  100 |
| 10 | qiuyi       |   15 |
| 11 | qiuxiaotian |   20 |
| 12 | hehe        |   20 |
| 13 | xixi        |   40 |
+----+-------------+------+
12 rows in set (0.00 sec)


mysql差异备份恢复
//模拟误删数据
mysql> drop database liuaodan;
Query OK, 1 row affected (0.01 sec)

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

//刷新创建新的二进制日志
[root@localhost ~]# ll /opt/data/
total 122996
-rw-r-----. 1 mysql mysql       56 May  4 23:51 auto.cnf
-rw-------. 1 mysql mysql     1680 May  4 23:51 ca-key.pem
-rw-r--r--. 1 mysql mysql     1112 May  4 23:51 ca.pem
-rw-r--r--. 1 mysql mysql     1112 May  4 23:51 client-cert.pem
-rw-------. 1 mysql mysql     1680 May  4 23:51 client-key.pem
-rw-r-----. 1 mysql mysql      501 May  6 21:11 ib_buffer_pool
-rw-r-----. 1 mysql mysql 12582912 May  6 21:26 ibdata1
-rw-r-----. 1 mysql mysql 50331648 May  6 21:26 ib_logfile0
-rw-r-----. 1 mysql mysql 50331648 May  4 23:51 ib_logfile1
-rw-r-----. 1 mysql mysql 12582912 May  6 21:13 ibtmp1
drwxr-x---. 2 mysql mysql       92 May  5 01:16 kuaile
-rw-r-----. 1 mysql mysql    35330 May  6 21:11 localhost.localdomain.err
drwxr-x---. 2 mysql mysql     4096 May  5 01:19 mysql
-rw-r-----. 1 mysql mysql      898 May  6 21:26 mysql_bin.000002
-rw-r-----. 1 mysql mysql       19 May  6 21:13 mysql_bin.index
-rw-r-----. 1 mysql mysql        5 May  6 21:11 mysql.pid
drwxr-x---. 2 mysql mysql     8192 May  4 23:51 performance_schema
-rw-------. 1 mysql mysql     1680 May  4 23:51 private_key.pem
-rw-r--r--. 1 mysql mysql      452 May  4 23:51 public_key.pem
-rw-r--r--. 1 mysql mysql     1112 May  4 23:51 server-cert.pem
-rw-------. 1 mysql mysql     1680 May  4 23:51 server-key.pem
drwxr-x---. 2 mysql mysql     8192 May  4 23:51 sys
[root@localhost ~]# mysqladmin -uroot -p flush-logs
Enter password: 
[root@localhost ~]# ll /opt/data/
total 123000
-rw-r-----. 1 mysql mysql       56 May  4 23:51 auto.cnf
-rw-------. 1 mysql mysql     1680 May  4 23:51 ca-key.pem
-rw-r--r--. 1 mysql mysql     1112 May  4 23:51 ca.pem
-rw-r--r--. 1 mysql mysql     1112 May  4 23:51 client-cert.pem
-rw-------. 1 mysql mysql     1680 May  4 23:51 client-key.pem
-rw-r-----. 1 mysql mysql      501 May  6 21:11 ib_buffer_pool
-rw-r-----. 1 mysql mysql 12582912 May  6 21:26 ibdata1
-rw-r-----. 1 mysql mysql 50331648 May  6 21:26 ib_logfile0
-rw-r-----. 1 mysql mysql 50331648 May  4 23:51 ib_logfile1
-rw-r-----. 1 mysql mysql 12582912 May  6 21:13 ibtmp1
drwxr-x---. 2 mysql mysql       92 May  5 01:16 kuaile
-rw-r-----. 1 mysql mysql    35330 May  6 21:11 localhost.localdomain.err
drwxr-x---. 2 mysql mysql     4096 May  5 01:19 mysql
-rw-r-----. 1 mysql mysql      945 May  6 21:27 mysql_bin.000002
-rw-r-----. 1 mysql mysql      154 May  6 21:27 mysql_bin.000003
-rw-r-----. 1 mysql mysql       38 May  6 21:27 mysql_bin.index
-rw-r-----. 1 mysql mysql        5 May  6 21:11 mysql.pid
drwxr-x---. 2 mysql mysql     8192 May  4 23:51 performance_schema
-rw-------. 1 mysql mysql     1680 May  4 23:51 private_key.pem
-rw-r--r--. 1 mysql mysql      452 May  4 23:51 public_key.pem
-rw-r--r--. 1 mysql mysql     1112 May  4 23:51 server-cert.pem
-rw-------. 1 mysql mysql     1680 May  4 23:51 server-key.pem
drwxr-x---. 2 mysql mysql     8192 May  4 23:51 sys


//恢复完全备份
[root@localhost ~]# mysql -uroot -p < all-202105070913.sql
Enter password: 
[root@localhost ~]# mysql -uroot -p -e 'show databases;'
Enter password: 
+--------------------+
| Database           |
+--------------------+
| information_schema |
| kuaile             |
| liuaodan           |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
[root@localhost ~]# mysql -uroot -p -e 'select * from liuaodan.student;'
Enter password: 
+----+-------------+------+
| id | name        | age  |
+----+-------------+------+
|  1 | tom         |   20 |
|  2 | jerry       |   23 |
|  3 | wangqing    |   25 |
|  4 | sean        |   28 |
|  5 | zhangshan   |   26 |
|  7 | lisi        |   50 |
|  8 | chenshuo    |   10 |
|  9 | wangwu      |  100 |
| 10 | qiuyi       |   15 |
| 11 | qiuxiaotian |   20 |
+----+-------------+------+

//恢复差异备份
[root@localhost ~]# mysql -uroot -p
Enter password: 
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.33-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 |         295 | BEGIN                                 |
| mysql_bin.000002 | 295 | Table_map      |         1 |         353 | table_id: 142 (liuaodan.student)      |
| mysql_bin.000002 | 353 | Write_rows     |         1 |         410 | table_id: 142 flags: STMT_END_F       |
| mysql_bin.000002 | 410 | Xid            |         1 |         441 | COMMIT /* xid=502 */                  |
| mysql_bin.000002 | 441 | Anonymous_Gtid |         1 |         506 | SET @@SESSION.GTID_NEXT= 'ANONYMOUS'  |
| mysql_bin.000002 | 506 | Query          |         1 |         582 | BEGIN                                 |
| mysql_bin.000002 | 582 | Table_map      |         1 |         640 | table_id: 142 (liuaodan.student)      |
| mysql_bin.000002 | 640 | Update_rows    |         1 |         698 | table_id: 142 flags: STMT_END_F       |
| mysql_bin.000002 | 698 | Xid            |         1 |         729 | COMMIT /* xid=505 */                  |
| mysql_bin.000002 | 729 | Anonymous_Gtid |         1 |         794 | SET @@SESSION.GTID_NEXT= 'ANONYMOUS'  |
| mysql_bin.000002 | 794 | Query          |         1 |         898 | drop database liuaodan                |
| mysql_bin.000002 | 898 | Rotate         |         1 |         945 | mysql_bin.000003;pos=4                |
+------------------+-----+----------------+-----------+-------------+---------------------------------------+
15 rows in set (0.00 sec)

//这里pos是执行这条命令以前,End_log_pos是之后。
//使用mysqlbinlog恢复差异备份
[root@localhost ~]# mysqlbinlog --stop-position=794 /opt/data/mysql_bin.000002 | mysql -uroot -p
Enter password: 
[root@localhost ~]# mysql -uroot -p -e 'select * from liuaodan.student;'
Enter password: 
+----+-------------+------+
| id | name        | age  |
+----+-------------+------+
|  1 | tom         |   20 |
|  2 | jerry       |   23 |
|  3 | wangqing    |   25 |
|  4 | sean        |   28 |
|  5 | zhangshan   |   26 |
|  7 | lisi        |   50 |
|  8 | chenshuo    |   10 |
|  9 | wangwu      |  100 |
| 10 | qiuyi       |   15 |
| 11 | qiuxiaotian |   20 |
| 12 | hehe        |   20 |
| 13 | xixi        |   40 |
+----+-------------+------+

密码破解

//绕过授权
[root@localhost ~]# vi /etc/my.cnf
skip-grant-tables
[root@localhost ~]# systemctl restart mysql
//不用账号密码登陆进去
[root@localhost ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.33-log MySQL Community Server (GPL)

Copyright (c) 2000, 2021, 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>

//查看存放密码信息的表
mysql> select * from mysql.user\G
*************************** 1. row ***************************
                  Host: localhost
                  User: root
           Select_priv: Y
           Insert_priv: Y
           Update_priv: Y
           Delete_priv: Y
           Create_priv: Y
             Drop_priv: Y
           Reload_priv: Y
         Shutdown_priv: Y
          Process_priv: Y
             File_priv: Y
            Grant_priv: Y
       References_priv: Y
            Index_priv: Y
            Alter_priv: Y
          Show_db_priv: Y
            Super_priv: Y
 Create_tmp_table_priv: Y
      Lock_tables_priv: Y
          Execute_priv: Y
       Repl_slave_priv: Y
      Repl_client_priv: Y
      Create_view_priv: Y
        Show_view_priv: Y
   Create_routine_priv: Y
    Alter_routine_priv: Y
      Create_user_priv: Y
            Event_priv: Y
          Trigger_priv: Y
Create_tablespace_priv: Y
              ssl_type: 
            ssl_cipher: 
           x509_issuer: 
          x509_subject: 
         max_questions: 0
           max_updates: 0
       max_connections: 0
  max_user_connections: 0
                plugin: mysql_native_password
 authentication_string: *FC4C71C368D56E1FA435BD77C9388ACF52F06FFB
      password_expired: N
 password_last_changed: 2021-05-05 00:47:04
     password_lifetime: NULL
        account_locked: N
*************************** 2. row ***************************
                  Host: localhost
                  User: mysql.session
           Select_priv: N
           Insert_priv: N
           Update_priv: N
           Delete_priv: N
           Create_priv: N
             Drop_priv: N
           Reload_priv: N
         Shutdown_priv: N
          Process_priv: N
             File_priv: N
            Grant_priv: N
       References_priv: N
            Index_priv: N
            Alter_priv: N
          Show_db_priv: N
            Super_priv: Y
 Create_tmp_table_priv: N
      Lock_tables_priv: N
          Execute_priv: N
       Repl_slave_priv: N
      Repl_client_priv: N
      Create_view_priv: N
        Show_view_priv: N
   Create_routine_priv: N
    Alter_routine_priv: N
      Create_user_priv: N
            Event_priv: N
          Trigger_priv: N
Create_tablespace_priv: N
              ssl_type: 
            ssl_cipher: 
           x509_issuer: 
          x509_subject: 
         max_questions: 0
           max_updates: 0
       max_connections: 0
  max_user_connections: 0
                plugin: mysql_native_password
 authentication_string: *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE
      password_expired: N
 password_last_changed: 2021-05-04 23:51:07
     password_lifetime: NULL
        account_locked: Y
*************************** 3. row ***************************
                  Host: localhost
                  User: mysql.sys
           Select_priv: N
           Insert_priv: N
           Update_priv: N
           Delete_priv: N
           Create_priv: N
             Drop_priv: N
           Reload_priv: N
         Shutdown_priv: N
          Process_priv: N
             File_priv: N
            Grant_priv: N
       References_priv: N
            Index_priv: N
            Alter_priv: N
          Show_db_priv: N
            Super_priv: N
 Create_tmp_table_priv: N
      Lock_tables_priv: N
          Execute_priv: N
       Repl_slave_priv: N
      Repl_client_priv: N
      Create_view_priv: N
        Show_view_priv: N
   Create_routine_priv: N
    Alter_routine_priv: N
      Create_user_priv: N
            Event_priv: N
          Trigger_priv: N
Create_tablespace_priv: N
              ssl_type: 
            ssl_cipher: 
           x509_issuer: 
          x509_subject: 
         max_questions: 0
           max_updates: 0
       max_connections: 0
  max_user_connections: 0
                plugin: mysql_native_password
 authentication_string: *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE
      password_expired: N
 password_last_changed: 2021-05-04 23:51:07
     password_lifetime: NULL
        account_locked: Y
3 rows in set (0.00 sec)

//更改表格里的密码
mysql> update mysql.user set authentication_string = password('liuaodan123') where Host = 'localhost' and User = 'root';

//删除my.cnf里绕过权限的语句
//用新密码进数据库
[root@localhost ~]# mysql -uroot -pliuaodan123
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 3
Server version: 5.7.33-log MySQL Community Server (GPL)

Copyright (c) 2000, 2021, 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> 

你可能感兴趣的:(服务管理,数据库,linux,mysql,centos)