CentOS 6.8にMySQL 5.5.50をソースからインストール

今更、MySQL5.5のソースインストールの需要もないと思いますが、5.5で検証したいことがあったので自分用のメモで残しておきます。

スポンサードリンク

環境

CentOS6.8(最小構成、update済み)

 

必要なパッケージのインストール

# yum install wget
# yum install gcc-c++
# yum install cmake
# yum install ncurses-devel
# yum install bison

 

mysqlグループとユーザの作成

# groupadd mysql
# useradd -g mysql -s /sbin/nologin -d /usr/local/mysql mysql

mysqlにスイッチできないことを確認する

# su - mysql
This account is currently not available.

 

ソースファイルのダウンロード

# cd /usr/local/src
# wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.50.tar.gz

 

ソースファイル展開

# tar zxvf mysql-5.5.50.tar.gz

 

cmakeコマンド

# cd /usr/local/src/mysql-5.5.50

# cmake . \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DWITH_EXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_LIBWRAP=ON \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1

 

makeコマンド

# make

 

インストール

# make install

 

インストールディレクトリのオーナーとグループをmysqlにする

# chown -R mysql:mysql /usr/local/mysql

 

インストールディレクトリのパーミッションを変更

# chmod 755 /usr/local/mysql

 

起動スクリプトのコピー

# cp -p /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
# chown root:root /etc/init.d/mysql
# chmod 755 /etc/init.d/mysql

 

設定ファイル修正

basedir/datadirを変更しているのでmy.cnfを修正しておきます。

# vi /etc/my.cnf

[mysqld]
#datadir=/var/lib/mysql
#socket=/var/lib/mysql/mysql.sock
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

 

MySQLの初期化

# /usr/local/mysql/scripts/mysql_install_db \
--user=mysql \
--basedir=/usr/local/mysql/ \
--datadir=/usr/local/mysql/data/

 

MySQL起動確認

# /etc/init.d/mysql start

 

パスの登録

# export PATH=$PATH:/usr/local/mysql/bin

# vi /etc/profile
# (最終行に追加)
export PATH=$PATH:/usr/local/mysql/bin

# (即時反映)
. /etc/profile

 

MySQL接続確認

# mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.5.50 Source distribution

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

 

rootパスワードの設定

# mysqladmin -u root password
New password: (設定するパスワードを入力)
Confirm new password: (確認のため再度パスワードを入力)

パスワードなしでは接続できないことを確認する

# mysql -uroot
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

パスワードが反映されていることを確認する

# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.5.50 Source distribution

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

 

2016/08/07 追記

MySQLのセキュア設定

MySQLの初期化を実行するとmysql_secure_installationのメッセージが表示されてました。

#  /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
...(省略)...
Alternatively you can run:
/usr/local/mysql//bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

rootパスワードの設定はmysql_secure_installationで同時にやってしまう方がいいですね。

# /usr/local/mysql//bin/mysql_secure_installation




NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!


In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, 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 MySQL
root user without the proper authorisation.

You already have a root password set, so you can safely answer 'n'.

Change the root password? [Y/n] n <- rootパスワード設定済みだったので今回はno
 ... skipping.

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL 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 <- rootのリモートログイン禁止
 ... Success!

By default, MySQL 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 MySQL
installation should now be secure.

Thanks for using MySQL!

 

最新記事

 

参考
MySQL5.5 – CentOS6 にソースからインストール

スポンサードリンク