是的,另一个MySql: ERROR 1045(28000):用户“root”@“localhost”访问被拒绝(使用密码:Yes)

时间:2021-08-08 20:33:48

So I'm not sure what caused this to scramble my MySql password (upgrade to Mountain Lion, reinstalling ruby/rails (other issues), or simply just bad luck) but here we are:

因此,我不确定是什么原因导致我的MySql密码(升级到Mountain Lion,重新安装ruby/rails(其他问题),或者只是运气不佳)出现混乱。

Logging in to mysql is fine, but I can't log into the root

登录到mysql很好,但是我不能登录到根目录。

Ayman$ mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 96
Server version: 5.5.25 MySQL Community Server (GPL)

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

When I try to login to root:

当我试图登录到root:

Ayman$ mysql -u root -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

Looked at the users:

看了看用户:

mysql> CREATE USER root@localhost IDENTIFIED BY 'out22out';
ERROR 1227 (42000): Access denied; you need (at least one of) the CREATE USER privilege(s)     for this operation
mysql> SELECT USER(),CURRENT_USER();
+-----------------+----------------+
| USER()          | CURRENT_USER() |
+-----------------+----------------+
| Ayman@localhost | @localhost     |
+-----------------+----------------+
1 row in set (0.00 sec)

mysql> SELECT USER, HOST FROM mysql.user;
ERROR 1142 (42000): SELECT command denied to user ''@'localhost' for table 'user'
mysql> select user, host from mysql.user;
ERROR 1142 (42000): SELECT command denied to user ''@'localhost' for table 'user'
mysql> grant all on *.* to Ayman@'%';
ERROR 1045 (28000): Access denied for user ''@'localhost' (using password: NO)
mysql> 

I've tried reinstalling MySql (not sure how to uninstall it), stopping the server instance and restarting it, and every other suggestion on the myriad of similar questions to the right. I've been on this for 3 days now and it's killing me.

我尝试过重新安装MySql(不知道如何卸载它)、停止服务器实例并重新启动它,以及对右侧大量类似问题的所有其他建议。我已经用了3天了,简直要了我的命。

Any clue?

有线索吗?

2 个解决方案

#1


5  

You can start MySQL (the server, not the command line monitor) with --skip-grant-tables, which shuts off the permissions systems temporarily. That'll let you get in, update your accounts/passwords without those screwed up permissions getting in the way. Once things are fixed, you do a flush privileges; to re-enable the permissions system.

您可以使用—skip-grant-tables启动MySQL(服务器,而不是命令行监视器),它临时关闭权限系统。这样你就可以进入,更新你的帐户/密码,而不需要那些搅乱你的权限。一旦事情得到了解决,你就拥有了齐平的特权;重新启用权限系统。

#2


1  

Ok I figured it out using the tutorial on this website:

我是通过这个网站上的教程算出来的

I had no clue how to run skip grant tables as evidenced below:

我不知道如何运作跳跳补助金表格,如下所示:

Last login: Wed Aug 22 23:10:42 on console
Ayman$ --skip-grant-tables
-bash: --skip-grant-tables: command not found
Ayman$ mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock'    (2)
Ayman$ --skip-grant-tables
-bash: --skip-grant-tables: command not found

Here is where I googled Skip Grant Tables and found the tutorial listed above:

在这里,我搜索了Skip Grant表,找到了上面列出的教程:

Don't think any of the initial part of the tutorial worked:

不要认为本教程的最初部分有用:

Ayman$ # vi /etc/rc.d/init.d/mysql
Ayman$ $bindir/mysqld_safe --datadir=$datadir --pid-file=$server_pid_file $other_args     >/dev/null 2>&1 &
[1] 302
Ayman$ $bindir/mysqld_safe --skip-grant-tables --datadir=$datadir --pid-  file=$server_pid_file $other_args >/dev/null 2>&1 &
[2] 303
[1]   Exit 127                $bindir/mysqld_safe --datadir=$datadir --pid-   file=$server_pid_file $other_args > /dev/null 2>&1
Ayman$ mysql start
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock'   (2)
[2]+  Exit 127                $bindir/mysqld_safe --skip-grant-tables --datadir=$datadir -  -pid-file=$server_pid_file $other_args > /dev/null 2>&1
Ayman$ # service mysql start
Ayman$ mysql -u root mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
Ayman$ mysql

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

错误2002 (HY000):无法通过socket '/tmp/ MySQL连接到本地MySQL服务器。袜子”(2)

HERE IS THE MAGIC!:

这是神奇的!

Ayman$ mysql -u root mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.5.27 MySQL Community Server (GPL)

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> UPDATE user SET password=PASSWORD('newpassword') WHERE user='root';
Query OK, 4 rows affected (0.11 sec)
Rows matched: 4  Changed: 4  Warnings: 0

mysql> flush privileges
-> ;
Query OK, 0 rows affected (0.00 sec)

More stuff from the link above that didn't work:

以上链接中更多没用的东西:

mysql> service mysql stop
-> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that   corresponds to your MySQL server version for the right syntax to use near 'service mysql stop'    at line 1
mysql> # service mysql stop
mysql> # vi /etc/rc.d/init.d/mysql
mysql> $bindir/mysqld_safe --datadir=$datadir --pid-file=$server_pid_file $other_args   >/dev/null 2>&1 &
    -> 
    -> ;
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock'   (2)
ERROR: 
Can't connect to the server

mysql> $bindir/mysqld_safe --skip-grant-tables --datadir=$datadir --pid-  file=$server_pid_file $other_args >/dev/null 2>&1 &;
No connection. Trying to reconnect...
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock'   (2)
ERROR: 
Can't connect to the server

mysql> $bindir/mysqld_safe --skip-grant-tables --datadir=$datadir --pid-  file=$server_pid_file $other_args >/dev/null 2>&1 &;
No connection. Trying to reconnect...
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
ERROR: 
Can't connect to the server

mysql> $bindir/mysqld_safe --datadir=$datadir --pid-file=$server_pid_file $other_args   >/dev/null 2>&1 &;
No connection. Trying to reconnect...
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
ERROR: 
Can't connect to the server

IT's ALIVE!!!!:

它还活着! ! ! !

mysql> quit
Bye
Ayman$ mysql -u root -p
Enter password: newpassword 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 25
Server version: 5.5.27 MySQL Community Server (GPL)

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

Thank you to MARC B and the * community for pointing me in the right direction and getting this novice back in the game!!

感谢MARC B和*社区为我指明了正确的方向,让这个新手回到游戏中来!

#1


5  

You can start MySQL (the server, not the command line monitor) with --skip-grant-tables, which shuts off the permissions systems temporarily. That'll let you get in, update your accounts/passwords without those screwed up permissions getting in the way. Once things are fixed, you do a flush privileges; to re-enable the permissions system.

您可以使用—skip-grant-tables启动MySQL(服务器,而不是命令行监视器),它临时关闭权限系统。这样你就可以进入,更新你的帐户/密码,而不需要那些搅乱你的权限。一旦事情得到了解决,你就拥有了齐平的特权;重新启用权限系统。

#2


1  

Ok I figured it out using the tutorial on this website:

我是通过这个网站上的教程算出来的

I had no clue how to run skip grant tables as evidenced below:

我不知道如何运作跳跳补助金表格,如下所示:

Last login: Wed Aug 22 23:10:42 on console
Ayman$ --skip-grant-tables
-bash: --skip-grant-tables: command not found
Ayman$ mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock'    (2)
Ayman$ --skip-grant-tables
-bash: --skip-grant-tables: command not found

Here is where I googled Skip Grant Tables and found the tutorial listed above:

在这里,我搜索了Skip Grant表,找到了上面列出的教程:

Don't think any of the initial part of the tutorial worked:

不要认为本教程的最初部分有用:

Ayman$ # vi /etc/rc.d/init.d/mysql
Ayman$ $bindir/mysqld_safe --datadir=$datadir --pid-file=$server_pid_file $other_args     >/dev/null 2>&1 &
[1] 302
Ayman$ $bindir/mysqld_safe --skip-grant-tables --datadir=$datadir --pid-  file=$server_pid_file $other_args >/dev/null 2>&1 &
[2] 303
[1]   Exit 127                $bindir/mysqld_safe --datadir=$datadir --pid-   file=$server_pid_file $other_args > /dev/null 2>&1
Ayman$ mysql start
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock'   (2)
[2]+  Exit 127                $bindir/mysqld_safe --skip-grant-tables --datadir=$datadir -  -pid-file=$server_pid_file $other_args > /dev/null 2>&1
Ayman$ # service mysql start
Ayman$ mysql -u root mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
Ayman$ mysql

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

错误2002 (HY000):无法通过socket '/tmp/ MySQL连接到本地MySQL服务器。袜子”(2)

HERE IS THE MAGIC!:

这是神奇的!

Ayman$ mysql -u root mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.5.27 MySQL Community Server (GPL)

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> UPDATE user SET password=PASSWORD('newpassword') WHERE user='root';
Query OK, 4 rows affected (0.11 sec)
Rows matched: 4  Changed: 4  Warnings: 0

mysql> flush privileges
-> ;
Query OK, 0 rows affected (0.00 sec)

More stuff from the link above that didn't work:

以上链接中更多没用的东西:

mysql> service mysql stop
-> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that   corresponds to your MySQL server version for the right syntax to use near 'service mysql stop'    at line 1
mysql> # service mysql stop
mysql> # vi /etc/rc.d/init.d/mysql
mysql> $bindir/mysqld_safe --datadir=$datadir --pid-file=$server_pid_file $other_args   >/dev/null 2>&1 &
    -> 
    -> ;
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock'   (2)
ERROR: 
Can't connect to the server

mysql> $bindir/mysqld_safe --skip-grant-tables --datadir=$datadir --pid-  file=$server_pid_file $other_args >/dev/null 2>&1 &;
No connection. Trying to reconnect...
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock'   (2)
ERROR: 
Can't connect to the server

mysql> $bindir/mysqld_safe --skip-grant-tables --datadir=$datadir --pid-  file=$server_pid_file $other_args >/dev/null 2>&1 &;
No connection. Trying to reconnect...
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
ERROR: 
Can't connect to the server

mysql> $bindir/mysqld_safe --datadir=$datadir --pid-file=$server_pid_file $other_args   >/dev/null 2>&1 &;
No connection. Trying to reconnect...
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
ERROR: 
Can't connect to the server

IT's ALIVE!!!!:

它还活着! ! ! !

mysql> quit
Bye
Ayman$ mysql -u root -p
Enter password: newpassword 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 25
Server version: 5.5.27 MySQL Community Server (GPL)

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

Thank you to MARC B and the * community for pointing me in the right direction and getting this novice back in the game!!

感谢MARC B和*社区为我指明了正确的方向,让这个新手回到游戏中来!