Help us understand the problem. What is going on with this article?

MySQLへの接続、SQL文の実行

今日は、MySQLへの接続SQL文の実行コマンドを紹介していきます!
ターミナルでコマンドを実行してみましょう^^

mysqlへ接続する

mysql -u root

ターミナルに以下のように表示されていれば、正常に接続できています

mysql>

データベース一覧を表示する

SHOW DATABASES;

*SQL文は必ず、終わりにセミコロンをつける必要があります!
もし;(セミコロン)を忘れて入力してしまった場合は、以下のようになります

mysql> SHOW DATABASES
         -> 

セミコロンを忘れて実行すると、SQLがまだ続くとみなされてしまいます
こうなった場合は、セミコロンのみを入力してエンターキーを押すと、正常に実行されます^^

実行後は、これまで作ってきたデータベースが一覧になって表示されます!

mysql> SHOW DATABASEs;
+-------------------------------------+
| Database                            |
+-------------------------------------+
| information_schema                  |
| DataBaseDesignSample_development    |
| DataBaseDesignSample_test           |
| chat-space_development              |
| chat-space_test                     |
| comment-box_development             |
| comment-box_test                    |
| drill_app_development               |
| drill_app_test                      |
| effective_model_sample_development  |
| effective_model_sample_test         |
| exception_sample_development        |
| exception_sample_test               |
| exp-exam-pictweet_development       |
| exp-exam-pictweet_test              |
| exp-html-exam_development           |
| exp-html-exam_test                  |
| freemarket_sample_68a_development   |
| freemarket_sample_68a_test          |
| git-app_development                 |
| git-app_test                        |
| mini_sns_development                |
| mini_sns_test                       |
| mysql                               |
| our_blog_development                |
| our_blog_test                       |
| ourblog_exam1_development           |
| ourblog_exam1_test                  |
| ourblog_exam3_development           |
| ourblog_exam3_test                  |
| performance_schema                  |
| pictweet4_development               |
| pictweet4_test                      |
| pictweet_development                |
| pictweet_exam1_development          |
| pictweet_exam1_test                 |
| pictweet_exam2_development          |
| pictweet_exem_retest_development    |
| pictweet_exem_retest_test           |
| pictweet_test                       |
| pictweet_workshop_exam_development  |
| pictweet_workshop_exam_test         |
| practice-exam-pictweet2_development |
| practice-exam-pictweet2_test        |
| reverse-app_development             |
| reverse-app_test                    |
| search_pictweet_development         |
| search_pictweet_test                |
| sql_curriculum_development          |
| sql_curriculum_test                 |
| sqltest                             |
| test                                |
| todo_app_development                |
| todo_app_test                       |
| view_drill_development              |
| view_drill_test                     |
+-------------------------------------+
56 rows in set (0.03 sec)

これでどんなデータベースがあるのか確認することができましたね!
次回は、データベースを作成するためのコマンドを紹介したいと思います^^

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした