Forget solution mysql super-user password

This article is for mariadb database with yum install, if it is tar packages installed mysql database, just close the database commands in different ways to start it.

方法一:
[root@localhost ~]# killall -u mysql
[root@localhost ~]# mysqld_safe --skip-grant-tables &
按一次回车
[root@localhost ~]# jobs
[1]+ 运行中 mysqld_safe --skip-grant-tables &
[root@localhost ~]# mysql
MariaDB [(none)]> use mysql
MariaDB [mysql]> update user set password=password('111111') where user='root';
MariaDB [mysql]> flush privileges;
MariaDB [mysql]> exit
[root@localhost ~]# ps
PID TTY TIME CMD
8115 pts/0 00:00:00 bash
10021 pts/0 00:00:00 mysqld_safe
10193 pts/0 00:00:00 ps
[root@localhost ~]# kill -9 10021
[root@localhost ~]# ps
PID TTY TIME CMD
8115 pts/0 00:00:00 bash
PTS 10195/0 00:00:00 PS
[. 1] + a killed-Grant-Tables --skip the mysqld_safe
[the root @ localhost ~] # MySQL -uroot--p'111111 '

方法二:
[root@localhost ~]# vim /etc/my.cnf
添加:
[mysqld]
port=3306
socket=/tmp/mysql.sock
skip-external-locking
skip_grant_tables
[root@localhost ~]# killall -u mysql
[root@localhost ~]# systemctl start mariadb
[root@localhost ~]# mysql
MariaDB [(none)]> update mysql.user set password=password('123123') where user='root';
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> exit
[root@localhost ~]# vim /etc/my.cnf
删除添加的五行:
[root@localhost ~]# mysql -uroot -p'123123'

Guess you like

Origin www.cnblogs.com/lyqlyqlyq/p/11652850.html