我在CentOS7上安装了MariaDB
因为我想安装Ruby on Rails5,所以我先安装了数据库。
我犹豫了一下是选择MySQL还是MariaDB,但考虑到我使用的是centOS7,所以选择了MariaDB。
我会记下来,以免忘记。
环境
操作系统:CentOS 7
从安装到启动的步骤
1. 安装MariaDB。
# インストール
$ yum install mariadb mariadb-server
# インストール済みパッケージ一覧からmariadb確認
$ rpm -qa | grep -i mariadb
---- 入ったもの ----
mariadb-libs-5.5.56-2.el7.x86_64
mariadb-5.5.56-2.el7.x86_64
mariadb-server-5.5.56-2.el7.x86_64
2. 在my.cnf中指定字符编码选项。
$ vi /etc/my.cnf
# [mysqld]の中に記述
[mysqld]
character-set-server=utf8
3. 启动 MariaDB
一边想着“service”命令真好用,一边使用systemctl启动。
$ systemctl start mariadb
被生气了
Job for mariadb.service failed because the control process exited with error code. See "systemctl status mariadb.service" and "journalctl -xe" for details.
我收到了无法启动的错误报告。
我尝试了指示中的[journalctl -xe]命令。
然后,我查看了[ERROR]部分。
[ERROR] /usr/libexec/mysqld: unknown variable 'aracter-set-server=utf8'
啊,刚刚追加的[角色…]的c不见了……。
再次编辑一次,重新开始。
因为没有人说什么,所以确认一下状态。
$ systemctl status mariadb
--- 結果 ---
Active: active (running) ...
这次终于能顺利启动了。
话虽如此,这种地方什么时候才能治好呢?
但是,就算发生错误,我现在已经能够正确地查明原因,或者说是真的能够认真阅读并理解文章了…嗯,应该是有进步的。
由于能够成功启动,因此需要将自动启动设置启用。
$ systemctl enable mariadb
4. MariaDB的初始设置
$ 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):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
# rootパスワード設定するか
Set root password? [Y/n] y
New password: パスワード入力
Re-enter new password: もう一度パスワード入力
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
# デフォルトで作成される匿名ユーザーは削除するか
Remove anonymous users? [Y/n] y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
# rootのリモートログインは無効にするか
Disallow root login remotely? [Y/n] y
... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
# デフォルトの[test]データベースは削除するか
Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
# 特権情報の更新するか
Reload privilege tables now? [Y/n] y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
尝试登录到MariaDB。
$ mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 5.5.56-MariaDB MariaDB Server
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
我成功登录了,完毕。
2018年5月5日补充
因为5.5版本已经不再是最新的,所以我在安装之后立即进行了更新。
我将centOS7中的MariaDB5.5版本升级到了v10.2。