0
0

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 3 years have passed since last update.

実は簡単!?HerokuにアップロードしたCleraDB(MySQL)をCLIで接続する方法

Posted at

heroku上にアップロードしたCleraDB(MySQL)を接続する方法に凄く手間がかかったので、同じ境遇にいる人の助けになればなと思い、自分の備忘録も兼ねて書いていきます。

開発環境

  • windows10
mysql --version
mysql  Ver 8.0.22 for Win64 on x86_64 (MySQL Community Server - GPL)

以下のコマンドを打ち、データベースのユーザー名、パスワード、ホスト名、データベース名を取得します。

heroku config:get CLEARDB_DATABASE_URL

すると、このようにデータベースの情報が返ってくると思います。

「CLEARDB_DATABASE_URL: mysql://[ユーザー名]:[パスワード]@[ホスト名]/[データベース名]?reconnect=true」

この情報を元に、CLIで接続を行っていきます。

注意:MySQLのコマンドプロンプトではなく、windowsに搭載されているコマンドプロンプトを使ってください(Macならターミナル)

mysql -u[ユーザー名] -p[パスワード] -h[ホスト名]
//末尾にダブルセミコロン(;)は付けないでください。付けるとエラーが出ます。

すると、以下のような実行結果が返ってきます

~
Your MySQL connection id is id名
Server version: 5.5.62-log MySQL Community Server (GPL)
~

最後にデータベースを選択してください。(これめっちゃ忘れる)

use [データベース名];
//ここ、ダブルセミコロン(;)付ける

Database changed

後は好きにMySQLの構文を打ってください

select * from users;

んね?実は簡単♪

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?