LoginSignup
2
4

More than 5 years have passed since last update.

CentOS 7 MySQL 5.7.21のソースファイルからのインストール

Last updated at Posted at 2018-03-06

動作確認環境

  • 仮想環境 VMware Workstation Player 14.1.1
  • OS Windows 10 Pro 64bit

仮想環境

  • OS CentOS 7.4 (1708) minimalインストール
  • メモリ 2GB
  • HDD 250GB

前提条件

  • gcc 7.3.0
  • cmake 3.11.0

最新バージョン確認

MySQL :: Download MySQL Community Server

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

yum -y install ncurses-devel zlib-devel

CentOS 7にはDBにMariaDBがインストールされているので、削除する。

yum -y remove mariadb-libs

ソースの取得

/usr/local/srcディレクトリに移動する。

cd /usr/local/src/

ソースファイルをダウンロードする。

wget http://ftp.jaist.ac.jp/pub/mysql/Downloads/MySQL-5.7/mysql-5.7.21.tar.gz

ダウンロードしたファイルを展開する。

tar zxvf mysql-5.7.21.tar.gz

インストール

展開したディレクトリに移動する。

cd mysql-5.7.21

Makefile の生成

cmake . -DMYSQL_UNIX_ADDR=/var/run/mysqld/mysqld.sock -DMYSQL_DATADIR=/var/lib/mysql -DDEFAULT_CHARSET==utf8mb4 -DDEFAULT_COLLATION=utf8mb4_unicode_ci -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/mysql

次のエラーが表示された場合、boost_1_59_0.tar.gzのダウンロードが自動でできなかったので、手動でする。

-- Downloading boost_1_59_0.tar.gz to /usr/local/mysql
-- [download 100% complete]
-- Download failed, error: 1;"Unsupported protocol"
CMake Error at cmake/boost.cmake:194 (MESSAGE):
  You can try downloading
  http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
  manually using curl/wget or a similar tool
Call Stack (most recent call first):
  CMakeLists.txt:507 (INCLUDE)

/usr/local/mysqlディレクトリ移動する。

cd /usr/local/mysql

ダウンロードする。

wget http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz

その後、cmakeのコマンドを実行する。(/usr/local/src/mysql-5.7.21ディレクトリに移動)
ビルド・インストールを行う。

make
make install

設定

設定ファイルmy.cnfが無いので作成する。

vi /etc/my.cnf
my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
default-character-set = utf8mb4

[mysql]
show-warnings
#safe-updates
prompt = '[\d] mysql> '

[mysqld]
# basic
datadir = /usr/local/mysql/data
tmpdir = /tmp
port = 3306
socket = /tmp/mysql.sock
character-set-server = utf8mb4
default-storage-engine = InnoDB
explicit_defaults_for_timestamp = 1
default_password_lifetime = 0
lower-case-table-names = 2
#secure-file-priv = /tmp
#sql_mode=NO_ENGINE_SUBSTITUTION

# max connections
max_connections = 64
# table_open_cache = (max_connections * tables used in one transaction) + alpha
table_open_cache = 800
# table_definition_cache = (all tables in mysql + max_connections) + alpha
table_definition_cache = 400
# open_files_limit = table_open_cache * 1.4
open_files_limit = 1120

# global buffer
key_buffer_size = 16M
query_cache_type = 0
# innodb_buffer_pool_size = RAM for Mysql * 0.7
innodb_buffer_pool_size = 256M

# thread buffer
read_buffer_size = 256K
read_rnd_buffer_size = 512K
join_buffer_size = 256K
sort_buffer_size = 512K

# InnoDB
innodb_file_per_table
innodb_autoextend_increment = 64
innodb_log_files_in_group = 2
innodb_log_file_size = 64M
innodb_log_buffer_size = 16M
innodb_flush_log_at_trx_commit = 1
innodb_flush_neighbors=0
#innodb_flush_method=O_DIRECT
innodb_thread_concurrency = 4
innodb_commit_concurrency = 4

# log
general_log = 1
general_log_file = /usr/local/var/mysql/general.log
slow_query_log = 1
slow_query_log_file ="/usr/local/var/mysql/slow.log
long_query_time = 5


[mysqldump]
#max_allowed_packet = 16M
quick
set-charset
single-transaction

my.cnfの内容を変更する。

datadir = /usr/local/mysql/data

[client]
default-character-set = utf8mb4

[mysqld]
character-set-server = utf8mb4
explicit_defaults_for_timestamp = 1
default_password_lifetime = 0

パーミッション等の変更

mysqlグループを追加する。

groupadd mysql

mysqlユーザを追加する。

useradd -g mysql -s /sbin/nologin -d /usr/local/mysql mysql
useradd: 警告: ホームディレクトリが既に存在します。
skel ディレクトリからのコピーは行いません。

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

su - mysql
This account is currently not available.

パーミッションの変更

chown -R mysql:mysql /usr/local/mysql/
chmod 755 /usr/local/mysql/

インストールしたディレクトリに移動する。

cd /usr/local/mysql

所有者・所有グループの変更をする。

chown -R mysql. .

環境変数 PATH の設定

/etc/bashrcに環境変数を追記する。

vi /etc/bashrc
PATH=$PATH:/usr/local/mysql/bin

変更内容を更新する。

source /etc/bashrc

初期設定

コマンドを実行し、初期設定を行う。

/usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --log-error-verbosity=3 --initialize-insecure

起動スクリプト

起動スクリプトをソースファイルを展開したディレクトリから/etc/rc.d/init.dにコピーする。

cp /usr/local/src/mysql-5.7.21/support-files/mysql.server /etc/rc.d/init.d/mysqld

パーミッションを変更する。

chmod a+x /etc/rc.d/init.d/mysqld

起動関係

  • 自動起動の設定
systemctl enable mysqld

以下のような表示をする。

mysqld.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig mysqld on
  • サーバの起動
systemctl start mysqld
  • ステータスの確認
systemctl status mysqld

以下のような表示をする。

● mysqld.service - LSB: start and stop MySQL
   Loaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled)
   Active: active (running) since 月 2018-03-12 16:57:19 JST; 2s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 18258 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/mysqld.service
           tq18266 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/lo...
           mq18771 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --d...

 3月 12 16:57:18 knut systemd[1]: Starting LSB: start and stop MySQL...
 3月 12 16:57:18 knut mysqld[18258]: Starting MySQL.Logging to '/usr/local...'.
 3月 12 16:57:19 knut mysqld[18258]: SUCCESS!
 3月 12 16:57:19 knut systemd[1]: Started LSB: start and stop MySQL.
Hint: Some lines were ellipsized, use -l to show in full.

バージョン表示

以下のコマンドでmysqlのバージョンを表示できる。

mysql --version

以下のような表示をする。

mysql  Ver 14.14 Distrib 5.7.21, for Linux (x86_64) using  EditLine wrapper

参考

apache,mysql,phpをソースからインストールしたメモ - 備忘録
MySQL 5.6 ソースからCentOS7にインストール


目次

2
4
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
2
4