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


    安装完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]>
    
  • 相关阅读:
    CURL常用命令
    极客无极限 一行HTML5代码引发的创意大爆炸
    JS的prototype和__proto__(含es6的class)
    leetcode 44:construct-binary-tree-from-preorder-and-inorder
    leetcode 43:construct-binary-tree-from-inorder-and-postorder
    leetcode 42:binary-tree-level-order-traversal-ii
    leetcode 38:path-sum
    leetcode 37:path-sum-ii
    leetcode 33:pascals-triangle
    leetcode 32:pascals-triangle-ii
  • 原文地址:https://www.cnblogs.com/1328497946TS/p/13162531.html
Copyright © 2020-2023  润新知