树莓派raspberry Pi 3B+安装mysql未提示输入密码,安装后修改mysql密码默认密码
使用mysql -uroot -p 命令连接mysql时,报错
pi@raspberrypi:/ $ mysql -uroot -p
Enter password:
ERROR1698 (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 idis 5Server version:10.1.37-MariaDB-0+deb9u1 Raspbian 9.0Copyright (c)2000, 2018, Oracle, MariaDB Corporation Ab andothers.
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.00sec)
Rows matched:1 Changed: 1Warnings: 0
MariaDB [mysql]> update user set plugin="mysql_native_password";
Query OK,1 row affected (0.00sec)
Rows matched:1 Changed: 1Warnings: 0
MariaDB [mysql]>flush privileges;
Query OK, 0 rows affected (0.00sec)
MariaDB [mysql]>quit;
Bye
重启树莓派正常登录
此方法也使用与Ubuntu16以上的版本。