MySQL數(shù)據(jù)庫(kù)用戶權(quán)限表丟失的解決方案
在安裝軟件時(shí),需要用到Mysql數(shù)據(jù)庫(kù),要在里面建一個(gè)數(shù)據(jù)庫(kù),及相應(yīng)的用戶,執(zhí)行建庫(kù)腳本,很順利,數(shù)據(jù)庫(kù)成功建好,但在執(zhí)行用戶授權(quán)時(shí)錯(cuò)誤就產(chǎn)生了:
- createdatabasecactidb;
- grantalloncactidb.*toroot@localhost;
- grantalloncactidb.*tocactiuser;
本來(lái)這是沒什么的,但我之前已經(jīng)把root@localhost這個(gè)用戶給刪除了,我只留下了用戶名為root,host是%的用戶,而我平常的操作為了方便都只是用root在本機(jī)登錄的,我的mysql也只監(jiān)聽127.0.0.1這個(gè)地址,結(jié)果一執(zhí)行g(shù)rantalloncactidb.*toroot@localhost;這個(gè)命令立即完蛋了,我在本機(jī)用root登錄就只能是root@localhost這個(gè)用戶的權(quán)限,而不是一平常用的root@%這個(gè)用戶,但root@localhost基本就是沒有權(quán)限,按照Mysql的授權(quán)機(jī)制,我只有在其它主機(jī)登錄才可使用root@%這個(gè)用戶,而我根本就不可能從其它地址登錄,這下把我給急壞了。由于嚴(yán)格的防火墻策略,我是不可能開放mysql的端口的。后來(lái)在網(wǎng)上找了相關(guān)資料,用以下方法解決了這個(gè)問(wèn)題:
1、關(guān)閉mysql服務(wù):servicemysqldstop。
2、./mysqld_safe--skip-grant-tables重新啟動(dòng)mysql。
3、重新使用root登錄,此時(shí)不需要密碼。
4、登錄后刪除root@local這個(gè)用戶。
5、用ps查到mysqld進(jìn)程,并用kill中止mysql進(jìn)程。
6、重新啟動(dòng)mysql進(jìn)程:servicemysqldstart。
7、當(dāng)然使用這個(gè)方法也可重置root密碼:setpasswordforroot=password(yourpass');
8、或者也可以重置root用戶權(quán)限。
- updatedbsetSelect_priv='Y'whereuser='root';
- updatedbsetInsert_priv='Y'whereuser='root';
- updatedbsetUpdate_priv='Y'whereuser='root';
- updatedbsetDelete_priv='Y'whereuser='root';
- updatedbsetCreate_priv='Y'whereuser='root';
- updatedbsetDrop_priv='Y'whereuser='root';
- updatedbsetReferences_priv='Y'whereuser='root';
- updatedbsetGrant_priv='Y'whereuser='root';
- updatedbsetIndex_priv='Y'whereuser='root';
- updatedbsetAlter_priv='Y'whereuser='root';
- updatedbsetCreate_tmp_table_priv='Y'whereuser='root';
- updatedbsetLock_tables_priv='Y'whereuser='root';
- updatedbsetCreate_view_priv='Y'whereuser='root';
- updatedbsetGrant_priv='Y'whereuser='root';
- updatedbsetShow_view_priv='Y'whereuser='root';
- updatedbsetCreate_routine_priv='Y'whereuser='root';
- updatedbsetAlter_routine_priv='Y'whereuser='root';
- updatedbsetExecute_priv='Y'whereuser='root';
再把mysql.user表里root用戶的所有字段都置為'Y'。
注意:使用--skip-grant-tables啟動(dòng)mysql時(shí)不可使用grant命令的,所以只有我們手工來(lái)設(shè)置權(quán)限表了。
關(guān)于MySQL權(quán)限表的問(wèn)題就介紹到這里,如果大家想了解更多關(guān)于MySQL數(shù)據(jù)庫(kù)的知識(shí),不妨到這里看一下:http://database.51cto.com/mysql/,一定會(huì)讓您滿意的哦!
【編輯推薦】