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

  1. [root@localhost ~]# mysql -uroot -p
  2. Enter password:
  3. ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
  4. [root@localhost ~]# mysql -uroot -p
  5. Enter password:
  6. ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

环境

系统版本

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

MariaDB版本

  1. Server version: 5.5.56-MariaDB MariaDB Server

重置密码的步骤

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

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

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

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

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

  1. MariaDB [(none)]> use mysql;
  2. Reading table information for completion of table and column names
  3. You can turn off this feature to get a quicker startup with -A
  4. Database changed
  5. MariaDB [mysql]> update user set password=PASSWORD("admin@1234") where user='root'; # 重置数据库密码
  6. Query OK, 5 rows affected (0.00 sec)
  7. Rows matched: 5 Changed: 5 Warnings: 0
  8. MariaDB [mysql]> flush privileges; # 刷新权限
  9. Query OK, 0 rows affected (0.02 sec)
  10. MariaDB [mysql]> quit
  11. Bye

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

  1. [root@localhost ~]# systemctl restart mariadb # 重启MariaDB数据库
  2. [root@localhost ~]# mysql -uroot -p
  3. Enter password:
  4. Welcome to the MariaDB monitor. Commands end with ; or \g.
  5. Your MariaDB connection id is 7
  6. Server version: 5.5.56-MariaDB MariaDB Server
  7. Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
  8. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  9. MariaDB [(none)]> show databases;
  10. +--------------------+
  11. | Database |
  12. +--------------------+
  13. | information_schema |
  14. | mysql |
  15. | netperformance |
  16. | performance_schema |
  17. | test |
  18. +--------------------+
  19. 15 rows in set (0.01 sec)
  20. MariaDB [(none)]> use mysql;
  21. Reading table information for completion of table and column names
  22. You can turn off this feature to get a quicker startup with -A
  23. Database changed
  24. MariaDB [mysql]> show tables;
  25. +---------------------------+
  26. | Tables_in_mysql |
  27. +---------------------------+
  28. | columns_priv |
  29. | db |
  30. | event |
  31. | func |
  32. | general_log |
  33. | help_category |
  34. | help_keyword |
  35. | help_relation |
  36. | help_topic |
  37. | host |
  38. | ndb_binlog_index |
  39. | plugin |
  40. | proc |
  41. | procs_priv |
  42. | proxies_priv |
  43. | servers |
  44. | slow_log |
  45. | tables_priv |
  46. | time_zone |
  47. | time_zone_leap_second |
  48. | time_zone_name |
  49. | time_zone_transition |
  50. | time_zone_transition_type |
  51. | user |
  52. +---------------------------+
  53. 24 rows in set (0.00 sec)
  54. MariaDB [mysql]> select User,Host from user;
  55. +---------+-----------------------+
  56. | User | Host |
  57. +---------+-----------------------+
  58. | root | % |
  59. | root | 127.0.0.1 |
  60. | root | ::1 |
  61. | | localhost |
  62. | root | localhost |
  63. | | localhost.localdomain |
  64. | root | localhost.localdomain |
  65. +---------+-----------------------+
  66. 8 rows in set (0.03 sec)
  67. MariaDB [mysql]> exit
  68. Bye

5.查看MariaDB进程是否正常

  1. [root@localhost ~]# ps aux | grep mysql # 查看MariaDB数据库的进程
  2. root 6122 0.0 0.1 113260 1592 pts/0 S+ 17:51 0:00 /bin/sh /usr/bin/mysqld_safe --skip-grant-tables
  3. 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
  4. root 6295 0.0 0.0 112660 976 pts/2 R+ 17:55 0:00 grep --color=auto mysql
  5. [root@localhost ~]# ss -tunlp | grep 3306 # 查看MariaDB数据库的端口
  6. 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. Eclipse 查看 WebService 服务请求和响应消息

    每个WebService 对入参和返参都是有自己的要求的:别人调用我的WebService,需要按照我的要求进行传参.当我返回数据时,我也得告诉别人,我的返回数据是怎样组织的,方便别人读取. 那怎样查 ...

  2. Servlet的 GenericServlet 和 HttpServlet

    一.GenericServlet? servlet 是一个接口 下面有两个抽象类 GenericServlet 和 HttpServlet 需要被 继承并重写其中的方法. package javawe ...

  3. springboot +thymeleaf+myql 记录

    thymeleaf官方文档: https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.pdf demo案例:https://github. ...

  4. js 实现数据结构 -- 栈

    原文: 在 Javascript 中学习数据结构与算法. 概念: 栈是一种遵从先进后出 (LIFO) 原则的有序集合:新添加的或待删除的元素都保存在栈的末尾,称作栈顶,另一端为栈底.在栈里,新元素都靠 ...

  5. luogu2597-[ZJOI2012]灾难 && DAG支配树

    Description P2597 [ZJOI2012]灾难 - 洛谷 | 计算机科学教育新生态 Solution 根据题意建图, 新建一个 \(S\) 点, 连向每个没有入边的点. 定义每个点 \( ...

  6. wrk编译报错gcc: Command not found

    报错信息如下: 问题原因:没有安装gcc 解决办法: yum -y install gcc+ gcc-c++ 若需升级gcc,则采用如下命令: yum -y update gcc

  7. BZOJ2527[Poi2011]Meteors——整体二分+树状数组

    题目描述 Byteotian Interstellar Union (BIU) has recently discovered a new planet in a nearby galaxy. The ...

  8. 爬虫 BeatifulSoup 模块

    BeatifulSoup 模块 介绍 Beautiful Soup 是一个可以从HTML或XML文件中提取数据的Python库 安装 pip install beautifulsoup4  解析器下载 ...

  9. Java多线程编程-线程之间的通信

    转载自:这里 学习了基础的线程知识 看到了 线程之间的通信 线程之间有哪些通信方式呢? 1.同步 这里讲的同步是指多个线程通过synchronized关键字这种方式来实现线程间的通信. public ...

  10. CF914G Sum the Fibonacci

    解:发现我们对a和b做一个集合卷积,对d和e做一个^FWT,然后把这三个全部对位乘上斐波那契数,然后做&FWT就行了. #include <bits/stdc++.h> , MO ...