LoginSignup
0
1

More than 5 years have passed since last update.

MySQLへのログインを簡単にする

Last updated at Posted at 2017-10-12

なんで前回こんな記事を書いたか?

VagrantでAmazon EC2を使う〜おまけ編
mysql_config_editorを使いたいから!MySQL5.6以上なんだよ!

表題の通り

いっつも忘れてググるからメモ。

$ mysql_config_editor set --login-path=user --host=[hostのエンドポイント] --user=[MySQLのユーザー名] --password

で、パスワードを入力しましょう。

ちなみにshellとかvagrantのprovisionに書く時は

# echo "MySQLのパスワード" | mysql_config_editor set --login-path=user --host=[hostのエンドポイント] --user=[MySQLのユーザー名] --password

これをしとくと、以下でMySQLにログインできるなりよ。

$ mysql --login-path=user

これでも長い。
ので、おもむろに以下

$ mkdir ~/bin
$ touch ~/bin/mysql_user
$ chmod 700 ~/bin/mysql_user

で、以下のように編集。

#!/bin/bash
mysql --login-path=user

そうすると、以下でログインできるなりよ

$ mysql_user

まぁ、パスワード平文で書いてもいいなら

#!/bin/bash
mysql -h [MySQLのエンドポイント] -u [MySQLのユーザー名] -p[パスワード]

でもいいんですけどね。

さらにさらにrailsだったら、database.yml書いておけば

$ rails dbconsole -p

で入れるんですけどね。

いじょー

by 株式会社Arrvis

0
1
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
0
1