码迷,mamicode.com
首页 > 数据库 > 详细

ERROR 1698 (28000): Access denied for user 'root'@'localhost'

时间:2020-06-19 13:47:45      阅读:68      评论:0      收藏:0      [点我收藏+]

标签:erro   必须   change   不同   htm   database   match   ogr   denied   

安装完Mysql之后使用root账户登录出现1698错误

pi@raspberrypi:~ $ mysql -uroot
ERROR 1698 (28000): Access denied for user ‘root‘@‘localhost‘
pi@raspberrypi:~ $

查看Mysql官方文档发现

Using Socket Pluggable Authentication

The socket plugin checks whether the socket user name (the operating system user name) matches the MySQL user name specified by the client program to the server. If the names do not match, the plugin checks whether the socket user name matches the name specified in the authentication_string column of the mysql.user system table row. If a match is found, the plugin permits the connection.(套接字插件检查套接字用户名(操作系统用户名)是否与客户端程序指定的MySQL用户名匹配到服务器。如果名称不匹配,插件将检查套接字用户名是否与mysql.user用户系统表行。如果找到匹配项,则插件允许连接。)

系统当前的用户是pi,要使用root账户必须使用sudo命令获得root身份再与Mysql连接。所以使用sudo mysql -uroot可以进入Mysql命令行。

pi@raspberrypi:~ $ sudo service mysql restart
pi@raspberrypi:~ $ mysql -uroot
ERROR 1698 (28000): Access denied for user ‘root‘@‘localhost‘
pi@raspberrypi:~ $ sudo mysql -uroot
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 33
Server version: 10.0.28-MariaDB-2+b1 Raspbian testing-staging

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

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

MariaDB [(none)]>

解决办法

1. 更改plugin(身份验证插件)

长期以来,MySQL支持不同的身份验证插件,在此使用mysql_native_password传统的身份验证方法,不是很安全(它仅使用密码的哈希值),但是与较旧的驱动程序兼容。

  1. sudo mysql -u root进入MySQL命令行
  2. update user set plugin="mysql_native_password" where user="root"; 要设置密码的话多加一条update user set password=PASSWORD("1989") where user="root";
  3. flush privileges;
  4. exit;
  5. sudo service mysql restart
pi@raspberrypi:~ $ sudo service mysql restart
pi@raspberrypi:~ $ mysql -uroot
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 32
Server version: 10.0.28-MariaDB-2+b1 Raspbian testing-staging

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

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

MariaDB [(none)]>

没有设置密码直接使用mysql -u root即可进入MySQL命令行。

2. 创建一个新的账户(pi)

  1. sudo mysql -u root进入MySQL命令行
  2. USE mysql
  3. CREATE USER ‘YOU_SYSTEM_USER‘@‘localhost‘ IDENTIFIED BY ‘‘;
  4. GRANT ALL PRIVILEGES ON *.* TO ‘YOUR_SYSTEM_USER‘@‘localhost‘;
  5. UPDATE user SET plugin=‘auth_socket‘ WHERE User=‘YOUR_SYSTEM_USER‘;
  6. FLUSH PRIVILEGES;
  7. exit;
  8. sudo service mysql restart

使用mysql -upi直接进入MySQL命令行。

pi@raspberrypi:~ $ mysql -upi
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 34
Server version: 10.0.28-MariaDB-2+b1 Raspbian testing-staging

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

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

MariaDB [(none)]>

查看用户表

pi@raspberrypi:~ $ mysql -upi
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 34
Server version: 10.0.28-MariaDB-2+b1 Raspbian testing-staging

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

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

MariaDB [(none)]> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [mysql]> select user,host,plugin,password from user;
+------+-----------+-----------------------+----------+
| user | host      | plugin                | password |
+------+-----------+-----------------------+----------+
| root | localhost | mysql_native_password |          |
| pi   | localhost | unix_socket           |          |
+------+-----------+-----------------------+----------+
2 rows in set (0.00 sec)

MariaDB [mysql]>

ERROR 1698 (28000): Access denied for user 'root'@'localhost'

标签:erro   必须   change   不同   htm   database   match   ogr   denied   

原文地址:https://www.cnblogs.com/1328497946TS/p/13162531.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!