系统:ubuntu1404
找到mysql的 my.cnf
/etc/mysql my.cnf
sudo vim my.cnf
在[mysqld]下面添加
skip-grant-tables
保存退出(ESC !:wq)
重启服务
sudo service mysql restart
mysql -uroot
use mysql
update user set password=password('root') where user='root'; --修改密码
flush privileges; --刷新
删除my.cnf [mysqld]
skip-grant-tables
用密码登陆即可
方法二:
/etc/init.d/mysql stop
stop fail的
cat /run/mysqld/mysqld.pid
kill xxx
再/etc/init.d/mysql stop
mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
mysql -u root
mysql 5.7设置密码
use mysql
update mysql.user set authentication_string=password('123456') where user='root';
FLUSH PRIVILEGES;
quit
# /etc/init.d/mysql restart
# mysql -uroot -p
Enter password: <输入新设的密码newpassword>