LoginSignup
26
32

More than 5 years have passed since last update.

Vagrant上のMySQL(MariaDB)へMacから接続するまでの手順

Last updated at Posted at 2015-05-30

Vagrantの設定

※centos7を前提としています。

Vagrantのネットワークの設定



  1. Vagrantfileの変更
    
                $ vim Vagrantfile
                # config.vm.network :private_network, ip: "192.168.33.10"
                ↑ここのコメントアウトを削除


  2. Vagrantのリロード
    $ vagrant reload


  3. pingで接続確認(mac ターミナル)

    1922.168.33.10というipアドレスで接続できるようになっているはず.
    
                  $ ping 192.168.33.10
                  PING 192.168.33.10 (192.168.33.10): 56 data bytes
                  64 bytes from 192.168.33.10: icmp_seq=0 ttl=64 time=0.268 ms
                  64 bytes from 192.168.33.10: icmp_seq=1 ttl=64 time=0.624 ms
                  64 bytes from 192.168.33.10: icmp_seq=2 ttl=64 time=0.794 ms
                  ...


  4. sshで接続確認(mac ターミナル)
    $ ssh vagrant@'192.168.33.10'
                passwordを入力.デフォルトはvagrant





mysqlを永続的に公開する



  1. サービスの公開設定
    # firewall-cmd --permanent --add-service=mysql


  2. 永続設定の反映

    # firewall-cmd --reload


  3. Firewalldサービスのリロード

    # systemctl reload firewalld.service


  4. 設定内容の表示

    # firewall-cmd --permanent --list-all
      public (default, active)
      interfaces: enp0s3 enp0s8
      sources:
      services: dhcpv6-client mysql ssh
      ports:
      masquerade: no
      forward-ports:
      icmp-blocks:
      rich rules:
     

    mysqlが追加されていればOK.




MySQLの外部ホスト用アカウント追加


  1. vagrant上のmysqlにログイン

    $ mysql -u root -p
                           Enter password:


  2. ユーザーの確認

    mysql> select user, host from mysql.user;

    hostカラムがlocalhost127.0.0.1などローカルホストだけならば
    ローカルからの接続しかできない

  3. 外部ホストからの接続の許可とユーザーの追加

    mysql> grant all privileges on *.* to root@"192.168.33.10" identified by 'パスワード' with grant option;

    この例の場合、

    ホスト"192.168.33.10"のユーザー名がrootのユーザーへ、全データベース全テーブルに対するALL権限を付与している

  4. 外部ホスト(Macターミナル)から接続確認

    $ mysql -h 192.168.33.10 -u root -p
                  passwordは上記のidentified by 'パスワード'で指定したものを入力.







参考


http://linuxserver.jp/%E3%82%B5%E3%83%BC%E3%83%90%E6%A7%8B%E7%AF%89/db/mysql/%E5%A4%96%E9%83%A8%E6%8E%A5%E7%B6%9A%E8%A8%B1%E5%8F%AF%E8%A8%AD%E5%AE%9A.php


http://qiita.com/inouet/items/b36638adc2b5772db457


http://www.kakiro-web.com/linux/firewalld.html


26
32
0

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
26
32