Vagrant 中的 mysql 外界訪問設置方法


在開啟了端口轉發的情況下,Vagrant 中的 mysql 在默認安裝情況下從外界也是無法訪問。

解決思路

需要兩步。此處假定 root 密碼為 123456

  1. 注釋掉/etc/mysql/my.cnf中的bind-address = 127.0.0.1。因為綁定到 127.0.0.1 時,mysql 只接受來自 localhost 的連接。
  2. 開放訪問權限。mysql -uroot -p123456 -e "create user 'root'@'10.0.2.2' identified by '123456'; grant all privileges on *.* to 'root'@'10.0.2.2' with grant option; flush privileges;"

實例

當 mysql 安裝好,並且 vagrant 的3306端口映射到宿主機的3306端口時,用 Navicat 連接報錯:Lost connection to MySQL server at 'reading initial communication packet', system error: 0 "Internal error/check (Not system error)"

sudo vim /etc/mysql/my.cnf 注釋掉 bind-address = 127.0.0.1

重啟服務(ubuntu)sudo service mysql restart

重新連接,報錯:Host '10.0.2.2' is not allowed to connect to this MySQL server

修改權限:

mysql -uroot -p123456 -e "create user 'root'@'10.0.2.2' identified by '123456'; grant all privileges on *.* to 'root'@'10.0.2.2' with grant option; flush privileges;"
  • 1

重啟服務(ubuntu)sudo service mysql restart

再次連接,成功。

http://blog.csdn.net/techfield/article/details/72810222


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM