mysqlコマンドのオプション。MySQL・MariaDBの両方で使用可能。

MySQL・MariaDBの両方で使用することができる「mysql」コマンドのオプションを紹介します。

mysqlコマンドはMySQL・MariaDBのCUIで、

SQL文だけでなく強力なメタコマンドもある非常に便利なコマンドになります。

DBはインストールされている前提ですので、

MariaDB・MySQLのインストール方法は下の記事を参考にしてください。

[st-card id=1208 label=\ name=\ bgcolor=\ color=\ readmore=on\]

目次

DBへの接続関連オプション

データベースに接続する時に使用するオプションを紹介します。

[table id=65 column_widths=40%|60% /]

補足ですが「-D」オプションを省略してもデータベース名を指定することが出来ます。

# -Dオプションを省略する
[root@test-server ~]# mysql testdb001 -u root -p -s
Enter password:
MariaDB [testdb001]>

# -Dオプションは指定する
[root@test-server ~]# mysql -D testdb001 -u root -p -s
Enter password:
MariaDB [testdb001]>

[st-card id=1493 label=\ name=\ bgcolor=\ color=\ readmore=on\]

表示・出力結果を変更するオプション

表示・出力結果を変更するオプションを以下になります。

[table id=66 column_widths=40%|60% /]

以下、表示・出力結果の例です。

# 表形式で表示デフォルト
MariaDB [testdb001]> select * from testdb001.tab001;
+------------+------------+
| col01 | col02 |
+------------+------------+
| 0000000001 | 0000000001 |
+------------+------------+
1 row in set (0.00 sec)

# 列名を非表示
MariaDB [testdb001]> select * from testdb001.tab001;
+------------+------------+
| 0000000001 | 0000000001 |
+------------+------------+
1 row in set (0.00 sec)

# 垂直表示
MariaDB [testdb001]> select * from testdb001.tab001;
*************************** 1. row ***************************
col01: 0000000001
col02: 0000000001

# HTML形式表示
MariaDB [testdb001]> select * from testdb001.tab001;
<TABLE BORDER=1><TR><TH>col01</TH><TH>col02</TH></TR><TR><TD>0000000001</TD><TD>0000000001</TD></TR></TABLE>MariaDB [testdb001]>

# XML形式表示
MariaDB [testdb001]> select * from testdb001.tab001;
<?xml version="1.0"?>

<resultset statement="select * from testdb001.tab001;" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<row>
<field name="col01">0000000001</field>
<field name="col02">0000000001</field>
</row>
</resultset>

実行を制御するオプション

[table id=67 column_widths=40%|60% /]

「-q」オプションを使用するとキャッシュせずに結果を1行づつ順に出力するため、

大量データを表示させる時に速度向上が見込めます。

ただし、ヒストリー機能が使えなくなるので注意してください。 「

-U」オプションを使用するとWHERE句を指定しないUPDATE、DELETE文が使用できなくなるので、

オペミスしてもデータが消えなくなります。

MariaDB & MySQL全機能バイブルposted with ヨメレバ

鈴木啓修/山田奈緒子 技術評論社 2015年01月

Amazon

Kindle

楽天ブックス

7net

honto

e-hon

紀伊國屋書店

よかったらシェアしてね!
  • URLをコピーしました!
目次