[转]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=simpleUser=mysqlGroup=mysqlUser=mysqlGroup=mysqlExecStartPre=/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 ~]# mysqlWelcome to the MariaDB monitor. Commands end with ; or \g.Your MariaDB connection id is 2Server version: 5.5.44-MariaDB MariaDB ServerCopyright (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: 0MariaDB [(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 -pEnter password: Welcome to the MariaDB monitor. Commands end with ; or \g.Your MariaDB connection id is 4Server version: 5.5.44-MariaDB MariaDB ServerCopyright (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)]> |
作者:horizonli
出处:http://www.cnblogs.com/horizonli/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
如果您认为文章还不错或者有所收获,您可以通过扫描下方的二维码进行随性打赏(¥1/¥2/¥5)以及点击左下角的【好文要顶】按钮以示支持,或者扫描关注即将写作的公众号二维码,因为这几种方式都是支持我继续写作,分享的最大动力!公众号将记录工作生活,技术内容,个性观点等内容,欢迎您的关注
出处:http://www.cnblogs.com/horizonli/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
|
![]() 支付宝(alipay) 二维码打赏 |
![]() 微信(wechat) 二维码打赏 JUST LI(**波) |
![]() 微信公众号: 木子李的菜田 |





浙公网安备 33010602011771号