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 1 year has passed since last update.

ターミナルからデータベースへ接続する方法

Posted at

データベースへ接続する

ターミナルからSSH接続した状態からスタート。
どこのディレクトリからでもいいので

$ mysql -u your_username -p

パスワードを聞かれるので、入力する。

データベースの特定のテーブルのレコードを確認する

以下のコマンドで、テータベース一覧を表示させる。

mysql> SHOW DATABASES;

以下のコマンドで、特定のデータベースに切り替える

mysql> USE データベース名;

以下のコマンドで、テーブル一覧を表示させる

mysql> SHOW TABLES;

以下のコマンドで、特定のテーブルのレコード全件を表示させる

mysql> SELECT * FROM テーブル名;

レコード件数が多いテーブルの場合、ターミナルだと全件は表示できなかったりする。そんな時は、以下で10件だけ取得することもできる。

mysql> SELECT * FROM テーブル名 LIMIT 10;

特定のカラムで昇順、降順に表示させる

昇順で上位10件取得

mysql> SELECT * FROM テーブル名 ORDER BY カラム名 ASC LIMIT 10;

降順で上位10件を取得

mysql> SELECT * FROM テーブル名 ORDER BY カラム名 DESC LIMIT 10;
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?