错误报警Access denied for user ‘root’@‘localhost’ (using password: YES)
出现原因
数据库用户权限过期
解决办法
- 修改数据库安装目录下
my.ini
- 在命令行中输入
net stop mysql
- 关闭
mysql
服务 - 在
my.ini
文件中加入skip-grant-tables
- 在命令行中输入
[client]
port=3306
default-character-set=utf8
[mysqld]
skip-grant-tables
port=3306
character_set_server=utf8
#安装路径
basedir=D:\\soft\mysql
#数据路径
datadir=D:\\soft\mysql\data
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[WinMySQLAdmin]
D:\\soft\mysql\bin\mysqld.exe
- 打开命令行,输入
mysql
- 连接
mysql
- 刷新掉权限
- 更新数据库权限
- 连接
具体命令看如下代码
C:\Users\Administrator>mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 5.6.50 MySQL Community Server (GPL)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
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> FLUSH PRIVILEGES;
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
mysql> quit;
- 删除配置文件
my.ini
中的skip-grant-tables
- 重新启动数据库服务,在命令行中输入
net start mysql
C:\Users\Administrator>net start mysql
MySQL 服务正在启动 .
MySQL 服务已经启动成功。
C:\Users\Administrator>
- 连接
mySQL
,输入用户名,密码即可连接
C:\Users\Administrator>mysql -uroot -p
Enter password: ****
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.50 MySQL Community Server (GPL)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
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>