Vagrant上のMySQL(guest)にlocal(host)から接続する方法

どんな時に必要?

  • Vagrant上のDBにlocal(DBViewer or 0xDBEなど)から接続したい時

前提

  • Vagrantfileでportfoward済
    • host:xxxx => guest:3306

    Vagrantfile config.vm.network :forwarded_port, guest: 3306, host: xxxx

MySQLの設定

  • 待受アドレスの設定

    • /etc/mysql/my.conf or /etc/my.conf
    • サーバの持つ全てのIPアドレスを受けますという意味になる

    /etc/my.conf bind-address = 0.0.0.0

  • 権限付与 (ALL)

GRANT ALL PRIVILEGES ON *.* TO root@'%' IDENTIFIED BY 'password' WITH GRANT OPTION
  • MySQL再起動 (flushでも良いかもしれないです)
# service mysqld restart