一、没有输入或输入错误的root用户密码,没法进入数据库:mysql
# mysql -uroot -psql
(1)没有输入root用户密码,直接回车:数据库
(2)输入错误的root用户密码:ide
二、强制结束MySQL进程:spa
# yum -y install psmiscblog
# killall mysqld进程
# pkill mysqldip
# ps -ef | grep mysqlstring
# ss -tunlp | grep 3306it
三、使用mysqld命令,增长--skip-grant-tables参数,跳过权限表,启动数据库:
# mysqld --defaults-file=/etc/my.cnf --user=mysql --skip-grant-tables &
# ps -ef | grep mysql
# ss -tunlp | grep 3306
四、使用mysql命令直接进入数据库,为root用户设置新的密码并刷新权限:
# mysql
mysql> use mysql;
mysql> update user set authentication_string=password('root@1234') where user='root';
mysql> flush privileges;
五、重启数据库:
# killall mysqld
# pkill mysqld
# ps -ef | grep mysql
# ss -tunlp | grep 3306
# systemctl start mysqld
六、输入root用户新设置的密码root@1234,进入数据库:
# mysql -uroot -p