使用以下方式可以無密碼進(jìn)入mysql:
- 以系統(tǒng)管理員權(quán)限進(jìn)入mysql
sudo mysql -uroot
- 以debian用戶的賬號(hào)密碼進(jìn)入mysql
- 進(jìn)入
/etc/mysql/debian.cnf
中找到賬號(hào)(user)和密碼(password) - 然后登陸到
mysql
mysql -u<user> -p<password>
- 進(jìn)入
- 編輯
/etc/mysql/mysql.conf.d/mysqld.cnf
文件。- 在
[mysqld]
下方的skip-external-locking
下面添加一行:skip-grant-tables
- 重啟
mysql
服務(wù)sudo service mysql restart
- 在
成功進(jìn)入mysql后蒋譬,在mysql的命令行中通過輸入以下命令來將 root
用戶的密碼設(shè)置為 root
。
use mysql;
update mysql.user set authentication_string=password('root') where user='root' and Host ='localhost';
update user set plugin="mysql_native_password";
flush privileges;
最后重其服務(wù)就可以用我們剛剛設(shè)置的密碼進(jìn)行登陸了并齐。(設(shè)置了 skip-grant-tables
參數(shù)的同學(xué)別忘記把這個(gè)參數(shù)刪掉或在注釋掉!@认堋)