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';
--Update--
Sometimes you will need to restart your mysql server.
sudo service mysql restart
or
sudo systemctl restart mysql