Centos7 之 MariaDB(Mysql) root密码忘记的解决办法
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Centos7 之 MariaDB(Mysql) root密码忘记的解决办法,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2698字,纯文字阅读大概需要4分钟。
内容图文
1.首先先关闭mariadb数据库的服务
# 关闭mariadb服务命令(mysql的话命令就是将mariadb换成mysql)
[root@node ~]# systemctl stop mariadb
# 通过进行查询服务或者通过端口查询服务还是否存在
[root@node ~]# ps aux|grep mariadb
root 6852 0.0 0.0 112704 964 pts/2 S+ 23:19 0:00 grep --color=auto mariadb
[root@node ~]# netstat -lntup|grep 3306
2.修改配置
修改/etc/my.cnf文件,在[mysqld]下添加 skip-grant-tables , 再启动mysql
# 开启mariadb服务
[root@node ~]# systemctl start mariadb
# 查看服务已经开启
[root@node ~]# ps aux|grep mariadb
mysql 7104 1.1 5.6 972516 80672 ? Sl 23:22 0:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mysql/mysql.sock
root 7141 0.0 0.0 112704 964 pts/2 S+ 23:22 0:00 grep --color=auto mariadb
# 查看端口也正在使用
[root@node ~]# netstat -lntup|grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 7104/mysqld
3.进入数据库并更新密码
# 免密码可进入
root@node ~]# mysql -u root
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.60-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
# 更新密码
MariaDB [(none)]> update mysql.user set Password=password(‘123‘) where User=‘root‘;
Query OK, 1 row affected (0.01 sec)
Rows matched: 4 Changed: 1 Warnings: 0
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> quit;
Bye
4.还原需要密码的配置
# 重新修改为原来配置并重启服务
[root@node ~]# vi /etc/my.cnf
[root@node ~]# systemctl restart mariadb
# 可以看到没有密码现在无法进入
[root@node ~]# mysql -u root
ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO)
# 使用新密码进入mariadb数据库
[root@node ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.60-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
MariaDB [(none)]>
同理此问题也可以解决其他linux版本的mariadb(mysql)密码忘记问题
Centos7 之 MariaDB(Mysql) root密码忘记的解决办法
标签:emctl set roo pts cal error table grant emc
本文系统来源:https://www.cnblogs.com/hszstudypy/p/11518696.html
内容总结
以上是互联网集市为您收集整理的Centos7 之 MariaDB(Mysql) root密码忘记的解决办法全部内容,希望文章能够帮你解决Centos7 之 MariaDB(Mysql) root密码忘记的解决办法所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。