mysql 忘记root密码

修改maraidb root密码
1.查看安装的MySQL还是mariadb
#rpm -ql|grep mysql
#rpm -ql|grep mariadb
2.使用root登录发现root被本地禁用

3.进入mariadb配置文件,增加一条配置
# vi /etc/my.cnf
在[mysqld]项中增加
skip-grant-tables

4.重启zabbix服务
#systemctl restart mariadb

5.重新登录mysql
#注意密码为空
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 25
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.

#使用系统管理库mysql
MariaDB [(none)]> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

#查看mysql库中表
MariaDB [mysql]> show tables;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
| event                     |
| func                      |
| general_log               |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| host                      |
| ndb_binlog_index          |
| plugin                    |
| proc                      |
| procs_priv                |
| proxies_priv              |
| servers                   |
| slow_log                  |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+
24 rows in set (0.00 sec)


#用户名及密码都保存在user表中
 MariaDB [mysql]> UPDATE user SET Password = password('zabbix') WHERE User = 'root';
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4  Changed: 4  Warnings: 0

#刷新数据库
MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

6. 将配置文件/etc/my.cnf [mysqld]中的skip-grant-tables注释掉,重启mysql服务即可

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# 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
#skip-grant-tables
[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

#重启mariadb数据库
systemctl restart maraidb




posted @ 2020-08-05 12:02  3哥哥  阅读(132)  评论(0编辑  收藏  举报