20
13

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

MariaDBのテーブル定義を確認してみる

Posted at

環境

  • CentOS Linux release 7.4.1708 (Core)
  • MariaDb 5.5.56

MariaDBのテーブル定義を確認する

どうするんだっけ?てなるのでメモ。
MariaDBでデータベース、テーブル、カラムを確認した時の手順を残す。
ローカル接続で確認。
表示されるデータベース、テーブルはインストール時のデフォルト。

ルートで入る(パスワードなし)

ルートのパスワードを設定しているとエラーになる。

[root@localhost etc]# mysql -u root                                                 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)  

ルートで入る(パスワードあり)

Enter password: とDBのルートパスワードを聞かれる

[root@localhost etc]# mysql -u root -p                            
Enter password:                                                                     
Welcome to the MariaDB monitor.  Commands end with ; or \g.                         
Your MariaDB connection id is 27                                                    
Server version: 5.5.56-MariaDB MariaDB Server                                       
                                                                                    
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.                
                                                                                    
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.      

データベース一覧

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

データベースの選択

mysqlを選択。

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

mysqlのテーブル一覧

MariaDB [mysql]> show tables;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
... 省略 ...
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+
24 rows in set (0.00 sec)

userテーブルのカラム一覧

以下のコマンドで確認できた。

  • show columns from テーブル名
  • show fields from テーブル
  • describe テーブル名
  • explain テーブル名
MariaDB [mysql]> show columns from user;
+------------------------+-----------------------------------+------+-----+---------+-------+
| Field                  | Type                              | Null | Key | Default | Extra |
+------------------------+-----------------------------------+------+-----+---------+-------+
| Host                   | char(60)                          | NO   | PRI |         |       |
| User                   | char(16)                          | NO   | PRI |         |       |
... 省略 ...
| authentication_string  | text                              | NO   |     | NULL    |       |
+------------------------+-----------------------------------+------+-----+---------+-------+
42 rows in set (0.00 sec)

ユーザの一覧

MariaDB [(none)]> select user,host from mysql.user;
+------+-----------------------+
| user | host                  |
+------+-----------------------+
| root | 127.0.0.1             |
| root | ::1                   |
|      | localhost             |
| root | localhost             |
|      | localhost.localdomain |
| root | localhost.localdomain |
+------+-----------------------+
6 rows in set (0.00 sec)

SQLの実行

MariaDB [mysql]> select * from user;
+-----------------------+------+-------
... 省略

パスワードリセット

久々に入って使うとパスワード忘れてましったて時
参考: MariaDB(MySQL) パスワードリセット

20
13
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
20
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?