centos系统

1】mysql5.6.x环境

centos6.x关闭mysql

# /etc/init.d/mysql stop

centos7.x关闭mysql

#systemctl stop mysqld

# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &

# mysql -u root mysql

mysql> UPDATE user SET Password=PASSWORD(’newpassword’) where USER=’root’;

mysql> FLUSH PRIVILEGES;

mysql> quit

# /etc/init.d/mysql restart

# mysql -uroot -p

Enter password: <输入新设的密码newpassword>

mysql> 


2】mysql5.7.x环境

#vim /etc/my.cnf

 [mysqld]

  skip-grant-tables

 :wq! #保存退出

//登录数据库

#mysql -uroot -p

>UPDATE user SET Password=PASSWORD("userpasswd") where user="username";

> flush privileges;

> quit

//把 /etc/my.cnf 的 skip-grant-tables 这行注释掉

//重启服务

#systemctl restrt mysqld

到此,已可以成功登录了!!!!