“Linux下忘记mysql的root用户密码解决方法 忘记mysql密码 mysql修改密码方法”的版本间的差异
跳到导航
跳到搜索
(→解决过程) |
|||
(未显示同一用户的8个中间版本) | |||
第4行: | 第4行: | ||
=解决过程= | =解决过程= | ||
<pre> | <pre> | ||
− | 首先 要把mysqld 进程停止 kill or killall 你自己选择 | + | 注意 有时看 .mysql_history 就行了 |
+ | |||
+ | |||
+ | |||
+ | 首先 要把mysqld 进程停止 最后是用正常的停止服务方法 实在不行 kill or killall 你自己选择 | ||
接着 | 接着 | ||
第27行: | 第31行: | ||
#mysql5.7 | #mysql5.7 | ||
− | + | ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码'; | |
+ | # or | ||
update mysql.user set authentication_string=PASSWORD('123456#') where user='root'; | update mysql.user set authentication_string=PASSWORD('123456#') where user='root'; | ||
flush privileges; | flush privileges; | ||
第42行: | 第47行: | ||
mysql -uroot -p | mysql -uroot -p | ||
</pre> | </pre> | ||
+ | |||
+ | =mysql5.7忘记密码= | ||
+ | <pre> | ||
+ | docker mysql5.6 也一样 不过改了配置后 docker restart mysqlid 就行了 | ||
+ | |||
+ | vim /etc/my.cnf 或者 vi /etc/my.cnf.d/server.cnf | ||
+ | |||
+ | |||
+ | |||
+ | top your databases | ||
+ | |||
+ | systemctl stop mysqld | ||
+ | |||
+ | Modify /etc/my.cnf file add skip-grant-tables | ||
+ | |||
+ | vi /etc/my.cnf # or | ||
+ | vi /etc/mysql/mysql.conf.d/mysqld.cnf | ||
+ | [mysqld] | ||
+ | skip-grant-tables | ||
+ | |||
+ | |||
+ | mysql> use mysql; | ||
+ | Reading table information for completion of table and column names | ||
+ | You can turn off this feature to get a quicker startup with -A | ||
+ | |||
+ | Database changed | ||
+ | mysql> update user set authentication_string=PASSWORD("password") where User='root'; | ||
+ | Query OK, 1 row affected, 1 warning (0.00 sec) | ||
+ | Rows matched: 1 Changed: 1 Warnings: 1 | ||
+ | |||
+ | mysql> flush privileges; | ||
+ | Query OK, 0 rows affected (0.00 sec) | ||
+ | |||
+ | |||
+ | |||
+ | Restart MySQL database | ||
+ | |||
+ | service mysqld restart 新密码 | ||
+ | mysql -u root -p | ||
+ | |||
+ | </pre> | ||
+ | https://stackoverflow.com/questions/43013730/how-to-change-root-password-in-mysql5-7 | ||
+ | |||
+ | https://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html | ||
+ | |||
+ | [https://www.zllwsy.com/2021/05/26/Docker%E5%AE%B9%E5%99%A8%E4%B8%AD%E5%BF%98%E8%AE%B0Mysql%E5%AF%86%E7%A0%81/ docker容器中忘记Mysql密码] | ||
+ | |||
=mariadb= | =mariadb= | ||
<pre> | <pre> | ||
第59行: | 第111行: | ||
use mysql; | use mysql; | ||
+ | #选择一句就行了 | ||
update user set authentication_string=password('root'),plugin='mysql_native_password' where user='root'; | update user set authentication_string=password('root'),plugin='mysql_native_password' where user='root'; | ||
+ | ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码'; | ||
flush privileges; | flush privileges; | ||
第68行: | 第122行: | ||
skip-grant-tables=1 这句#注释掉 | skip-grant-tables=1 这句#注释掉 | ||
+ | |||
+ | |||
+ | |||
</pre> | </pre> | ||
第73行: | 第130行: | ||
=参考= | =参考= | ||
+ | |||
+ | |||
+ | [https://www.jianshu.com/p/c110efbfdbcc MariaDB 10.4+ 新版本默认初始密码的修改] | ||
[http://blog.linuxchina.net/?p=879 linux下忘记mysql的root用户密码解决方法–忘记mysql密码] | [http://blog.linuxchina.net/?p=879 linux下忘记mysql的root用户密码解决方法–忘记mysql密码] | ||
[[category:mysql]] | [[category:mysql]] |
2022年5月24日 (二) 02:35的最新版本
原因
不小心 把自己在公司的测试机上的mysql root 密码给忘记了,网上有很多方法,但这个是我试过的 包成功哦
解决过程
注意 有时看 .mysql_history 就行了 首先 要把mysqld 进程停止 最后是用正常的停止服务方法 实在不行 kill or killall 你自己选择 接着 用--skip-grant-tables参数启动mysqld # 其中/usr/local/mysql/bin是我的mysql安装目录 [root@localhost /]#/usr/local/mysql/bin/mysqld_safe --skip-grant-tables& 新办法 也可用于 mariadb my.cnf 在[mysqld] 下添加 skip-grant-tables=1 #不用密码进入mysql [root@localhost /]/usr/local/mysql/bin/mysql #切换到mysql database good mysql> use mysql; #将mysql root密码该为123456#了 #mysql5.7 ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码'; # or update mysql.user set authentication_string=PASSWORD('123456#') where user='root'; flush privileges; 特别提醒注意的一点是,新版的mysql数据库下的user表中已经没有Password字段了 #这个是mysql5.6之前 UPDATE user SET password=password('123456#') WHERE user='root'; FLUSH PRIVILEGES; killall mysqld #登录正常 mysql -uroot -p
mysql5.7忘记密码
docker mysql5.6 也一样 不过改了配置后 docker restart mysqlid 就行了 vim /etc/my.cnf 或者 vi /etc/my.cnf.d/server.cnf top your databases systemctl stop mysqld Modify /etc/my.cnf file add skip-grant-tables vi /etc/my.cnf # or vi /etc/mysql/mysql.conf.d/mysqld.cnf [mysqld] skip-grant-tables mysql> use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> update user set authentication_string=PASSWORD("password") where User='root'; Query OK, 1 row affected, 1 warning (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 1 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) Restart MySQL database service mysqld restart 新密码 mysql -u root -p
https://stackoverflow.com/questions/43013730/how-to-change-root-password-in-mysql5-7
https://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html
mariadb
sudo /etc/init.d/mysql stop Stopping mysql (via systemctl): mysql.service. evan@myxps:~/python/jumpserver$ sudo vim /etc/mysql/mariadb.conf.d/50-server.cnf skip-grant-tables=1 mysql -uroot 无密码登录 use mysql; #选择一句就行了 update user set authentication_string=password('root'),plugin='mysql_native_password' where user='root'; ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码'; flush privileges; vim /etc/mysql/mariadb.conf.d/50-server.cnf 将 skip-grant-tables=1 这句#注释掉
https://www.cnblogs.com/messhair/p/11782850.html