31 rows in set (0.00 sec)

mysql> select * from user\G

*************************** 1. row ***************************

Host: localhost

User: root

Select_priv: Y ## yes 代表有权限

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
《一线大厂Java面试题解析+后端开发学习笔记+最新架构讲解视频+实战项目源码讲义》无偿开源 威信搜索公众号【编程进阶路】
authentication_string: *E6CC90B878B948C35(##这里里就是加密过的密码)E92B003C792C46C58C4AF40

password_expired: N

password_last_changed: 2021-08-25 01:14:23

password_lifetime: NULL

account_locked: N

[](()步骤

=================================================================

[](()1. 绕过密码验证


修改mysql配置文件

[root@localhost ~]# cat /etc/my.cnf

[mysqld]

datadir=/opt/data

socket=/tmp/mysql.sock

basedir=/usr/local/mysql

port=3306

character-set-server=utf8

log-error=/var/log/mysqld.log

pid-file=/opt/data/mysql.pid

server-id=1

log-bin=mysql_bin

skip-grant-tables ## 跳过授权表

[](()2. 重启服务


重启服务能直接进入能正常创建表,库等操作,但无法直接设置密码

[root@localhost ~]# systemctl restart mysqld

[root@localhost ~]# mysql

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.7.34-log MySQL Community Server (GPL)

Copyright © 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> set password = password(‘123’); ## 无法设置密码

ERROR 1290 (HY000): The MySQL server is running with the –skip-grant-tables option so it cannot execute this statement

[](()3. 修改密码


mysql> use mysql

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> update user set authentication_string = ‘123’ where user = ‘root’ and host = ‘localhost’;

Query OK, 1 row affected (0.01 sec)

Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from 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: 123 ##密码以明文显示不安全

password_expired: N

password_last_changed: 2021-08-25 01:14:23

password_lifetime: NULL

account_locked: N

重新设置

mysql> update user set authentication_string = password(‘123’) where user = ‘root’ and host = ‘localhost’ ##用password参数加密

Query OK, 1 row affected, 1 warning (0.00 sec)

Rows matched: 1 Changed: 1 Warnings: 1

mysql> select * from user\G

*************************** 1. row ***************************

Host: localhost

User: root

Select_priv: Y

Insert_priv: Y