环境背景:CentOS 7.2

 

 

一、编辑/usr/lib/systemd/system/mariadb.service 文件,在Service段中添加
1
2
3
4
5
6
7
8
9
10
11
12
[Service]
Type=simple
User=mysql
Group=mysql
User=mysql
Group=mysql
 
ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n
# Note: we set --basedir to prevent probes that might trigger SELinux alarms,
# per bug #547485
#在Server段中的ExecStart出添加如下
ExecStart=/usr/bin/mysqld_safe --basedir=/usr --skip-grant-tables --skip-networking

二、键入systemctl daemon-reload使其立即生效

1
[root@node1 ~]# systemctl daemon-reload
三、重新启动mariadb服务并使用mysql联入
1
2
3
4
5
6
7
8
9
10
11
[root@node1 ~]# systemctl restart mariadb.service
[root@node1 ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.44-MariaDB MariaDB Server
 
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
MariaDB [(none)]>
四、更改root用户的密码
1
2
3
4
5
6
MariaDB [(none)]> UPDATE mysql.user SET Password=PASSWORD('xiaoshui') WHERE user='root' and host='localhost';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1  Changed: 0  Warnings: 0
 
MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
五、退出并关闭mariadb服务并把/usr/lib/systemd/system/mariadb.service文件中刚刚添加的那两行移除
1
2
ExecStart=/usr/bin/mysqld_safe --basedir=/usr 
ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID
六、启动mariadb服务,并使用新设置的密码连接
1
2
3
4
5
6
7
8
9
10
11
[root@node1 ~]# mysql -u root -h localhost -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 5.5.44-MariaDB MariaDB Server
 
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
MariaDB [(none)]>

参考:http://dashui.blog.51cto.com/11254923/1877042

[转]Mariadb的root密码忘记后的解决方法的更多相关文章

  1. MySQL root密码忘记后更优雅的解决方法

    MySQL root密码忘记后更优雅的解决方法 https://www.jb51.net/article/143453.htm /usr/bin/mysqld_safe --defaults-file ...

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

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

  3. root密码忘记后如何修改

    方法一: 1.在DOS窗口下输入net stop mysql5 或 net stop mysql 2.开一个DOS窗口,这个需要切换到mysql的bin目录.一般在bin目录里面创建一个批处理1.ba ...

  4. vmvare centos 7.0 root密码忘记后重置及总结

    今天遇到了一个比较尴尬的事情,我centos 7.0的虚拟机密码忘了.....里面还有我配置好的环境呢.于是我就上网上搜索各种方法,最后经我验证下面这个方法比较靠谱: 使用光盘修复Centos: ht ...

  5. mysql5.7中root密码忘记后修改密码

    一.更改my.cnf配置文件 1.用命令编辑/etc/my.cnf配置文件,即:vim /etc/my.cnf 或者 vi /etc/my.cnf 2.在[mysqld]下添加skip-grant-t ...

  6. CentOS忘记mariadb/mysql root密码解决办法

    本文不再更新,可能存在内容过时的情况,实时更新请访问原地址:CentOS忘记mariadb/mysql root密码解决办法: 这里有两种方式实现修改mariadb root密码. mariadb版本 ...

  7. Ubuntu root 密码忘记-恢复

    @Ubuntu root 密码忘记-恢复 2012-04-27 11:09:22 方法一: 如果用户具有sudo权限,那么直接可以运行如下命令: #sudo su root #passwd #更改密码 ...

  8. centos7 mariadb 设置root密码

    centos7 mariadb 设置root密码   修改root密码1.以root身份在终端登陆,必须2.输入 mysqladmin -u root -p password root后面的 root ...

  9. [转载]Ubuntu 14.04中root 密码忘记解决方法

      Ubuntu 14.04中root 密码忘记解决方法 方法一: 如果用户具有sudo权限,那么直接可以运行如下命令: #sudo su root #passwd #更改密码 或者直接运行sudo ...

随机推荐

  1. 【转】浅谈分布式服务协调技术 Zookeeper

    非常好介绍Zookeeper的文章, Google的三篇论文影响了很多很多人,也影响了很多很多系统.这三篇论文一直是分布式领域传阅的经典.根据MapReduce,于是我们有了Hadoop:根据GFS, ...

  2. python测试开发django-47.xadmin上传图片和文件

    前言 xadmin上传图片和上传文件功能 依赖环境 如果没安装Pillow的话,会有报错:practise.Upload.upload_image: (fields.E210) Cannot use ...

  3. C# ConcurrentStack实现

    我们通过C# Queue 和Stack的实现知道Stack是依靠数组实现的,那么ConcurrentStack的栈又是如何实现的了,然后它的线程安全又是怎么做到的了? 来看看其code吧 public ...

  4. ANTLR flex/bison

    https://stackoverflow.com/questions/29971097/how-to-create-ast-with-antlr4 这个很值得仔细看 https://github.c ...

  5. How to extract a complete list of extension types within a directory?

    Open the PowerShell Tool and Run the below command: Get-Childitem "D:\testfolder\" -Recurs ...

  6. asp.net core 2.1 post 无法提交参数?

    起 ,是微软二逼升级了.....不是说好了合并Controller 了吗?又倒回去了.................

  7. 编程调节Win7/Win8系统音量的一种方法

    不得不说, 自Win7(好像是吧), Windows的音量调节功能比以前更人性化了....      但编程接口却变得更加复杂了............. 还要用到IAudioEndpointVolu ...

  8. CountDownLatch、CyclicBarrier及Semaphore的用法示例

    一.参考blog https://www.cnblogs.com/dolphin0520/p/3920397.html 二.CountDownLatch 个人把它类比于一个持有计数的闸门,每到达这个闸 ...

  9. xmind指定32位jdk解决在64位系统上不能启动的问题

    在xmind.ini文件的第一行添加下面的内容: -vmF:\kfgj\Java32.1.6\jdk1.6.0_16\bin\javaw.exe (根据实际情况指定32位jdk的javaw.exe文件 ...

  10. Shell函数的7种用法介绍

    1. 在shell文件内部定义函数并引用: 复制代码代码如下: [~/shell/function]# cat factorial.sh #!/bin/bashfunction factorial{f ...