1. 獲取可用用戶(hù)名
$ sudo cat /etc/mysql/debian.cnf
可以看到該文件中的內(nèi)容
[client]
host = localhost
user = debian-sys-maint
password = ********
socket = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host = localhost
user = debian-sys-maint
password = ********
socket = /var/run/mysqld/mysqld.sock
2. 使用該用戶(hù)名進(jìn)入mysql
$ mysql -u debian-sys-maint -p
Enter password:
3. 修改mysql數(shù)據(jù)庫(kù)中的user表
用戶(hù)名和密碼存在該表中
$ update mysql.user set authentication_string=password('123qwe') \
> where user='root'
4. 重啟mysql
$ service mysql restart