vagrant内のmysqlにworkbenchでアクセスする

sshを使ってやるのがいいと思います
vagrant内のmysqlは外からつながるようにしておいて

参考)mysqlに外からアクセスする

workbenchの設定はこんな感じ

workbench

Connection Method: Standard TCP/IP over SSH
SSH Hostnam : 127.0.0.1:2222
SSH username : vagrant
MySQL Hostn : 127.0.0.1
MySQL Server : 3306
Username : user

ユーザーとパスワードは環境に合わせてください

Workbenchでつなぐときに
known_hostsを消せ、とかエラーが出たら

$ ssh-keygen -R [127.0.0.1]:2222

で回避できます

mysqlに外からアクセスする

mysql入のサーバーへ外からmysqlにつないでみました
mysqlにログインしてユーザーを見てみます

$ mysql -u root -p
とかではいってまずは確認

mysql> select user, host from mysql.user;

+------------------+--------------------------+
| user             | host                     |
+------------------+--------------------------+
| root             | 127.0.0.1                |
| root             | ::1                      |
| root             | localhost                |
+------------------+--------------------------+

hostがつなぐとことができるものです
そとからつなげるユーザーを増やしてみます

mysql> grant all privileges on . to user@”%” identified by ‘password’ with grant option;

確認

mysql> select user, host from mysql.user;

+------------------+--------------------------+
| user             | host                     |
+------------------+--------------------------+
| user             | %                        |
| root             | 127.0.0.1                |
| root             | ::1                      |
| root             | localhost                |
+------------------+--------------------------+

これでuserというユーザーが外からつなげます

192.168.0.2のサーバーにつなぐとしたら
$ mysql -h 192.168.0.2 -u user -p
とコマンドをたたいてつながるか確認できます

UbuntuでApacheの実行ユーザーを調べる

Apacheが動いているときに簡単に見るには

$ ps aux | grep apache2

www-data 10153  0.0  0.5 276228  5828 ?        S    16:40   0:00 /usr/sbin/apache2 -k start
www-data 10154  0.0  0.5 276228  5828 ?        S    16:40   0:00 /usr/sbin/apache2 -k start
www-data 10155  0.0  0.5 276228  5828 ?        S    16:40   0:00 /usr/sbin/apache2 -k start
www-data 10156  0.0  0.5 276244  6072 ?        S    16:40   0:00 /usr/sbin/apache2 -k start
www-data 10157  0.0  0.6 276464  6740 ?        S    16:40   0:00 /usr/sbin/apache2 -k start
www-data 10260  0.0  0.5 276228  5828 ?        S    16:41   0:00 /usr/sbin/apache2 -k start

こんな感じで確認できます

sshでWARNING: POSSIBLE DNS SPOOFING DETECTED!エラー

sshでサーバーにつなごうとしたらエラーが..

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@       WARNING: POSSIBLE DNS SPOOFING DETECTED!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
The RSA host key for [sub.sample.jp]:10022 has changed,
and the key for the corresponding IP address [192.168.0.2]:10022
is unknown. This could either mean that
DNS SPOOFING is happening or the IP address for the host
and its host key have changed at the same time.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx.
Please contact your system administrator.
Add correct host key in /home/user/.ssh/known_hosts to get rid of this message.
Offending RSA key in /home/user/.ssh/known_hosts:9
  remove with: ssh-keygen -f "/home/user/.ssh/known_hosts" -R [sub.sample.jp]:10022
RSA host key for [sub.sample.jp]:10022 has changed and you have requested strict checking.
Host key verification failed.

接続先のIPが変わってたりすると起きるようです

$ ssh-keygen -R [sub.sample.jp]:10022

で直しました