系统环境:
[root@db02 ~]# uname -m x86_64 [root@db02 ~]# uname -r 2.6.32-696.el6.x86_64 [root@db02 ~]# cat /etc/redhat-release CentOS release 6.9 (Final)
5.6和5.7有点不同,在5.6中列名为password,但5.7为authentication_stringmysql
操做过程:
一、修改/etc/my.cnf 在[mysqld]下面一行加入skip-grant-tables
[root@db02 ~]# vim /etc/my.cnf [mysqld] skip-grant-tables ……………………二、启动mysql
/etc/init.d/mysqld-5.7.17 start三、无密进入数据库,修改密码
mysql> use mysql; mysql> update user set authentication_string=PASSWORD('123yk') where user='root' and host='localhost'; mysql> flush privileges;四、再次修改/etc/my.cnf,去掉刚才添加的skip-grant-tables
[root@db02 ~]# vim /etc/my.cnf [mysqld] # skip-grant-tables五、重启mysql
/etc/init.d/mysqld-5.7.17 restart六、使用新修改的密码登陆
/application/mysql-5.7.17/bin/mysql -uroot -p
注:用户根据自身的系统环境和自身的状况进行修改和设置密码,此博文仅供从参考sql