MYSQL 错误 1045 拒绝访问

我刚买了一个新的 macbook pro (OS X 10.8.2),我正在尝试在它上面设置 mysql.到目前为止,我已经能够安装它,但我无法获得我的 root 用户访问权限(或任何与此相关的用户).我计划将它用于 Python,在我的另一台计算机上我只使用 MYSQL(没有 MAMP),我更喜欢保持这种方式.

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$别名mysqladmin=/usr/local/mysql/bin/mysqladmin

当我输入 mysqlmysql -u root -p 它给我这个:

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

ERROR 1045 (28000): Access denied for user 'root'@'localhost'(使用密码:YES)

ERROR 1045 (28000): Access denied for user 'jmitch'@'localhost' (using password: NO)取决于我使用的措辞

MYSQL 正在我的系统首选项中运行.感谢您的帮助.

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

推荐答案

可能是更新包更新程序覆盖了 root 密码.

Maybe updating the package the updater overwrote the root password.

要恢复它:

停止 mysqld 守护进程.

Stop mysqld deamons.

$ sudo service mysqld stop

进入mysql/bin目录

Go to mysql/bin directory

$ cd /usr/bin

用这个选项启动一个 mysql 守护进程:

Start a mysql deamon with this option:

$ sudo mysqld_safe --skip-grant-tables

打开另一个终端并打开一个mysql会话来执行这个:

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;

现在杀死mysqld_safe进程并正常重启mysqld:

Now kill the mysqld_safe process and restart mysqld normally:

$ sudo service mysqld start

注1: password是5.7版本之前mysql.user表中的列名.之后它变成了authentication_string.相应地更改您的更新声明.

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.

相关文章