1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

MariaDBでデータベースを作ってテーブルにデータを入れて取得してみた

Posted at

概要

今日もデータベースの勉強ということで、MariaDBで遊んでみました。
インストールして、データベースを作って、テーブルを作って、データを入れて、取得するところまでやってみました。
以下のページを参考にしました。
https://www.javadrive.jp/mariadb/

環境構築

以下のコマンドを実行しました。

$ sudo apt install mariadb-server

(インストール途中で確認あり。OKで通過。)

rootでログイン

以下のコマンドを実行しました。

$ sudo mariadb -u root -h localhost

ユーザーを作りました。create userを実行しました。

MariaDB [(none)]> create user 'user1'@'localhost' identified by '********';
Query OK, 0 rows affected (0.015 sec)

データベースを作りました。create databaseを実行しました。

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

user1に権限を与えました。grantを実行しました。

MariaDB [(none)]> grant all on mydb.* to 'user1'@'localhost';
Query OK, 0 rows affected (0.015 sec)

user1でログイン

以下のコマンドを実行しました。

$ mariadb -u user1 -p

データベースを切り替えました。useを実行しました。

MariaDB [(none)]> use mydb
Database changed

テーブルを作りました。create tableを実行しました。

MariaDB [mydb]> create table animal (id int, name varchar(10));
Query OK, 0 rows affected (0.145 sec)

データを入れました。insertを実行しました。

MariaDB [mydb]> insert into animal (id, name) values (11, 'monkey');
Query OK, 1 row affected (0.033 sec)

データを取得しました。selectを実行しました。

MariaDB [mydb]> select * from animal;
+------+--------+
| id   | name   |
+------+--------+
|   11 | monkey |
+------+--------+
1 row in set (0.000 sec)

今のところMySQLとほぼ同じですね。何かの役に立てばと。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?