一、一般忘記密碼的解決辦法,需要重啟Mysql
1、skip-grant-tables
我們常用的方法是使用skip-grant-tables選項,mysqld server啟動之后并不使用權(quán)限系統(tǒng)(privilege system)。用戶不需要任何賬號、不受任何限制的訪問數(shù)據(jù)庫中所有數(shù)據(jù)。為了安全起見,通常加上 skip-networking ,mysqld不偵聽任何TCP/IP連接請求。操作過程如下,
1)修改my.cnf配置文件,在mysqld選項中添加skip-grant-tables和skip-networking。
2)再重啟mysqld server。
3)通過sql語句修改mysql.user表中存儲密碼。執(zhí)行flush privileges,重新啟用mysql權(quán)限系統(tǒng)。
復(fù)制代碼 代碼如下:
UPDATE mysql.USER SET Password=PASSWORD('newpwd')WHERE User='root';
FLUSH PRIVILEGES;
復(fù)制代碼 代碼如下:
UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root';
FLUSH PRIVILEGES;
復(fù)制代碼 代碼如下:
mysqld_safe --init-file=/home/me/mysql-init &
二、不重啟mysqld的方法
1、首先得有一個可以擁有修改權(quán)限的mysql數(shù)據(jù)庫賬號,當前的mysql實例賬號(較低權(quán)限的賬號,比如可以修改test數(shù)據(jù)庫)或者其他相同版本實例的賬號。把data/mysql目錄下面的user表相關(guān)的文件復(fù)制到data/test目錄下面。
復(fù)制代碼 代碼如下:
[root@localhost mysql]# cp mysql/user.* test/
[root@localhost mysql]# chown mysql.mysql test/user.*
復(fù)制代碼 代碼如下:
[root@localhost mysql]# mysql -utest -p12345
Welcome to the MySQL monitor. Commands end with ; or /g.
Your MySQL connection id is 17
Server version: 5.5.25a-log Source distribution
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '/h' for help. Type '/c' to clear the current input statement.
mysql> use test
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('yayun') where user='root';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 5 Changed: 0 Warnings: 0
mysql>
復(fù)制代碼 代碼如下:
mv mysql/user.MYD mysql/user.MYD.bak
mv mysql/user.MYI mysql/user.MYI.bak
cp test/user.MY* mysql/
chown mysql.mysql mysql/user.*
復(fù)制代碼 代碼如下:
[root@localhost mysql]# pgrep -n mysql
2184
[root@localhost mysql]#
[root@localhost mysql]# kill -SIGHUP 2184
復(fù)制代碼 代碼如下:
[root@localhost mysql]# mysql -uroot -pyayun
Welcome to the MySQL monitor. Commands end with ; or /g.
Your MySQL connection id is 20
Server version: 5.5.25a-log Source distribution
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '/h' for help. Type '/c' to clear the current input statement.
mysql>
新聞熱點
疑難解答
圖片精選