Ubuntu 18.04 に MariaDB のインストールを実施します。
MariaDBのインストール
インストールは以下で実施します。
1 2 3 |
$ sudo apt -y install mariadb-server |
次に設定ファイルを以下のように変更します。
1 2 3 4 5 6 7 8 |
$ sudo vi /etc/mysql/mariadb.conf.d/50-server.cnf -----------------------------変更 #collation-server = utf8mb4_general_ci collation-server = utf8mb4_bin ----------------------------- |
Collationを「utf8mb4_bin」に設定しました。
「utf8mb4_general_ci」だと大文字と小文字を区別してくれません。
Web系のアプリで一部セキュリティホールになる可能性があるので、大文字と小文字を区別してくれる「utf8mb4_bin」を利用しています。
★MySQLの文字コードとCollation
https://qiita.com/tfunato/items/e48ad0a37b8244a788f6
DBの初期設定
次にDBの初期設定を実施します。
1 2 3 |
$ sudo systemctl restart mariadb |
そして次にrootパスワードの設定など。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
$ mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): ERROR 1698 (28000): Access denied for user 'root'@'localhost' Enter current password for root (enter for none): Aborting! |
パスワードが空白で入らなくて中止となりました。
ちなみにコンソールでの接続もエラーになります。
1 2 3 4 5 |
$ mysql -u root -p Enter password: ERROR 1698 (28000): Access denied for user 'root'@'localhost' |
これはrootのパスワードが「unix_socket」を利用したログインとなっており、Unixユーザを利用してログインしようとしているためです。
★Ubunt 16.04でMariaDBをインストールするとパスワードが変
https://jyn.jp/ubuntu-16-04-mariadb-password-bug/
そこで、UNIXのrootユーザーになり状況を確認してみます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
$ sudo mysql -u root Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 36 Server version: 10.1.34-MariaDB-0ubuntu0.18.04.1 Ubuntu 18.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 [mysql]> SELECT Host,User,Password,plugin FROM user; +-----------+------+----------+-------------+ | Host | User | Password | plugin | +-----------+------+----------+-------------+ | localhost | root | | unix_socket | +-----------+------+----------+-------------+ 1 row in set (0.00 sec) |
こちらの設定が入っているのでrootユーザーはこのままにしておきます。
そこで、アプリ用のDBなどを作成し、ログインユーザーを作成します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
MariaDB [mysql]> CREATE DATABASE my_app \ -> DEFAULT CHARACTER SET utf8mb4 \ -> COLLATE utf8mb4_bin; Query OK, 1 row affected (0.00 sec) MariaDB [mysql]> MariaDB [mysql]> CREATE USER 'app_user'@'localhost' IDENTIFIED BY 'app_passwd'; Query OK, 0 rows affected (0.00 sec) MariaDB [mysql]> GRANT ALL ON my_app.* TO 'app_user'@'localhost'; Query OK, 0 rows affected (0.00 sec) |
必要な作業が実施できました。
アプリに必要な設定などできましたのでインストールと基本設定はこちらで完了します。
このブログは株式会社CoLabMixによる技術ブログです。
GCP、AWSなどでのインフラ構築・運用や、クローリング・分析・検索などを主体とした開発を行なっています。
Ruby on RailsやDjango、Pythonなどの開発依頼などお気軽にお声がけください。
開発パートナーを増やしたいという企業と積極的に繋がっていきたいです。
お問い合わせやご依頼・ご相談など