mysql重置root密码

英文原文参考地址

1、检查版本
mysql –version
MySQL output

mysql Ver 14.14 Distrib 5.7.16, for Linux (x86_64) using EditLine wrapper
Or output like this for MariaDB:

MariaDB output
mysql Ver 15.1 Distrib 5.5.52-MariaDB, for Linux (x86_64) using readline 5.1

2、停止服务

MySQL with:
sudosystemctl stop mysql

MariaDB wtih:
sudosystemctl stop mariadb

3、开启安全模式
sudo mysqld_safe –skip-grant-tables –skip-networking &

4、使用root免密码登录
mysql -uroot

MySQL prompt
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
mysql>
MariaDB prompt
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
MariaDB [(none)]>

5、FLUSH PRIVILEGES;
非常关键,必须先执行这个,然后执行后面的语句才有效

6、修改密码
For MySQL 5.7.6 and newer as well as MariaDB 10.1.20 and newer, use the following command.

ALTER USER’root’@’localhost’IDENTIFIED BY ‘new_password’;

For MySQL 5.7.5 and older as well as MariaDB 10.1.20 and older, use:

SET PASSWORD FOR ‘root’@’localhost’=PASSWORD(‘new_password’);

或者
UPDATE mysql.user SET authentication_string =PASSWORD(‘new_password’)WHERE User =’root’AND Host =’localhost’;

7、重启
For MySQL, use:
sudokillcat/var/run/mysqld/mysqld.pid

For MariaDB, use:
sudokill/var/run/mariadb/mariadb.pid

Then, restart the service using systemctl.

For MySQL, use:
sudo systemctl start mysql

For MariaDB, use:
sudo systemctl start mariadb

wordpress忘记用户登录密码

参考地址 https://wordpress.org/documentation/article/reset-your-password/
1、登录数据库,找到users结尾的表,如wp_users
2、使用新密码生成MD5 hash 在线生成工具 https://www.miraclesalad.com/webtools/md5.php
或者通过下面的命令生成
python

import hashlib
m = hashlib.md5()
m.update(b’123′)
m.hexdigest()
‘202cb962ac59075b964b07152d234b70’

On Unix/Linux:
  1. Create a file called wp.txt, containing nothing but the new password.
  2. tr -d ‘\r\n’ < wp.txt | md5sum | tr -d ‘ -‘
  3. rm wp.txt
On Mac OS X:
  1. Create a file called wp.txt, containing nothing but the new password. Then enter either of the lines below
  2. md5 -q ./wp.txt; rm ./wp.txt (If you want the MD5 hash printed out.)
3. md5 -q ./wp.txt | pbcopy; rm ./wp.txt (If you want the MD5 hash copied to the clipboard.)
3 、修改表
update wp_users set user_pass='md5 hash' where id=1;--改成你的id
腾讯云图