爛泥:mysql修改本地主機串連

來源:互聯網
上載者:User

標籤:爛泥   mysql   修改   本地   主機   串連   

本文首發於爛泥行天下。

在mysql資料庫安裝完畢後,為了能遠端連線管理mysql資料庫。我們一般是在mysql伺服器上通過update命令來更新user表中的host記錄的。如下:

mysql -uroot -p123456

update user set host=‘%‘ where user=‘root‘;

FLUSH PRIVILEGES;

/etc/init.d/mysqld restart

650) this.width=650;" title="clip_image001" style="border-right-width:0px;background-image:none;border-bottom-width:0px;padding-top:0px;padding-left:0px;margin:0px;padding-right:0px;border-top-width:0px;" border="0" alt="clip_image001" src="http://img1.51cto.com/attachment/201411/5/526870_1415154077rL8u.png" width="564" height="391" />

這樣操作完畢之後,發現現在遠程主機是可以串連mysql資料庫了。但是在mysql資料庫伺服器上卻不能串連本地的mysql資料庫,如下:

650) this.width=650;" title="clip_image002" style="border-right-width:0px;background-image:none;border-bottom-width:0px;padding-top:0px;padding-left:0px;margin:0px;padding-right:0px;border-top-width:0px;" border="0" alt="clip_image002" src="http://img1.51cto.com/attachment/201411/5/526870_1415154080Sfo0.png" width="603" height="193" />

650) this.width=650;" title="clip_image003" style="border-right-width:0px;background-image:none;border-bottom-width:0px;padding-top:0px;padding-left:0px;margin:0px;padding-right:0px;border-top-width:0px;" border="0" alt="clip_image003" src="http://img1.51cto.com/attachment/201411/5/526870_1415154081ELKy.png" width="576" height="120" />

為什麼會出現這個情況呢?

是因為在mysql資料庫的user的host欄位中,已經明確拒絕本地登入。我們現在需要修改這個欄位,把該欄位中的不需要的相關記錄全部刪除。

先停止資料庫,然後使用mysqld_safe –skip-grant-tables &方式啟動資料庫。這種方式啟動資料庫,跳過了mysql資料庫的安全驗證。如下:

/etc/init.d/mysqld stop

mysqld_safe --skip-grant-tables &

mysql -uroot mysql

use mysql;

select host,user from user;

650) this.width=650;" title="clip_image004" style="border-right-width:0px;background-image:none;border-bottom-width:0px;padding-top:0px;padding-left:0px;margin:0px;padding-right:0px;border-top-width:0px;" border="0" alt="clip_image004" src="http://img1.51cto.com/attachment/201411/5/526870_1415154081xhQq.png" width="458" height="560" />

通過,我們可以看到目前localhost沒有對應的使用者。我們現在需要做的就是把,改記錄中不需要的全部刪除。只留下host為%的記錄。

刪除記錄,需要使用以下sql語句:

delete from user where host=‘127.0.0.1‘;

delete from user where host=‘ilanni‘;

delete from user where host=‘::1‘;

delete from user where host=‘localhost‘;

650) this.width=650;" title="clip_image005" style="border-right-width:0px;background-image:none;border-bottom-width:0px;padding-top:0px;padding-left:0px;margin:0px;padding-right:0px;border-top-width:0px;" border="0" alt="clip_image005" src="http://img1.51cto.com/attachment/201411/5/526870_1415154082p4a2.png" width="349" height="564" />

以上sql語句操作完畢後,我們再次重啟mysql資料庫。然後本地串連資料庫看下,如下:

650) this.width=650;" title="clip_image006" style="border-right-width:0px;background-image:none;border-bottom-width:0px;padding-top:0px;padding-left:0px;margin:0px;padding-right:0px;border-top-width:0px;" border="0" alt="clip_image006" src="http://img1.51cto.com/attachment/201411/5/526870_1415154082uddQ.png" width="551" height="309" />

通過,我們可以很明顯的看到。mysql資料庫伺服器已經可以串連mysql資料庫了。

以上是比較麻煩的做法,最簡單的做法是在遠端mysql管理軟體上直接刪除。因為現在遠程機器是可以登陸到mysql資料庫上的,再次我使用的Navicat Premium這款軟體。如下:

650) this.width=650;" title="clip_image007" style="border-right-width:0px;background-image:none;border-bottom-width:0px;padding-top:0px;padding-left:0px;margin:0px;padding-right:0px;border-top-width:0px;" border="0" alt="clip_image007" src="http://img1.51cto.com/attachment/201411/5/526870_1415154082nfGv.png" width="375" height="522" />

650) this.width=650;" title="clip_image008" style="border-right-width:0px;background-image:none;border-bottom-width:0px;padding-top:0px;padding-left:0px;padding-right:0px;border-top-width:0px;" border="0" alt="clip_image008" src="http://img1.51cto.com/attachment/201411/5/526870_1415154083LKWV.png" width="438" height="533" />

本文出自 “爛泥行天下” 部落格,請務必保留此出處http://ilanni.blog.51cto.com/526870/1571973

爛泥:mysql修改本地主機串連

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.