添加红色部分代码:
[root@rhel ~]# vi /etc/my.cnf
[mysqld]
skip-grant-tables
max_connections=1000
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
保存退出,重启服务。
[root@rhel ~]# service mysqld restart
停止 MySQL: [确定]
启动 MySQL:
[root@rhel ~]# mysql -u root -p
Enter password: //此处直接回车,即可进入mysql数据库
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.0.77 Source distribution
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.
mysql>
然后根据自己情况修改密码即可。
修改密码可参考:https://www.rootop.org/pages/354.html
命令行参数启动mysql:/usr/bin/mysqld_safe –skip-grant-tables &
–skip-grant-tables
在启动mysql时不启动 grant-tables 授权表。
PS:
如果在my.cnf中添加 skip-grant-tables 后,那么任何的帐号用任何的密码都可以登录到mysql数据库。
原创文章,转载请注明。本文链接地址: https://www.rootop.org/pages/787.html