[转]Mariadb的root密码忘记后的解决方法

环境背景: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

[[email protected] ~]# systemctl daemon-reload

三、重新启动mariadb服务并使用mysql联入

1

2

3

4

5

6

7

8

9

10

11

[[email protected] ~]# systemctl restart mariadb.service

[[email protected] ~]# 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

[[email protected] ~]# 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

时间: 2024-08-10 01:59:53

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

Mariadb的root密码忘记后的解决方法

环境背景:CentOS 7.2 一.编辑/usr/lib/systemd/system/mariadb.service 文件,在Service段中添加 [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 

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

MariaDB(Mysql) root密码忘记的解决办法 1.首先先关闭mariadb数据库的服务 # 关闭mariadb服务命令(mysql的话命令就是将mariadb换成mysql) [[email protected] ~]# systemctl stop mariadb # 通过进行查询服务或者通过端口查询服务还是否存在 [[email protected] ~]# ps aux|grep mariadb root       6852  0.0  0.0 112704   964 pt

MySQL的root密码忘记后重置方法

如果忘记了MySQL的root密码怎么办? 我们默认的情况下是没有给MySQL设置密码的,如下 默认的登录MySQL [[email protected] ~]# mysql -uroot Welcome to the MySQL monitor.  Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.1.40-log MySQL Community Server (GPL) Type 'help;

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

今天遇到了一个比较尴尬的事情,我centos 7.0的虚拟机密码忘了.....里面还有我配置好的环境呢.于是我就上网上搜索各种方法,最后经我验证下面这个方法比较靠谱: 使用光盘修复Centos: http://www.tuicool.com/articles/MJr2UzN 下面这个方法在重启之后发生了错误,可能我开启了syslinux,可以参考一下: centOs7 忘记root密码:http://blog.csdn.net/niu_hao/article/details/52882895 =

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

一.更改my.cnf配置文件 1.用命令编辑/etc/my.cnf配置文件,即:vim /etc/my.cnf 或者 vi /etc/my.cnf 2.在[mysqld]下添加skip-grant-tables,然后保存并退出 3.重启mysql服务:service mysqld restart 二.更改root用户名 1.重启以后,执行mysql命令进入mysql命令行 2.修改root用户密码 mysql> update mysql.user set authentication_strin

Mysql的Root密码忘记,查看或修改的解决方法

Mysql的Root密码忘记,查看或修改的解决方法:1.首先启动命令行2.在命令行运行:taskkill /f /im mysqld-nt.exe3.继续在命令行运行:mysqld-nt --skip-grant-tables4.新开一个命令行运行:mysql -u root (如果没有配置mysql的bin环境变量的话需要切换到bin目录下执行此语句) 如果不想改密码,只是想看原来的密码的话.可以在命令行执行这个语句 select host,user,password from mysql.u

Ubuntu 14.04中root 密码忘记解决方法[转载+17.04亲测可用]

Ubuntu 14.04中root 密码忘记解决方法 Ubuntu 14.04中root 密码忘记解决方法 方法一: 如果用户具有sudo权限,那么直接可以运行如下命令: #sudo su root #passwd #更改密码 或者直接运行sudo passwd root命令就可以直接更改root密码. 有关sudo su的区别: 1.共同点:都是root用户的权限: 2.不同点:su仅仅取得root权限,工作环境不变,还是在切换之前用户的工作环境:sudo是完全取得root的权限和root的工

centos7 mariadb 设置root密码

centos7 mariadb 设置root密码 修改root密码1.以root身份在终端登陆,必须2.输入 mysqladmin -u root -p password root后面的 root 是要设置的密码3.回车后出现 Enter password  输入就密码,如果没有,直接回车 创建用户//创建用户mysql> insert into mysql.user(Host,User,Password) values("localhost","admin"

Ubuntu root 密码忘记-恢复

Ubuntu root 密码忘记-恢复 2012-04-27 11:09:22 分类: LINUX 方法一: 如果用户具有sudo权限,那么直接可以运行如下命令: #sudo su root #passwd #更改密码 或者直接运行sudo passwd root命令就可以直接更改root密码. 有关sudo su的区别: 1.共同点:都是root用户的权限:   2.不同点:su仅仅取得root权限,工作环境不变,还是在切换之前用户的工作环境:sudo是完全取得root的权限和root的工作环