AL2023にMariaDBをインストールする
インストール
dnf -y install mariadb105 mariadb105-server systemctl enable mariadb systemctl start mariadb
mariadb105 がクライアント、mariadb105-server がサーバ、mariadb がサービス名
設定ファイル
[client] default-character-set = utf8mb4 [mysqld] default-storage-engine = InnoDB default_tmp_storage_engine = InnoDB character-set-server = utf8mb4 collation-server = utf8mb4_bin
ユーザー作成
CREATE USER 'testuser'@'%' IDENTIFIED BY 'hogehoge'; CREATE USER 'testuser'@'localhost' IDENTIFIED BY 'hogehoge'; CREATE DATABASE appdata; GRANT ALL ON appdata.* TO 'testuser'@'%'; GRANT ALL ON appdata.* TO 'testuser'@'localhost';
面倒だけど、ユーザは % と localhost で2つ作った上でデータベースごとに権限を与える。
外部からのアクセスが無ければ % の方はいらない。
ホストで制限するときなどはホスト名をちゃんと書く。
@'localhost' は省略可能。
GRANT ALL ON *.* TO 'testuser'@'%'; などとすると、管理DB(mysql)にも権限が与えられてよくない
そのた雑多なコマンド
-- ユーザー一覧 SELECT User, Host FROM mysql.user ORDER BY User, Host; -- 権限確認 SHOW GRANTS FOR 'testuser'@'%'; SHOW GRANTS FOR 'testuser'@'localhost'; -- ユーザー削除 DROP USER `testuser`@'%'; DROP USER `testuser`@'localhost';
-- DB一覧 SHOW DATABASES; SELECT * FROM information_schema.SCHEMATA; -- DB削除 DROP DATABASE appdata;