错误 1698 (28000):拒绝用户“root”@“localhost”访问

错误 1698 (28000):拒绝用户“root”@“localhost”访问
alhelal@VimLaTeX:~$ mysql -u root -p
Enter password: 
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
alhelal@VimLaTeX:~$ sudo mysql -u root -p
[sudo] password for alhelal: 
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 35
Server version: 10.1.29-MariaDB-6 Ubuntu 18.04

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]>   

为什么 mariadb 不允许普通 ubuntu 用户以 mysql root 用户身份进入 mysql?

我也试过错误 1698(28000):Ubuntu 18.04 上用户“root”@“localhost”的访问被拒绝但失败了?

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'test'' at line 1

答案1

根据这个答案从 SO 来看,这可能是因为您的 root 用户正在使用auth_socketUbuntu 上 MySQL/MariaDB 中默认使用的插件。

$ sudo mysql -u root

MariaDB [mysql]> USE mysql;
MariaDB [mysql]> SELECT User, Host, plugin FROM mysql.user;

+------------------+-----------------------+
| User             | plugin                |
+------------------+-----------------------+
| root             | auth_socket           |
+------------------+-----------------------+

将其更改为mysql_native_password将允许您连接而不需要sudo

$ sudo mysql -u root

MariaDB [mysql]> USE mysql;
MariaDB [mysql]> UPDATE user SET plugin='mysql_native_password' WHERE User='root';
MariaDB [mysql]> FLUSH PRIVILEGES;
MariaDB [mysql]> exit;

$ service mysql restart

相关内容