MariaDB 接続するDBを選択する

MariaDB 接続するDBを選択する

MariaDBで、接続するDBを選択する手順を記述してます。「use」に使用したい「DB」名を指定するとことで可能です。

環境

  • OS ubuntu20.04
  • MariaDB 10.6.5

手順

接続するDBを選択するには、「use」を使用します。

use DB名

「foo」という「DB」を指定してみます。

MariaDB [(none)]> use foo;

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

「DB」を選択しないと、「select」実行時などに以下のエラーが発生します。

MariaDB [(none)]> select * from tbl1;

ERROR 1046 (3D000): No database selected

接続しているDBを確認

接続中のDBを確認するには、以下のコマンドで確認可能です。

MariaDB [foo]> SELECT database();
+------------+
| database() |
+------------+
| foo        |
+------------+
1 row in set (0.001 sec)