MYSQL 错误 1045 拒绝访问
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13480170/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Access Denied for MYSQL ERROR 1045
提问by jmitchel3
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.
我刚买了一个新的 macbook pro (OS X 10.8.2),我正在尝试在它上面设置 mysql。到目前为止,我已经能够安装它,但我无法获得我的 root 用户访问权限(或任何与此相关的用户)。我打算使用它Python
,在我的另一台计算机上我只使用 MYSQL(没有 MAMP),我更喜欢保持这种方式。
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
$ 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:
当我进入mysql
或mysql -u root -p
它给我这个:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
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
ERROR 1045 (28000): Access denied for user 'jmitch'@'localhost' (using password: NO)
取决于我使用的措辞
MYSQL is running in my system preferences. Thank you for your help.
MYSQL 正在我的系统首选项中运行。感谢您的帮助。
回答by Drew
Maybe updating the package the updater overwrote the root password.
也许更新包更新程序覆盖了 root 密码。
To restore it:
要恢复它:
Stop mysqld deamons.
停止 mysqld 守护进程。
$ sudo service mysqld stop
Go to mysql/bin directory
进入mysql/bin目录
$ cd /usr/bin
Start a mysql deamon with this option:
使用此选项启动 mysql 守护进程:
$ sudo mysqld_safe --skip-grant-tables
Open another terminal and open a mysql session to execute this:
打开另一个终端并打开一个 mysql 会话来执行这个:
$ 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:
现在杀死mysqld_safe进程并正常重启mysqld:
$ 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.
注 1:password
是mysql.user
5.7 版本之前的表中的列名。之后就变成了authentication_string
。相应地更改您的更新语句。
回答by remkohdev
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.
在 Mac OSX 10.9 Mavericks 上,我使用了 support-files 目录中的“mysql.server”脚本,而不是 mysqld_safe 和服务脚本。
$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
回答by Ivan Chaer
I was having a similar issue trying to access MAMP's MySQL through the terminal on Mountain Lion.
我在尝试通过 Mountain Lion 上的终端访问 MAMP 的 MySQL 时遇到了类似的问题。
The --no-defaults flag solved it for me.
--no-defaults 标志为我解决了这个问题。
/Applications/MAMP/Library/bin/mysql --no-defaults -u root -proot -h localhost
回答by user1283068
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).
我想为 MySQL 5.7 添加它,简单地更改 authentication_string 列不起作用。这是因为 MySQL 从不实际使用这些值进行 root 身份验证,它使用插件。据我所知,此插件会验证您是否也是主机帐户上的 root(因此您必须 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.
还应该注意的是,5.7 的官方 MySQL 文档从未提及这一点。严格按照本文档进行操作会让您一无所获。