vim /etc/mysql/mysql.conf.d/mysqld.cnf
在[mysqld]段下加入一行“skip-grant-tables”
use mysql
update mysql.user set authentication_string=password('new_pass') where user='root';
flush privileges;
複制
把剛才加入的那一行“skip-grant-tables”注釋或删除掉。
service mysql restart
啟動:sudo service mysql start
停止:sudo service mysql stop
參考連結
- Python 操作 MySQL 的正确姿勢
- https://www.cnblogs.com/wt11/p/6141225.html