1. 程式人生 > >樹莓派raspberry Pi 3B+系統中安裝mysql過程中不提示輸入密碼,安裝完後如何設置密碼

樹莓派raspberry Pi 3B+系統中安裝mysql過程中不提示輸入密碼,安裝完後如何設置密碼

rate current 默認 oca acc inpu .so error enter

樹莓派raspberry Pi 3B+安裝mysql未提示輸入密碼,安裝後修改mysql密碼默認密碼

使用mysql -uroot -p 命令連接mysql時,報錯

pi@raspberrypi:/ $ mysql -uroot -p 
Enter password: 
ERROR 1698 (28000): Access denied for user root@localhost

按照網上的說法,

1.進入到etc/mysql 目錄下,查看debian.cnf文件,使用默認的用戶名和密碼登錄

pi@raspberrypi:/etc/mysql $ sudo cat debian.cnf
# Automatically generated for Debian scripts. DO NOT TOUCH! [client] host = localhost user = root password = socket = /var/run/mysqld/mysqld.sock [mysql_upgrade] host = localhost user = root password = socket = /var/run/mysqld/mysqld.sock basedir = /usr

結果是默認密碼是空,多次嘗試不成功,依然報錯。

最後輸入:sudo mysql -uroot(使用root身份免密碼登錄,一定要sudo,不要輸入-p 否則進不去,我就是嘗試多次,不成功)

終於進入系統

pi@raspberrypi:/ $ sudo mysql -uroot 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 10.1.37-MariaDB-0+deb9u1 Raspbian 9.0

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

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

MariaDB [(none)]>

原來系統用的mysql的版本是MariaDB,是mysql的一個主要分支,但是它全面兼容mysql。

後續的操作按照網上介紹的內容繼續操作:

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.01 sec)

然後使用use mysql; 命令打開數據庫。

MariaDB [(none)]> use mysql;
MariaDB [mysql]> update user set authentication_string=("你要設置的密碼") where user=root;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [mysql]> update user set plugin="mysql_native_password";
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [mysql]> quit;
Bye

重啟樹莓派正常登錄

此方法也使用與Ubuntu16以上的版本。

樹莓派raspberry Pi 3B+系統中安裝mysql過程中不提示輸入密碼,安裝完後如何設置密碼