如何在MySQL8中重置root密码

database

ERROR 1045 (28000): Access denied for user "root"@"localhost" (using password: YES)

一般这个错误是由密码错误引起,解决的办法自然就是重置密码

解决方案如下:

1.停止mysql数据库:

systemctl stop mysqld

2.用以下命令启动MySQL,以不检查权限的方式启动:

mysqld --skip-grant-tables &

此时又报了一个错误:

2020-01-30T12:56:04.313195Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.19) starting as process 14214                                       [20:56:04]
2020-01-30T12:56:04.314429Z 0 [ERROR] [MY-010123] [Server] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!
2020-01-30T12:56:04.314465Z 0 [ERROR] [MY-010119] [Server] Aborting
2020-01-30T12:56:04.314565Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.19)  MySQL Community Server - GPL.

执行命令:

mysqld --user=root --skip-grant-tables &

2020-01-30T12:57:00.762096Z 0 [Warning] [MY-010091] [Server] Can"t create test file /var/lib/mysql/mysqld_tmp_file_case_insensitive_test.lower-test          [20:57:00]
2020-01-30T12:57:00.762156Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.19) starting as process 14230
2020-01-30T12:57:00.764479Z 0 [Warning] [MY-010091] [Server] Can"t create test file /var/lib/mysql/mysqld_tmp_file_case_insensitive_test.lower-test
2020-01-30T12:57:00.764489Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /var/lib/mysql/ is case insensitive
2020-01-30T12:57:00.764672Z 0 [Warning] [MY-010122] [Server] One can only use the --user switch if running as root

权限不够 +  
2020-01-30T12:57:00.764685Z 0 [ERROR] [MY-013276] [Server] Failed to set datadir to "/var/lib/mysql/" (OS errno: 13 - Permission denied)
2020-01-30T12:57:00.764764Z 0 [ERROR] [MY-010119] [Server] Aborting
2020-01-30T12:57:00.764861Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.19)  MySQL Community Server - GPL.

[1]  + 14230 exit 1     mysqld --user=root --skip-grant-tables
 

3.登录mysql:mysql -uroot或mysql

4.更新root密码

mysql5.7以下版本:UPDATE mysql.user SET Password=PASSWORD("123456") where USER="root";

mysql8.0版本:UPDATE mysql.user SET authentication_string="123456" WHERE user="root";

5.刷新权限:

flush privileges;

6.退出mysql:exit或quit

7.使用root用户重新登录mysql

mysql -uroot -p

Enter password:<输入新设的密码123456>

以上是 如何在MySQL8中重置root密码 的全部内容, 来源链接: utcz.com/z/532114.html

回到顶部