环境背景: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. c++ try catch 问题

    以前都是用try{} catch(…){}来捕获C++中一些意想不到的异常, 今天看了Winhack的帖子才知道,这种方法在VC中其实是靠不住的.例如下面的代码: 以前都是用try{} catch(… ...

  2. 动态ip、静态ip、pppoe拨号的区别

    pppoe拨号 pppoe拨号上网,又叫做ADSL拨号上网.宽带拨号上网.指现在有很多我的E家用户,送的无线猫,阉割了PPPOE拨号功能,必须要从电脑上拨号才能上网.还有大街上的WIFI热点也很多,如 ...

  3. 针对UDP丢包问题,进行系统层面和程序层面调优

    转自:https://blog.csdn.net/xingzheouc/article/details/49946191 1. UDP概念 用户数据报协议(英语:User Datagram Proto ...

  4. 推荐10本C#编程的最佳书籍

    C#和.NET非常受全球开发人员的追捧和热爱.书籍是人类进步的阶梯.想要学习C# ?这里有10本学习C#编程的最好书籍在等着你哦. 1.<C# 5.0 in a Nutshell>:权威的 ...

  5. Windows 7用U盘安装CentOS 7

    已经有Windows 7,准备再安装一个CentOS 7. 1. 划分磁盘空间 从磁盘上划分安装CentOS 7的安装空间.如果有多个硬盘的话,一定要在主硬盘上划分2G的空间(其实1G就够了)作为bo ...

  6. 使用PostgreSQL存储时序数据

    操作系统 :CentOS7.3.1611_x64 PostgreSQL版本 :9.6 问题描述 在InfluxDB中存储时序数据时,当tag值和时间戳都相同时会执行覆盖操作.在PostgreSQL中能 ...

  7. mysql如何处理亿级数据,第一个阶段——优化SQL语句

    1.应尽量避免在 where 子句中使用!=或<>操作符,否则将引擎放弃使用索引而进行全表扫描. 2.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉 ...

  8. 【翻译自mos文章】在10g中,当发生ORA-00020时,sqlplus登陆会报“connected to an idle instance”

    在10g中.当发生ORA-00020时,sqlplus登陆会报"connected to an idle instance" 来源于: Sqlplus Logon Reports ...

  9. 【转】苹果App Store审核指南中文翻译(更新)

    (注:<苹果应用商店审核指南>中文翻译最近一次更新为2013-03-04,文中红色部分是相对于2013-03-04版本的新增内容,绿色部分代表更改的内容,蓝色表示苹果相关官方文档的链接.) ...

  10. 【Android】解析Paint类中MaskFilter的使用

    目录结构: contents structure [+] EmbossMaskFilter BlurMaskFilter MaskFilter可以用来指定画笔的边缘效果.如果引用开启硬件加速的话,那么 ...