Mysql密碼忘了怎麼登陸?

話很少說直接寫解決方案: 環境:centos7 數據庫:mariadb 1.關閉mysql服務mysql

[root@a ~]# systemctl stop mariadb
複製代碼

2.kill掉mysql進程sql

[root@a ~]# ps -ef |grep mariadb
root       8438   8420  0 06:22 pts/0    00:00:00 grep --color=auto mariadb
[root@a ~]# kill 8420
複製代碼

3.修改mysql配置文件 添加skip-grant-tables數據庫

[root@a ~]# vi /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-grant-tables 
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
複製代碼

4.重啓服務無密碼登陸centos

[root@a ~]# systemctl restart mariadb
[root@a ~]# mysql -uroot
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.64-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>
複製代碼

5.在mysql裏面就能夠從新設置密碼了markdown

MariaDB [(none)]> update mysql.user set Password=password('a') where User='root';
Query OK, 0 rows affected (0.00 sec) Rows matched: 4 Changed: 0 Warnings: 0 複製代碼

6.登陸成功socket

[root@a ~]# mysql -uroot -pa
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.64-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>
複製代碼
相關文章
相關標籤/搜索