Ubuntu 23.04 MariaDB 10.11 データベースを作成する手順

環境
MariaDB 10.11.2
Ubuntu 23.04

操作方法
1.MariaDB に root ユーザーで接続します

# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 38
Server version: 10.11.2-MariaDB-1 Ubuntu 23.04

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)]>

2.[Unix_Socket] 認証権限を確認します

# show grants for root@localhost;
+-----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost |
+-----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO `root`@`localhost` IDENTIFIED VIA mysql_native_password USING 'invalid' OR unix_socket WITH GRANT OPTION |
| GRANT PROXY ON ''@'%' TO 'root'@'localhost' WITH GRANT OPTION |
+-----------------------------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.002 sec)

3. ユーザー情報一覧表示する

MariaDB [(none)]> select user,host,password from mysql.user;
+-------------+-----------+----------+
| User | Host | Password |
+-------------+-----------+----------+
| mariadb.sys | localhost | |
| root | localhost | invalid |
| mysql | localhost | invalid |
+-------------+-----------+----------+
3 rows in set (0.009 sec)

4. データベース一覧を表示する

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

5.テストデータベースを作成する

MariaDB [(none)]> create database arkgame_db;
Query OK, 1 row affected (0.002 sec)

6.テストデータベースにテストテーブル作成

MariaDB [(none)]> create table arkgame_db.test_table (id int, name varchar(50), address varchar(50), primary key (id));
Query OK, 0 rows affected (0.029 sec)

7.テストテーブルにデータ挿入

MariaDB [(none)]> insert into arkgame_db.test_table(id, name, address) values("001", "Ubuntu", "tokyo");
Query OK, 1 row affected (0.009 sec)

8.テストテーブル表示

MariaDB [(none)]> select * from arkgame_db.test_table;
+----+--------+---------+
| id | name | address |
+----+--------+---------+
| 1 | Ubuntu | tokyo |
+----+--------+---------+
1 row in set (0.003 sec)

9.データベースを削除します

MariaDB [(none)]> drop database arkgame_db;

MariaDB [(none)]> exit

 

Ubuntu 23.04

Posted by arkgame