【mysql】linuxでバージョン確認から、sqlファイルの取り込みまで

ローカルの環境をサーバー側に反映させるために、やったメモです。

バージョンを確認

mysql --version
結果
mysql  Ver 15.1 Distrib 10.7.3-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

接続する(SQLが使える)

mysql -u root -p
結果
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 33
Server version: 10.7.3-MariaDB-1:10.7.3+maria~focal-log mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

データベースを表示(SQL)

show databases;
結果
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sampleapp_db       |
| sys                |
+--------------------+
5 rows in set (0.028 sec)

テーブルを表示(SQL)

show tables from sampleapp_db;
結果
+----------------------------+
| Tables_in_sampleapp_db     |
+----------------------------+
| auth_group                 |
| auth_group_permissions     |
| auth_permission            |
| auth_user                  |
| auth_user_groups           |
| auth_user_user_permissions |
| django_admin_log           |
| django_content_type        |
| django_migrations          |
| django_session             |
+----------------------------+
10 rows in set (0.026 sec)

カラムを表示(SQL)

show full columns from auth_user from sampleapp_db;
+--------------+--------------+--------------------+------+-----+---------+----------------+---------------------------------+---------+
| Field        | Type         | Collation          | Null | Key | Default | Extra          | Privileges
     | Comment |
+--------------+--------------+--------------------+------+-----+---------+----------------+---------------------------------+---------+
| id           | int(11)      | NULL               | NO   | PRI | NULL    | auto_increment | select,insert,update,references |         |
| password     | varchar(128) | utf8mb4_general_ci | NO   |     | NULL    |                | select,insert,update,references |         |
| last_login   | datetime(6)  | NULL               | YES  |     | NULL    |                | select,insert,update,references |         |
| is_superuser | tinyint(1)   | NULL               | NO   |     | NULL    |                | select,insert,update,references |         |
| username     | varchar(150) | utf8mb4_general_ci | NO   | UNI | NULL    |                | select,insert,update,references |         |
| first_name   | varchar(150) | utf8mb4_general_ci | NO   |     | NULL    |                | select,insert,update,references |         |
| last_name    | varchar(150) | utf8mb4_general_ci | NO   |     | NULL    |                | select,insert,update,references |         |
| email        | varchar(254) | utf8mb4_general_ci | NO   |     | NULL    |                | select,insert,update,references |         |
| is_staff     | tinyint(1)   | NULL               | NO   |     | NULL    |                | select,insert,update,references |         |
| is_active    | tinyint(1)   | NULL               | NO   |     | NULL    |                | select,insert,update,references |         |
| date_joined  | datetime(6)  | NULL               | NO   |     | NULL    |                | select,insert,update,references |         |
+--------------+--------------+--------------------+------+-----+---------+----------------+---------------------------------+---------+
11 rows in set (0.018 sec)

テーブル作成(SQL)

create databaes hoge_table
結果
Query OK, 1 row affected (0.014 sec)

使うデータベースを選択する(SQL)

use hoge_table
結果
MariaDB [(none)]>

Database changed
MariaDB [hoge_table]>

sqlファイルを取り込む (SQL)

source ./hoge.sql
結果
Query OK, 0 rows affected (0.000 sec)

終了する

exit
結果
Bye

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です