gpt4 book ai didi

mysql - "mysql -u root"在 Ubuntu 上从 5.6 升级到 5.7 后不起作用

转载 作者:行者123 更新时间:2023-11-29 11:33:16 25 4
gpt4 key购买 nike

我刚刚将 Ubuntu 从 15.10 升级到 16.04,这也将 MySQL 从 5.6 升级到 5.7。

我以前没有 root 密码(它只是一个本地开发虚拟机)。我无法以非特权用户身份执行“mysql -u root”,但是当我更改为 root ubuntu 用户时,我可以毫无问题地启动 mysql 客户端。两个用户的 mysql 二进制文件是相同的,因此不会出现任何欺骗行为。

user@ubuntu:~$ mysql -u root
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
user@ubuntu:~$ sudo -u root -i
root@ubuntu:~# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.12-0ubuntu1 (Ubuntu)

更改主机设置(localhost 与 127.0.0.1)没有任何影响。 mysql.user表的内容是:

+-----------+------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+-----------------------+-------------------------------------------+------------------+-----------------------+-------------------+----------------+
| Host | User | Select_priv | Insert_priv | Update_priv | Delete_priv | Create_priv | Drop_priv | Reload_priv | Shutdown_priv | Process_priv | File_priv | Grant_priv | References_priv | Index_priv | Alter_priv | Show_db_priv | Super_priv | Create_tmp_table_priv | Lock_tables_priv | Execute_priv | Repl_slave_priv | Repl_client_priv | Create_view_priv | Show_view_priv | Create_routine_priv | Alter_routine_priv | Create_user_priv | Event_priv | Trigger_priv | Create_tablespace_priv | ssl_type | ssl_cipher | x509_issuer | x509_subject | max_questions | max_updates | max_connections | max_user_connections | plugin | authentication_string | password_expired | password_last_changed | password_lifetime | account_locked |
+-----------+------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+-----------------------+-------------------------------------------+------------------+-----------------------+-------------------+----------------+
| localhost | root | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | | | | | 0 | 0 | 0 | 0 | auth_socket | | N | 2016-05-04 21:46:45 | NULL | N |
| ubuntu | root | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | | | | | 0 | 0 | 0 | 0 | mysql_native_password | | N | 2016-05-04 21:46:45 | NULL | N |
| 127.0.0.1 | root | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | | | | | 0 | 0 | 0 | 0 | mysql_native_password | | N | 2016-05-04 21:46:45 | NULL | N |
+-----------+------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+-----------------------+-------------------------------------------+------------------+-----------------------+-------------------+----------------+

任何关于如何更好地调试这里发生的事情的想法将不胜感激。

最佳答案

我发现问题了!

在升级过程中,MySQL 添加了 auth_socket插件类型。这种调整意味着当连接到 localhost 时,我不能只是简单地添加“-uroot”标志并期望它起作用,因为 MySQL 会将当前用户的名称与请求的 mysql 名称进行比较。如果能有来自 MySQL 的更有用的错误消息就更好了。

来自MySQL documentation :

If a user on the local host with a login name of stefanie invokes mysql with the option --user=valerie to connect through the socket file, the server uses auth_socket to authenticate the client. The plugin determines that the --user option value (valerie) differs from the client user's name (stephanie) and refuses the connection. If a user named valerie tries the same thing, the plugin finds that the user name and the MySQL user name are both valerie and permits the connection. However, the plugin refuses the connection even for valerie if the connection is made using a different protocol, such as TCP/IP.

关于mysql - "mysql -u root"在 Ubuntu 上从 5.6 升级到 5.7 后不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37041155/

25 4 0