Access Denied for MYSQL ERROR 1045

雨燕双飞 提交于 2019-11-27 23:06:10

Maybe updating the package the updater overwrote the root password.

To restore it:

Stop mysqld deamons.

$ sudo service mysqld stop

Go to mysql/bin directory

$ cd /usr/bin

Start a mysql deamon with this option:

$ sudo mysqld_safe --skip-grant-tables

Open another terminal and open a mysql session to execute this:

$ mysql

mysql> use mysql;

see Note1 below for next line.
mysql> UPDATE user SET password=PASSWORD('YOUR_NEW_PASSWORD_HERE') WHERE user = 'root';

mysql> exit;

Now kill the mysqld_safe process and restart mysqld normally:

$ sudo service mysqld start

Note1: password is the column name in table mysql.user prior to version 5.7. After which it became authentication_string. Change your update statement accordingly.

on Mac OSX 10.9 Mavericks I used the 'mysql.server' script in the support-files directory instead of the mysqld_safe and service script.

$sudo ./mysql.server stop
$sudo ./mysql.server start --skip-grant-tables
$ mysql
mysql> use mysql;
mysql> UPDATE user SET password=PASSWORD('YOUR_NEW_PASSWORD_HERE') WHERE user = 'root';
mysql> exit;
$sudo ./mysql.server stop
$sudo ./mysql.server start

I was having a similar issue trying to access MAMP's MySQL through the terminal on Mountain Lion.

The --no-defaults flag solved it for me.

/Applications/MAMP/Library/bin/mysql --no-defaults -u root -proot -h localhost

I want to add that for MySQL 5.7 simply changing the authentication_string column doesn't work. This is because MySQL never actually uses those values for root authentication, it uses a plugin. As far as I can tell this plugin verifies that you are also root on the host account (so you have to sudo mysql -u root).

The only way I was able to get this to work was to run this:

UPDATE mysql.user
SET authentication_string=PASSWORD(''), plugin=''
WHERE mysql.user = 'root';

It should also be noted that the official MySQL documentation for 5.7 never mentions this. Following this documentation to the letter gets you nowhere at all.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!