ERROR 1045 (28000): Access denied 解决方案

安装完版本mysql-5.7.20-winx64  在安装完毕,运行时报如下错误:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) 或则

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


我的解决方案是:

1、在my.ini文件中添加:

   skip-grant-tables   添加这句话可以免密登录

 [mysql]
   # 设置mysql客户端默认字符集
   default-character-set=utf8 
  [mysqld]
  #设置3306端口
         skip-grant-tables
         port = 3306 
 # 设置mysql的安装目录
         basedir=E:\\mysql-5.7.20-winx64
   # 设置mysql数据库的数据的存放目录
         datadir=E:\\mysql-5.7.20-winx64\\data
  # 允许最大连接数
         max_connections=200
 # 服务端使用的字符集默认为UTF8
         character-set-server=utf8
   # 创建新表时将使用的默认存储引擎
   default-storage-engine=INNODB

2、添加完毕记得mysql处于关闭状态:net stop mysql


3、然后删除data目录下的文件

4、然后执行命令:

mysqld --initialize

5、再次启动mysql    

   net start mysql

6、然后登录系统

   mysql -h127.0.0.1  -u root -p   直接enter进入系统。

7、登录后自己设置密码

set password =password('你的密码');  //设置密码
flush privileges; //刷新权限

高版本替换为update mysql.user set authentication_string=password('root') where user='root' ;即可

8、其他权限(如果需要用)

mysql> grant all on *.* to 'root'@'localhost' IDENTIFIED BY '你的密码'with grant option ;
mysql> flush privileges;
3.进入mysql库修改user表
mysql> use mysql;
mysql> update user set password=password('你的密码') where user='root'; 
mysql> flush privileges;
mysql> grant all on *.* to 'root'@'192.168.0.163' IDENTIFIED BY 'root' with grant option ;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql>
mysql>
mysql>  alter user 'root'@'localhost' identified by 'root';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> grant all on *.* to 'root'@'localhost' IDENTIFIED BY 'root' with grant option ;
Query OK, 0 rows affected, 1 warning (0.00 sec)


mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)


mysql> grant all on *.* to 'root'@'192.168.0.163' IDENTIFIED BY 'root' with grant option ;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)


GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION; 
alter user 'root'@'%' identified by 'root';  

查看是否存在锁表情况:

 show OPEN TABLES where In_use > 0


查询进程:

show processlist


猜你喜欢

转载自blog.csdn.net/zhangkang65/article/details/79497368