0
1

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.

MariaDB コマンド(随時追加)

Last updated at Posted at 2023-10-19

MariaDBを使っていくにあたってのコマンド備忘。
基本はMySQLと同じ。

データベース一覧表示

コマンド
MariaDB [(none)]> show databases;
結果
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+

上記結果はMariaDBインストール直後の状態。
以降DBを作成していくと増えていきます。

接続するデータベースの選択

使用するDatabaseを選択。

コマンド
MariaDB [(none)]> use mysql;
結果
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [mysql]>

入力待ちのMairaDB[]の[]内が選択したDB名に変わっていればOK

接続しているデータベースの確認

コマンド
MariaDB[mysql]> select database();
結果
+------------+
| database() |
+------------+
| mysql      |
+------------+
1 row in set (0.000 sec)

入力待ちのMariaDB[]の[]内に接続しているDBは表記されているので、コマンドライン上で使うことはほぼないかも。

データベース作成

コマンド
MariaDB[(none)]> create database DBNAME;

DBNAMEはもちろん任意

テーブル作成

コマンド
create table TABLENAME(COLUMN_NAME TYPE OPTION, ...);

TABLENAME → 作成したいテーブル名
COLUMN_NAME → カラム名
TYPE → データ型
OPTION → autocomplete、unique、primary key()等
必要カラム分後に続ける

登録テーブル確認

コマンド
MariaDB [mysql]> show databases;
結果
MariaDB [mysql]> show tables;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| column_stats              |
| columns_priv              |
| db                        |
            ・
            ・
            ・
| transaction_registry      |
| user                      |
+---------------------------+
31 rows in set (0.001 sec)

テーブル構成の確認

コマンド
MariaDB [xxx]> desc TABLENAME;
または
SHOW COLUMNS FROM TABLENAME;
または
SHOW FIELDS FROM TABLENAME;
結果
+-------------+-----------------------+------+-----+---------+-------+
| Field       | Type                  | Null | Key | Default | Extra |
+-------------+-----------------------+------+-----+---------+-------+
| no          | mediumint(8) unsigned | NO   | PRI | NULL    |       |
                                    ・
                                    ・
                                    ・
+-------------+-----------------------+------+-----+---------+-------+
x rows in set (0.003 sec)

いずれのコマンドを実行しても結果は同じです。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?