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