Fedora 34 にMariaDB 10.5を使用する方法

2021年10月22日

MariaDBに接続する

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
[root@fedora ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 10.5.12-MariaDB MariaDB Server
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)]> select version();
+-----------------+
| version() |
+-----------------+
| 10.5.12-MariaDB |
+-----------------+
[root@fedora ~]# mysql Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 10 Server version: 10.5.12-MariaDB MariaDB Server 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)]> select version(); +-----------------+ | version() | +-----------------+ | 10.5.12-MariaDB | +-----------------+
[root@fedora ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 10.5.12-MariaDB MariaDB Server

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)]> select version();
+-----------------+
| version()       |
+-----------------+
| 10.5.12-MariaDB |
+-----------------+

1.ユーザー情報一覧表示

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
MariaDB [(none)]> select user,host,password from mysql.user;
+-------------+-----------+----------+
| User | Host | Password |
+-------------+-----------+----------+
| mariadb.sys | localhost | |
| root | localhost | invalid |
| mysql | localhost | invalid |
+-------------+-----------+----------+
MariaDB [(none)]> select user,host,password from mysql.user; +-------------+-----------+----------+ | User | Host | Password | +-------------+-----------+----------+ | mariadb.sys | localhost | | | root | localhost | invalid | | mysql | localhost | invalid | +-------------+-----------+----------+
MariaDB [(none)]> select user,host,password from mysql.user;
+-------------+-----------+----------+
| User        | Host      | Password |
+-------------+-----------+----------+
| mariadb.sys | localhost |          |
| root        | localhost | invalid  |
| mysql       | localhost | invalid  |
+-------------+-----------+----------+

2.データベース一覧表示

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
MariaDB [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | +--------------------+
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+

3.Unix_Socket 認証有効確認

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
MariaDB [(none)]> 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
MariaDB [(none)]> 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
MariaDB [(none)]> 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

4.データベース作成

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
MariaDB [(none)]> create database user_database;
MariaDB [(none)]> create database user_database;
MariaDB [(none)]> create database user_database;

5.テーブル作成

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
MariaDB [(none)]> create table user_database.user_tbl (uno int, username varchar(20), address varchar(35), primary key (uno));
MariaDB [(none)]> create table user_database.user_tbl (uno int, username varchar(20), address varchar(35), primary key (uno));
MariaDB [(none)]> create table user_database.user_tbl (uno int, username varchar(20), address varchar(35), primary key (uno));

6.テーブルにデータを挿入

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
MariaDB [(none)]> insert into user_database.user_tbl(uno, username, address) values("3004", "yamada", "tokyo");
MariaDB [(none)]> insert into user_database.user_tbl(uno, username, address) values("3005", "oosaki", "oosaka");
MariaDB [(none)]> insert into user_database.user_tbl(uno, username, address) values("3004", "yamada", "tokyo"); MariaDB [(none)]> insert into user_database.user_tbl(uno, username, address) values("3005", "oosaki", "oosaka");
MariaDB [(none)]> insert into user_database.user_tbl(uno, username, address) values("3004", "yamada", "tokyo");
MariaDB [(none)]> insert into user_database.user_tbl(uno, username, address) values("3005", "oosaki", "oosaka");

7.テーブルのデータ表示

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
MariaDB [(none)]> select * from user_database.user_tbl;
+------+----------+---------+
| uno | username | address |
+------+----------+---------+
| 3004 | yamada | tokyo |
| 3005 | oosaki | oosaka |
+------+----------+---------+
MariaDB [(none)]> select * from user_database.user_tbl; +------+----------+---------+ | uno | username | address | +------+----------+---------+ | 3004 | yamada | tokyo | | 3005 | oosaki | oosaka | +------+----------+---------+
MariaDB [(none)]> select * from user_database.user_tbl;
+------+----------+---------+
| uno  | username | address |
+------+----------+---------+
| 3004 | yamada   | tokyo   |
| 3005 | oosaki   | oosaka  |
+------+----------+---------+

8.データベース削除
MariaDB [(none)]> drop database user_database;

9.ログアウト
MariaDB [(none)]> exit
Bye

Fedora 34

Posted by arkgame