LoginSignup
4
3

More than 5 years have passed since last update.

vagrant上のmariadbにローカルのマネージメントツールからアクセスするためにやったこと

Last updated at Posted at 2016-09-23

vagrant上のmysqlにローカルからアクセスするためにやったこと

プライベートでvagrantでdebianのサーバ上にmariadbを入れてmac上のDBマネージメントツールからログインしようとしたら、ちょっと準備が必要でしたのでメモっておきます。

環境

  • ローカル
    Mac
    Vagrant 1.8.3
    VB 4.3.38

  • 仮想環境 (192.168.33.10)
    Debian 8.4
    mariadb 10.1.14 (mysql 15.1)

接続方法

listenされてるportの確認

以下のコマンドで状況を確認します。

netstat -ant

mysqlで使われる3306のポートがlocalhost(127.0.0.1)縛りになっているのであるならば、これを解放します。

mysqlの設定を変更

/etc/mysql/my.cnf 内の以下の行をコメントアウトすれば全解放になります。

# bind-address = 127.0.0.1

bind-addressを付け足して、IPアドレスを明示的に指定するかどうかは好みで。

設定が終わったら以下のコマンドで再起動します。(mariadbの再起動コマンドです)

systemctl restart mariadb

netstatを実行してみて、0:::3306となってればOK。

mariadbに接続する

terminalからtelnetで疎通確認してみます。

$ telnet 192.168.33.10 3306
Connected to ***.***.com.
Escape character is '^]'.
GHost '192.168.33.1' is not allowed 
to connect to this MariaDB serverConnection 
closed by foreign host.

と怒られます。
mysql上で192.168.33.1から接続されてもいいように許可しましょう。
今回ユーザ名はroot、パスワードはpasswordとしてます。

mysql> grant all privileges 
on *.* to root@"192.168.33.1" 
identified by 'password' with grant option;

とすると、telnetでつながるかと思います。

あとはDBマネージメントツールにて、以下の接続情報を設定すれば接続できるかと思います。

user : root
password : password
host : 192.168.33.10
port : 3306
4
3
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3