Mysql登录时报错 ERROR 1045 (28000): 错误解决办法

本文转载自:http://www.cnblogs.com/zlslch/p/5937784.html

错误问题的描述:

 Mysql登录时报错 ERROR 1045 (28000): 错误解决办法

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

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

windows下,以上两个错误的解决方法

 

解决方法:

  1、找到配置文件my.ini ,然后将其打开,可以选择用NotePadd++打开

Mysql登录时报错 ERROR 1045 (28000): 错误解决办法

 

 

2、打开后,搜索mysqld关键字

找到后,在mysqld下面添加skip-grant-tables,保存退出。

PS:若提示不让保存时,可以将该文件剪切到桌面,更改保存后再复制到mySQL目录下

Mysql登录时报错 ERROR 1045 (28000): 错误解决办法

Mysql登录时报错 ERROR 1045 (28000): 错误解决办法

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[mysqld]
skip-grant-tables

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
basedir = D:\SoftWare\MySQL\mysql-5.7.11-winx64
datadir = D:\SoftWare\MySQL\mysql-5.7.11-winx64\Data
port = 3306
# server_id = .....


# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

 

这样,是用于跳过密码问题,但是呢,这并不能彻底解决!

 

3、重启mysql服务

Mysql登录时报错 ERROR 1045 (28000): 错误解决办法

 

在任何路径目录下,都可以关闭/重启mysql的服务呢。(因为,之前,已经配置全局的环境变量了)

net stop mysql

net start mysql

 

4、进入数据库,重设置密码。

mysql -u root -p Enter

不用管password Enter

Mysql登录时报错 ERROR 1045 (28000): 错误解决办法

 

mysql> use mysql; Enter

mysql> update mysql.user set authtntication_string=password('rootroot') where user='root'; (密码自己设)

Mysql登录时报错 ERROR 1045 (28000): 错误解决办法

 

 

mysql> flush privileges; 刷新数据库

mysql> quit;

Mysql登录时报错 ERROR 1045 (28000): 错误解决办法

 

5、密码重设置成功,改好之后,再修改一下my.ini这个文件,把我们刚才加入的"skip-grant-tables"这行删除,保存退出再重启mysql服务就可以了。

Mysql登录时报错 ERROR 1045 (28000): 错误解决办法

Mysql登录时报错 ERROR 1045 (28000): 错误解决办法

 

 

6、重启mysql服务,并登录mysql用户,用户是root,密码是rootroot。

Mysql登录时报错 ERROR 1045 (28000): 错误解决办法

D:\SoftWare\MySQL\mysql-5.7.11-winx64\bin> net stop mysql

D:\SoftWare\MySQL\mysql-5.7.11-winx64\bin> net start mysql

D:\SoftWare\MySQL\mysql-5.7.11-winx64\bin>mysql -u root -p

Enter password:rootroot