今天開發人員說開發用測試服務器mysql的root密碼忘記了。mysql
mysql root密碼重置這種事常常碰到今天順便作下筆記sql
環境 OS:CentOS 6.5vim
mysql:服務器
解決:socket
在mysql配置文件中添加skip-grant-tables[mysqld]下面ide
vim /etc/my.cnf
測試
[mysqld]ui
#port=7416spa
datadir=/var/lib/mysqlrest
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
lower_case_table_names=1
log-error=/usr/mysql.log
character-set-server=utf8
skip-name-resolve
skip-grant-tables
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
skip-grant-tables:在啓動mysql時不啓動g受權表grant-tables。
***不改配置文件能夠這樣啓動/usr/bin/mysqld_safe --skip-grant-tables &****
重啓 service mysqld restart
使用空密碼登陸mysql並重置密碼
UPDATE mysql.user SET Password = password ("123456") WHERE User = 'root';
退出mysql 改回原配置文件 重啓mysql便可