使用 sudo apt install mysql-server 安装的mysql root密码你不知道吧,看如下资料:
https://stackoverflow.com/questions/42421585/default-password-of-mysql-in-ubuntu-server-16-04/49778695
I had a fresh installation of mysql-server on Ubuntu 18.10 and couldn't login with default password. Then only I got to know that by default root user is authenticated using auth_socket. So as in the answer when the plugin changed to mysql_native_password, we can use mysql default password
$ sudo apt install mysql-server
$ sudo cat /etc/mysql/debian.cnf
You can find the following lines in there
user = debian-sys-maint
password = password_for_the_user
Then:
$ mysql -u debian-sys-maint -p
Enter password:
type the password from debian.cnf
mysql> USE mysql
mysql> SELECT User, Host, plugin FROM mysql.user;
+------------------+-----------+-----------------------+
| User | Host | plugin |
+------------------+-----------+-----------------------+
| root | localhost | auth_socket |
| mysql.session | localhost | mysql_native_password |
| mysql.sys | localhost | mysql_native_password |
| debian-sys-maint | localhost | mysql_native_password |
+------------------+-----------+-----------------------+
4 rows in set (0.00 sec)
mysql> UPDATE user SET plugin='mysql_native_password' WHERE User='root';
mysql> COMMIT;
Either:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
Or:
// For MySQL 5.7+
mysql>UPDATE mysql.user SET authentication_string=PASSWORD('new_password') where user='root';
shareimprove this answer
edited Feb 14 at 10:17
answered Jan 13 at 2:26
Yasii
38938
You should add some details as to what OP was doing wrong, and why this solution works – schu34 Jan 13 at 2:34
You should add that context as an edit to your answer :) – schu34 Jan 13 at 14:30
I had to restart mysql server after do this solution. sudo service mysql restart – Tuxman May 11 at 20:05