mysql数据库root密码忘记如何重置?
1先停止数据库服务
/etc/init.d/mysqld stop service mysqld stop /usr/local/mysql/bin/mysqld stop
systemctl stop mysqld
2采用安全模式启动数据库(空密码方式进入数据库)
mysqld_safe --skip-grant-tables --skip-networking &
命令: mysqld_safe
参数:
--skip-grant-tables Start without grant tables. This gives all users FULL 数据库服务启动时,不加载授权表(没有保安)
--skip-networking Don't allow connection with TCP/IP
关闭远程连接端口
3设置数据库密码信息
flush privileges; 说明: 由于不加载授权表连接,此时修改root密码,需要加载授权表;
alter user root@'localhost' identified by '123456'; 说明: 修改root密码
4重启数据库服务
pkill mysql ---> 首先关闭手动安全运行的数据库服务 /etc/init.d/mysqld start ----> 重启mysqld服务
5验证数据库密码
mysql -uroot -p123456
说明: 以修改后的密码使用root密码登录.
浙公网安备 33010602011771号