虚拟机里的MariaDB忘记密码了,连接不上,只能重置MariaDB的密码,步骤参考网络

[root@localhost ~]# mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@localhost ~]# mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

环境

系统版本

[root@localhost ~]# cat /etc/redhat-release         # 查看系统版本
CentOS Linux release 7.4.1708 (Core)

MariaDB版本

Server version: 5.5.56-MariaDB MariaDB Server

重置密码的步骤

1.重启,以安全模式进行MariaDB

[root@localhost ~]# systemctl status mariadb            # 查看MariaDB数据库状态
● mariadb.service - MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled)
Active: active (running) since Thu 2018-07-12 17:42:01 CST; 4min 37s ago
Process: 1043 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS)
Process: 989 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS)
Main PID: 1042 (mysqld_safe)
CGroup: /system.slice/mariadb.service
├─1042 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
└─1141 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin ... Jul 12 17:41:56 localhost.localdomain systemd[1]: Starting MariaDB database server...
Jul 12 17:41:57 localhost.localdomain mariadb-prepare-db-dir[989]: Database MariaDB is probably initialized in /...ne.
Jul 12 17:41:57 localhost.localdomain mariadb-prepare-db-dir[989]: If this is not the case, make sure the /var/l...ir.
Jul 12 17:41:58 localhost.localdomain mysqld_safe[1042]: 180712 17:41:58 mysqld_safe Logging to '/var/lib/mysql...rr'.
Jul 12 17:41:58 localhost.localdomain mysqld_safe[1042]: 180712 17:41:58 mysqld_safe Starting mysqld daemon wit...ysql
Jul 12 17:42:01 localhost.localdomain systemd[1]: Started MariaDB database server.
Hint: Some lines were ellipsized, use -l to show in full. [root@localhost ~]# systemctl stop mariadb # 停止MariaDB数据库
[root@localhost ~]# mysqld_safe --skip-grant-tables # 安全模式进行MariaDB,并且跳过授权表
180706 17:51:16 mysqld_safe Logging to '/var/lib/mysql/localhost.localdomain.err'.
180706 17:51:16 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

2.新建一个ssh连接窗口,进入bash,连接密码库

[root@localhost ~]# mysql -uroot -p                 # 连接数据库
Enter password: # 不要输入密码,直接回车
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 1
Server version: 5.5.56-MariaDB MariaDB Server Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

3.重置密码,退出MariaDB数据库

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
MariaDB [mysql]> update user set password=PASSWORD("admin@1234") where user='root'; # 重置数据库密码
Query OK, 5 rows affected (0.00 sec)
Rows matched: 5 Changed: 5 Warnings: 0 MariaDB [mysql]> flush privileges; # 刷新权限
Query OK, 0 rows affected (0.02 sec) MariaDB [mysql]> quit
Bye

4.重启MariaDB数据库,使用密码进入MariaDB数据库

[root@localhost ~]# systemctl restart mariadb                   # 重启MariaDB数据库
[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 7
Server version: 5.5.56-MariaDB MariaDB Server Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| netperformance |
| performance_schema |
| test |
+--------------------+
15 rows in set (0.01 sec) 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
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) MariaDB [mysql]> select User,Host from user;
+---------+-----------------------+
| User | Host |
+---------+-----------------------+
| root | % |
| root | 127.0.0.1 |
| root | ::1 |
| | localhost |
| root | localhost |
| | localhost.localdomain |
| root | localhost.localdomain |
+---------+-----------------------+
8 rows in set (0.03 sec) MariaDB [mysql]> exit
Bye

5.查看MariaDB进程是否正常

[root@localhost ~]# ps aux | grep mysql                     # 查看MariaDB数据库的进程
root 6122 0.0 0.1 113260 1592 pts/0 S+ 17:51 0:00 /bin/sh /usr/bin/mysqld_safe --skip-grant-tables
mysql 6206 0.4 9.2 922568 92556 pts/0 Sl+ 17:51 0:01 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --skip-grant-tables --log-error=/var/lib/mysql/localhost.localdomain.err --pid-file=localhost.localdomain.pid
root 6295 0.0 0.0 112660 976 pts/2 R+ 17:55 0:00 grep --color=auto mysql
[root@localhost ~]# ss -tunlp | grep 3306 # 查看MariaDB数据库的端口
tcp LISTEN 0 50 *:3306 *:* users:(("mysqld",pid=1141,fd=14))

CentOS7中MariaDB重置密码的更多相关文章

  1. centOS7中Mariadb数据库安装与基本管理

    一.Mariadb数据库安装 1. 直接yum源安装 yum -y install mariadb mariadb-serversystemctl start mariadb /启动Mariadb服务 ...

  2. kali linux中mariadb加上密码

    kali自带mysql.2019.4 中带得是:MariaDB.据说跟Mysql差不多.简单用了一下发现root用户可以不要密码进入Mysql! 这极不习惯,不输入密码感觉好像少了点什么.这肯定是权限 ...

  3. mariadb 重置密码

    1. sudo身份打开 /etc/mysql/my.cnf 在[mysqld]节点下增加如下代码: skip-grant-tables #忽略密码授权 2. 杀掉mysql进程,重启mariadb,这 ...

  4. 怎么清除SVN密码,以及重置eclipse中svn插件密码

    如何清除SVN密码,以及重置eclipse中svn插件密码? 清除SVN客户端密码方法: 邮件选择TortoiseSVN中的settings选项---Saved Data---右边会发现有个Authe ...

  5. Linux MariaDB 遗忘密码后重置密码

    Linux MariaDB 遗忘密码后重置密码 MariaDB 是 MySQL 的一个分支数据库.处理的办法和 MySQL 相同. 修改 MySQL 配置文件 在 [mysqld] 追加配置项: [r ...

  6. CentOS7下mongodb忘记密码后重置密码

    新装mongodb后,结果一段时间没有用,密码给忘记了,只能重置密码了. 步骤如下: 1.找到mongodb的配置文件 通过ps -ef|grep mongod找到mongodb的配置文件mongod ...

  7. Centos7 之 MariaDB(Mysql) root密码忘记的解决办法

    MariaDB(Mysql) root密码忘记的解决办法 1.首先先关闭mariadb数据库的服务 # 关闭mariadb服务命令(mysql的话命令就是将mariadb换成mysql) [root@ ...

  8. 在CentOS7中利用yum命令安装mysql

    在CentOS7中利用yum命令安装mysql 原创 2016年08月31日 10:42:33 标签: mysql / centos 4832 一.说明 我们是在VMware虚拟机上安装的mysql, ...

  9. 详解如何在CentOS7中使用Nginx和PHP7-FPM安装Nextcloud

    转载地址:https://www.jb51.net/article/109382.htm 这篇文章主要介绍了详解如何在CentOS7中使用Nginx和PHP7-FPM安装Nextcloud,会通过 N ...

随机推荐

  1. 使用Spring表达式语言进行装备--SpEL

    本文主要想记录最近的两个使用spring框架实现通过配置文件装备Bean,以及使用SpEL装备Bean. 1.使用配置文件装备Bean: 当我们写某些Bean的时候是希望这个Bean当中的属性是可以通 ...

  2. Python——三级菜单

    #三级菜单函数 menu = { '北京':{ 海淀:{ '五道口':{} '中关村':{} '上帝':{} } '昌平':{} '朝阳':{} '东城':{} }, '上海':{} '山东':{} ...

  3. SPP-net原理解读

    转载自:目标检测:SPP-net 地址https://blog.csdn.net/tinyzhao/article/details/53717136 上文说到R-CNN的最大瓶颈是2k个候选区域都要经 ...

  4. ML.NET is an open source and cross-platform machine learning framework

    https://www.microsoft.com/net/learn/apps/machine-learning-and-ai/ml-dotnet Machine Learning made for ...

  5. python基础5 字典

    一.字典 字典是python的基础数据类型之一:字典可以存储大量的数据,关系型数据. 同样他也是python中唯一的映射类的数据类型. 数据类型的分类: 可变的(不可哈希)数据类型:list,dict ...

  6. 启动jar的方式

    1.windows server 2008 start "srvRegistry" java -jar srvRegistry-1.0-SNAPSHOT.jar --spring. ...

  7. kubernetes 报错汇总

    一. pod的报错: 1. pod的容器无法启动报错: 报错信息: Normal SandboxChanged 4m9s (x12 over 5m18s) kubelet, k8sn1 Pod san ...

  8. P4783 【模板】矩阵求逆

    原题链接 https://www.luogu.org/problemnew/show/P4783 一道模板题,更重要的省选难度..... 题目要求的是一个n*n的逆矩阵,还要对大数取膜. 普通高中生: ...

  9. ovs之组网实验

    介绍 本示例将创建两个OVS实例和两个主机,其中每个OVS上接入一个主机,OVS实例之间有链路连接,形成一个链状拓扑,如图.在OVS组网完成之后,再通过手动方式添加流表,实现网络通信,从而验证实验可行 ...

  10. luogu4705玩游戏

    题解 我们要对于每个t,求一个(1/mn)sigma(ax+by)^t. 把系数不用管,把其他部分二项式展开一下: simga(ax^r*by^(t-r)*C(t,r)). 把组合数拆开,就变成了一个 ...