Mariadb的root密码忘记后的解决方法
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 trigger SELinux alarms, # per bug #547485 #在Server段中的ExecStart出添加如下 ExecStart=/usr/bin/mysqld_safe --basedir=/usr --skip-grant-tables --skip-networking
二、键入systemctl daemon-reload使其立即生效 |
[[email protected] ~]# systemctl daemon-reload
三、重新启动mariadb服务并使用mysql联入 |
[[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用户的密码 |
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文件中刚刚添加的那两行移除 |
ExecStart=/usr/bin/mysqld_safe --basedir=/usr ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID
六、启动mariadb服务,并使用新设置的密码连接 |
[[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
以上是关于Mariadb的root密码忘记后的解决方法的主要内容,如果未能解决你的问题,请参考以下文章
Centos7 之 MariaDB(Mysql) root密码忘记的解决办法