centos7下忘記mysql5.7密碼


才裝完的mysql,轉眼密碼就忘記了,找了一圈的修改密碼方法,做下記錄!

  1. 編輯mysql配置文件。
[root@localhost ~]# vi /etc/my.cnf
  1. [mysqld]配置節下新增 skip-grant-tables
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

skip-grant-tables

# Disabling symbolic-links is recommended to prevent assorted security risks
"/etc/my.cnf" 29L, 979C written
  1. 保存配置文件后,重啟mysql服務。
[root@localhost ~]# systemctl restart mysqld.service
  1. 使用mysql命令登錄mysql數據庫。
[root@localhost ~]# mysql
  1. 使用下面語句修改root密碼,注意和之前版本的mysql語句不太一樣。
mysql>update mysql.user set authentication_string=password('新密碼') where user='root' ;
mysql>flush privileges ;
mysql>quit
  1. 編輯mysql配置文件,將之前添加的 skip-grant-tables去掉。
  2. 重啟mysql服務。
[root@localhost ~]# systemctl restart mysqld.service


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM