千家信息网

忘记mysql数据库密码怎么办?

发表于:2025-01-21 作者:千家信息网编辑
千家信息网最后更新 2025年01月21日,一、破解mysql数据库密码步骤1、修改mysql配置文件/etc/my.cnf[mysqld]port = 3306socket = /tmp/mysql.sockskip-
千家信息网最后更新 2025年01月21日忘记mysql数据库密码怎么办?

一、破解mysql数据库密码步骤

1、修改mysql配置文件/etc/my.cnf

[mysqld]port        = 3306socket      = /tmp/mysql.sockskip-external-lockingkey_buffer_size = 256Mmax_allowed_packet = 1Mtable_open_cache = 256sort_buffer_size = 1Mread_buffer_size = 1Mread_rnd_buffer_size = 4Mmyisam_sort_buffer_size = 64Mthread_cache_size = 8query_cache_size= 16M# Try number of CPU's*2 for thread_concurrencythread_concurrency = 2datadir = /mydata/dataskip-grant-tables  #加入此项


2、重新启动mysqld

# /etc/init.d/mysqld restart Stopping MySQL: [ OK ] Starting MySQL: [ OK ]


3.登录并修改MySQL的root密码

# /usr/bin/mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 to server version: 3.23.56 Type 'help;' or '\h' for help. Type '\c' to clear the buffer. 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 Password = password ( 'new-password' ) WHERE User = 'root' ; Query OK, 0 rows affected (0.00 sec) Rows matched: 2 Changed: 0 Warnings: 0 mysql> flush privileges ; Query OK, 0 rows affected (0.01 sec) mysql> quit Bye


5.将MySQL的登录设置修改回来

# vi /etc/my.cnf 将刚才在[mysqld]的段中加上的skip-grant-tables删除 保存并且退出vi。


6.重新启动mysqld

# /etc/init.d/mysqld restart Stopping MySQL: [ OK ] Starting MySQL: [ OK ]


图示:


修改如下:


重设密码:






0