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)]>
复制代码
相关文章
相关标签/搜索