System environment:
[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)
skip-grant-tables skip grant tables during startup
In this mode, you can log in without a password, and commands related to authorization cannot be used
Operation process:
# 停止正在运行的mysql /etc/init.d/mysqld stop # 启动mysql /application/mysql/bin/mysqld_safe --skip-grant-tables --skip-networking & # 使用--skip-networking是为了禁止用户通过网络登录,此时无密登录,仅让自己无密登录进行设置密码 # 进入mysql进行操作 # 将root密码改为123456 mysql> use mysql; mysql> update user set password=PASSWORD('123456') where user='root' and host='localhost'; mysql> flush privileges;
restart mysql
/etc/init.d/mysqld restart
login mysql with new password at login
Note: Readers modify the user's password according to their own situation, not only the root user, this blog post is for reference only!