LoginSignup
3
3

More than 5 years have passed since last update.

CentOS6にMariaDB 10.1.13をtarball形式でインストール

Last updated at Posted at 2016-05-05

yumでインストールする手順はたくさんネットにありましたが、
tarball形式でインストールする方法があまりなかったので書きました。

環境構築につかうもの

MariaDBはMySQLから派生したオープンソースDBです。
今回は、CentOS 6.7にMariaDBをtarball形式でインストールします。
環境構築には以下を使いました。

もちろんVagrantは使わなくてもかまいません。
Vagrantの操作方法は割愛しています。

ユーザー作成

MariaDB用のユーザーを作成します。
ログイン不要なので、-Mと-sを指定しています。


$ su -
# groupadd mysql
# useradd mysql -M -g mysql -s /sbin/nologin

関連ライブラリのインストール

MariaDBのインストールに必要なライブラリをインストールします。

# yum -y update
# yum -y install libaio

ダウンロード

MariaDB公式サイト からMariaDBのダウンロードを行います。
ここでは、Linux64ビット用の、Linuxmariadb-10.1.13-linux-x86_64.tar.gz をダウンロードします。
以下手順では、wgetで取得しています。

# cd /usr/local/src
# wget -O mariadb-10.1.13-linux-x86_64.tgz https://downloads.mariadb.org/f/mariadb-10.1.13/bintar-linux-x86_64/mariadb-10.1.13-linux-x86_64.tar.gz/from/http%3A//ftp.yz.yamagata-u.ac.jp/pub/dbms/mariadb/?serve
# tar xvzf mariadb-10.1.13-linux-x86_64.tgz

インストール

/usr/local/mysqlにインストールしていきます。

# mv mariadb-10.1.13-linux-x86_64 /usr/local/mysql
# cd /usr/local/mysql
# scripts/mysql_install_db --user=mysql --data=/usr/local/mysql/data
# chown -R mysql data

■my.cnfの設定

デフォルトだと文字コードがlatin1なので、utf-8に変更します。

# cp /usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf

以下のように差分が出るように、/etc/my.cnfを編集します。

# diff -u /usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf 
--- /usr/local/mysql/support-files/my-medium.cnf        2016-03-24 11:14:55.000000000 +0100
+++ /etc/my.cnf 2016-05-05 11:07:46.273338265 +0200
@@ -21,6 +21,7 @@
 #password      = your_password
 port           = 3306
 socket         = /tmp/mysql.sock
+default-character-set = utf8

 # Here follows entries for some specific programs

@@ -37,6 +38,7 @@
 read_buffer_size = 256K
 read_rnd_buffer_size = 512K
 myisam_sort_buffer_size = 8M
+character-set-server = utf8

 # Point the following paths to different dedicated disks
 #tmpdir                = /tmp/
@@ -133,9 +135,11 @@
 [mysqldump]
 quick
 max_allowed_packet = 16M
+default-character-set = utf8

 [mysql]
 no-auto-rehash
+default-character-set = utf8
 # Remove the next comment character if you are not familiar with SQL
 #safe-updates

パスを通す

/usr/local/mysql/binにパスを通します。

/etc/profile.d/mysql.sh
#!/usr/bin/env bash
PATH=/usr/local/mysql/bin:$PATH
export PATH

起動

# /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data &
エンターを押して、
# ps aux | grep mysql | grep -v grep
[root@localhost mysql]# ps aux | grep mysql | grep -v grep                                                                             
root     13640  0.1  0.2 106196  1572 pts/0    S    15:32   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data
mysql    13760  1.2 10.9 676152 69376 pts/0    Sl   15:32   0:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/localhost.localdomain.err --pid-file=localhost.localdomain.pid --socket=/tmp/mysql.sock --port=3306

psコマンドでプロセスがあればOKです。

起動していない場合は、/usr/local/mysql/data/localhost.localdomain.errにエラーログが出ていますので、
確認をしましょう。
例えば、先ほど行ったインストール時に、scripts/mysql_install_dbを実行する際に、
--dataオプションをつけないと起動に失敗します。

ユーザー設定

mysql_secure_installationを実行すると、以下を順に行ってくれます。

  • ルートユーザーのパスワード設定
  • 不要なユーザー情報の削除
  • testDBの削除
# bin/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.

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.

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.

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!

起動スクリプトの設置

serviceコマンドで起動できるよう、起動スクリプトを設置します。

# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

OS起動時にMariaDBも起動するように、chkconfigに登録します。

# chkconfig --add mysql

文字コードの確認

実際にテーブルを作って、my.cnfの文字コードの設定が正しく行えたかを確認します。
まずは、devというデータベースと、satoというユーザーを作成します。

# mysql -uroot -p
パスワードを入力
MariaDB [(none)]> CREATE database dev;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON dev.* TO 'sato'@'localhost' IDENTIFIED BY 'パスワード';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> exit

# mysql -usato -p dev
パスワードを入力
MariaDB [dev]> create table users(userid int unsigned auto_increment primary key, name varchar(255) not null, comments text);
MariaDB [dev]> show create table users\G 
*************************** 1. row ***************************
Table: users
Create Table: CREATE TABLE `users` (
`userid` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`comments` text,
PRIMARY KEY (`userid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
1 row in set (0.00 sec)

CHARSETがutf8になっていればOKです。

以上で完了です。

3
3
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
3
3