Existuje tolik odpovědí, které říkají, že je třeba přeinstalovat mysql nebo použít kombinaci
mysqld_safe --skip-grant-tables
a / nebo
UPDATE mysql.user SET Password=PASSWORD('password')
a / nebo něco jiného ...
... Nic z toho mi nefungovalo
Zde je to, co mi fungovalo na Ubuntu 18.04, shora
Se speciálním kreditem pro toto odpověď za to, že jste mě vykopali z frustrace z tohoto ...
$ sudo apt install mysql-server
$ sudo cat /etc/mysql/debian.cnf
Všimněte si řádků, které zní:
user = debian-sys-maint
password = blahblahblah
Potom:
$ mysql -u debian-sys-maint -p
Enter password: // type 'blahblahblah', ie. 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; // When you don't have auto-commit switched on
Buď:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
Nebo:
// For MySQL 5.7+
UPDATE mysql.user SET authentication_string=PASSWORD('new_password') where user='root';
Potom:
mysql> FLUSH PRIVILEGES;
mysql> COMMIT; // When you don't have auto-commit switched on
mysql> EXIT
$ sudo service mysql restart
$ mysql -u root -p
Enter password: // Yay! 'new_password' now works!