用户工具

站点工具


zh:notes:centos_mysql_pwd

差别

这里会显示出您选择的修订版和当前版本之间的差别。

到此差别页面的链接

两侧同时换到之前的修订记录 前一修订版
后一修订版
前一修订版
zh:notes:centos_mysql_pwd [2022/10/22 20:34]
pzczxs [CentOS环境下MySQL忘记root密码解决方案]
zh:notes:centos_mysql_pwd [2023/03/23 07:42] (当前版本)
pzczxs [Start mysql Service]
行 1: 行 1:
 ====== Reset the Password of MySQL in the CentOS ====== ====== Reset the Password of MySQL in the CentOS ======
-===== 修改MySQL的登录设置 ​===== +===== Stop mysql Service ​===== 
-<​code>​ +<​code ​bash
-# vim /etc/my.cnf +> systemctl stop mysqld.service
 </​code>​ </​code>​
-在[mysqld]的段中加上一句:<​color red>​skip-grant-tables</​color>​ + 
-例如: ​ +===== Set the Environment Option ===== 
-<​code>​ +<​code ​bash
-[mysqld]  +> systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"
-datadir=/​var/​lib/​mysql  +
-socket=/​var/​lib/​mysql/​mysql.sock  +
-skip-grant-tables ​+
 </​code>​ </​code>​
-保存并且退出vi。 
  
-===== 重新启动mysqld ​===== +===== Login as root without Password ​===== 
-<​code>​ +<​code ​bash
-# service ​mysqld ​restart+> systemctl start mysqld.service 
 +> mysql -uroot
 </​code>​ </​code>​
  
-===== 登录并修改MySQL的root密码 ​===== +===== Update the Password ​===== 
-<​code>​ +<​code ​bash
-# mysql  +mysql> USE mysql 
-mysql> USE mysql  +mysql> ​ALTER USER "root"​@"​localhost"​ IDENTIFIED BY "​MyNewPassword"​
-mysql> ​UPDATE user SET Password = password ( '​new-password'​ ) WHERE User = 'root' ​;  +mysql> ​FLUSH PRIVILEGES;
-mysql> ​flush privileges ​+
 mysql> quit mysql> quit
 </​code>​ </​code>​
  
-===== 将MySQL的登录设置修改回来 ​=====  +===== Stop mysql Service and Unset the Environment Option ​===== 
-<​code>​ +<​code ​bash
-# vim /etc/my.cnf +> systemctl stop mysqld.service 
 +> systemctl unset-environment MYSQLD_OPTS 
 +</code> 
 + 
 +===== Start mysql Service ===== 
 +<code bash> 
 +> systemctl start mysqld.service
 </​code>​ </​code>​
-将刚才在[mysqld]的段中加上的skip-grant-tables删除 ​ 
-保存并且退出vim 
  
-===== 重新启动mysqld ​=====  +===== Login with New Password ​===== 
-<​code>​ +<​code ​bash
-# service mysqld restart ​+> mysql -uroot -p
 </​code>​ </​code>​
  
 ~~DISCUSSION:​closed~~ ~~DISCUSSION:​closed~~
  
zh/notes/centos_mysql_pwd.1666442068.txt.gz · 最后更改: 2022/10/22 20:34 由 pzczxs