1$ sudo cat /etc/mysql/debian.cnf
2Note the lines which read:
3
4user = debian-sys-maint
5password = blahblahblah
6Then:
7
8$ mysql -u debian-sys-maint -p
9Enter password: // type 'blahblahblah', ie. password from debian.cnf
10
11mysql> USE mysql
12mysql> SELECT User, Host, plugin FROM mysql.user;
13+------------------+-----------+-----------------------+
14| User | Host | plugin |
15+------------------+-----------+-----------------------+
16| root | localhost | auth_socket |
17| mysql.session | localhost | mysql_native_password |
18| mysql.sys | localhost | mysql_native_password |
19| debian-sys-maint | localhost | mysql_native_password |
20+------------------+-----------+-----------------------+
214 rows in set (0.00 sec)
22
23mysql> UPDATE user SET plugin='mysql_native_password' WHERE User='root';
24mysql> COMMIT; // When you don't have auto-commit switched on
25Either:
26
27mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
28Or:
29
30// For MySQL 5.7+
31UPDATE mysql.user SET authentication_string=PASSWORD('new_password') where user='root';
32Then:
33
34mysql> FLUSH PRIVILEGES;
35mysql> COMMIT; // When you don't have auto-commit switched on
36mysql> EXIT
37
38$ sudo service mysql restart
39$ mysql -u root -p
40Enter password: // Yay! 'new_password' now works!