Why not login to Qiita and try out its useful features?

We'll deliver articles that match you.

You can read useful information later.

5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

VSCodeでVagrantのMySQLを操作する

Posted at

はじめに

普段使っているVSCodeでSQL文を書いてその場で実行・確認できたらなーと思って、色々試したら何とかできたのでそれの _φ(・_・ です

好きなExtensionをいれる

など

SSHトンネルを手動で掘る

仮想環境内に用意したMySQLにアクセスするために、SSHトンネルを掘ります(ポートフォワーディング)。

# portやipはよしなに変更ください
$ ssh -N -L 3306:127.0.0.1:3306 vagrant@192.168.33.40

上手くつながると(応答がないように見えますが)プロセスを閉じるまでアクセスできるようになります。ターミナルを閉じても切れないようにバックグラウンドで実行するには -f オプションを指定します。

参考にさせていただいたサイト

Extensionで接続設定をする

あとは普通にMySQLのホスト・ポート・ユーザー名・パスワード・DBなどを指定し接続されれば成功です!!(もちろんVagrantは立ち上げておきます)

# 例
host: 127.0.0.1
port: 3306
username: root
password: 
database: app

終わりに

Sequel Proを使えば一発なんですが、やっぱり慣れているエディターでシンタックスハイライト・サジェスト・スニペット・フォーマットなど使えるのは気持ち良いですね...!

5
5
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

Qiita Conference 2025 will be held!: 4/23(wed) - 4/25(Fri)

Qiita Conference is the largest tech conference in Qiita!

Keynote Speaker

ymrl、Masanobu Naruse, Takeshi Kano, Junichi Ito, uhyo, Hiroshi Tokumaru, MinoDriven, Minorun, Hiroyuki Sakuraba, tenntenn, drken, konifar

View event details
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?