Access Denied for MYSQL ERROR 1045

可紊 提交于 2019-12-28 06:23:24

问题


I just got a new macbook pro (OS X 10.8.2) and am attempting to get mysql set up on it. So far I've been able to get it installed but I cannot get my root user access (or any user for that matter). I plan on using this for Python, on my other computer I only use MYSQL (no MAMP) and I prefer to keep it that way.

For reference, I did the following:

$ alias mysql=/usr/local/mysql/bin/mysql $ sudo /Library/StartupItems/MySQLCOM/MySQLCOM start $ alias mysqladmin=/usr/local/mysql/bin/mysqladmin

When i enter mysql or mysql -u root -p it gives me this:

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

or

ERROR 1045 (28000): Access denied for user 'jmitch'@'localhost' (using password: NO) Depending on which phrasing I use

MYSQL is running in my system preferences. Thank you for your help.


回答1:


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.




回答2:


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



回答3:


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



回答4:


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.



来源:https://stackoverflow.com/questions/13480170/access-denied-for-mysql-error-1045

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