KAGOYACLOUD/VPSでやったことメモ その3 MySQL インストール篇

estis2017/05/31 (水) 00:30 に投稿

https://dev.mysql.com/doc/refman/5.7/en/installing-source-distribution… を参考に行う。

# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.18.tar.gz
# tar xvf mysql-boost-5.7.18.tar.gz
# groupadd mysql
# useradd -r -g mysql -s /bin/false mysql
# cd mysql-5.7.18/
# mkdir bld
# cd bld
# cmake .
-bash: cmake: コマンドが見つかりません

cmake なかった。ので、インストール。

# yum install cmake

# cmake ..
-- Could not find (the correct version of) boost.
-- MySQL currently requires boost_1_59_0

CMake Error at cmake/boost.cmake:81 (MESSAGE):
  You can download it with -DDOWNLOAD_BOOST=1 -DWITH_BOOST=

  This CMake script will look for boost in .  If it is not there,
  it will download and unpack it (in that directory) for you.

You can download it with -DDOWNLOAD_BOOST=1 -DWITH_BOOST= とのことなので、それに従う。

  # cmake . -DDOWNLOAD_BOOST=1 -DWITH_BOOST=./boost
  
  -- Could NOT find Curses (missing:  CURSES_LIBRARY CURSES_INCLUDE_PATH) 
CMake Error at cmake/readline.cmake:64 (MESSAGE):
  Curses library not found.  Please install appropriate package,

      remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.

今度は、CURSES_LIBRARY がないと言われる。

# yum install ncurses-devel
# ls
CMakeCache.txt  CMakeFiles  VERSION.dep  extra  zlib

一旦、きれいに消してから、再度cmake実行。

# rm -rf *
# cmake . -DDOWNLOAD_BOOST=1 -DWITH_BOOST=./boost
# make
[ 35%] Building CXX object sql/CMakeFiles/sql.dir/item_geofunc.cc.o

cc1plus: out of memory allocating 2048 bytes after a total of 22519808 bytes
make[2]: *** [sql/CMakeFiles/sql.dir/item_geofunc.cc.o] エラー 1
make[1]: *** [sql/CMakeFiles/sql.dir/all] エラー 2
make: *** [all] エラー 2

メモリ少し足りないらしいので、Apache を止める。

# systemctl stop httpd

# make
[100%] Built target my_safe_process

# make install

インストール完了。 初期設定を行う。

# cd /usr/local/mysql
# chown -R mysql:mysql .
# bin/mysqld --initialize --user=mysql
2017-05-30T12:29:46.981582Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-05-30T12:29:47.364546Z 0 [Warning] InnoDB: New log files created, LSN=45790
2017-05-30T12:29:47.420931Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-05-30T12:29:47.483005Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: ab21627e-4533-11e7-ac5d-7c0cc6bf6ad5.
2017-05-30T12:29:47.483620Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2017-05-30T12:29:47.484373Z 1 [Note] A temporary password is generated for root@localhost: Mcor6w6Qj<3p

ここで、表示されるのが、初期パスワード。

# bin/mysql_ssl_rsa_setup --uid=mysql
Generating a 2048 bit RSA private key
...............................................................................................+++
..................................................+++
writing new private key to 'ca-key.pem'
-----
Generating a 2048 bit RSA private key
......................+++
.........................+++
writing new private key to 'server-key.pem'
-----
Generating a 2048 bit RSA private key
.............................+++
...........+++
writing new private key to 'client-key.pem'
-----

# chown -R root .

#  bin/mysqld_safe --user=mysql &
2017-05-30T12:35:30.118227Z mysqld_safe error: log-error set to '/var/log/mariadb/mariadb.log', however file don't exists. Create writable for user 'mysql'.

[1]+  終了 1                bin/mysqld_safe --user=mysql

ログが書けないので、落ちる。 ファイル名が気になるが、ひとまずそのままで設定。

# mkdir /var/log/mariadb
# touch /var/log/mariadb/mariadb.log
# chown mysql /var/log/mariadb/mariadb.log

#  bin/mysqld_safe --user=mysql &
[1] 29323
[root@v10953 mysql]# 2017-05-30T12:42:37.380761Z mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
2017-05-30T12:42:37.402021Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
2017-05-30T12:42:38.011661Z mysqld_safe mysqld from pid file /var/run/mariadb/mariadb.pid ended

[1]+  終了                  bin/mysqld_safe --user=mysql

起動しない。 pid file が原因らしい。

# tail /var/log/mariadb/mariadb.log
2017-05-30T12:42:37.973937Z 0 [Note] InnoDB: Buffer pool(s) load completed at 170530 21:42:37
2017-05-30T12:42:37.988686Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
2017-05-30T12:42:37.988803Z 0 [ERROR] SSL error: Unable to get private key from 'server-key.pem'
2017-05-30T12:42:37.988811Z 0 [Warning] Failed to set up SSL because of the following SSL library error: Unable to get private key
2017-05-30T12:42:37.989366Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
2017-05-30T12:42:37.989406Z 0 [Note] IPv6 is available.
2017-05-30T12:42:37.989417Z 0 [Note]   - '::' resolves to '::';
2017-05-30T12:42:37.989477Z 0 [Note] Server socket created on IP: '::'.
2017-05-30T12:42:37.989892Z 0 [ERROR] /usr/local/mysql/bin/mysqld: Can't create/write to file '/var/run/mariadb/mariadb.pid' (Errcode: 2 - No such file or directory)
2017-05-30T12:42:37.989910Z 0 [ERROR] Can't start server: can't create PID file: No such file or directory

ログを見ると、PIDファイルが作成できないためらしい。 仕方がないので、PID ファイルのパスを変更する。

# cat /etc/my.cnf | grep pid
pid-file=/var/run/mariadb/mariadb.pid
# vi /etc/my.cnf
# cat /etc/my.cnf | grep pid
pid-file=/var/lib/mysql/mariadb.pid
# killall mysqld
# bin/mysqld_safe --user=mysql &

# bin/mysql -p
Enter password: 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

起動したけど、接続できない。 mysqlコマンドが思っている場所が違う。 mysql コマンドの設定を変更する。

# cat /etc/my.cnf | grep sock
socket=/var/lib/mysql/mysql.sock
# vi /etc/my.cnf.d/mysql-clients.cnf
# cat /etc/my.cnf.d/mysql-clients.cnf | grep -B1 sock
[mysql]
socket=/var/lib/mysql/mysql.sock

# bin/mysql -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.18

Copyright (c) 2000, 2017, 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.
<.pre>

接続できた。

mysql> \s ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. 

けれど、何かしようとすると、まずパスワードを変更しろと言われるので、変更する。

mysql> alter user 'root'@'localhost' identified by 'MyPassword';
Query OK, 0 rows affected (0.00 sec)

MySQL関連のコマンドにパスを通す。

# vi .bash_profile 
PATH=$PATH:$HOME/bin
PATH=$PATH:/usr/local/mysql/bin:$HOME/bin

# . /root/bash_profile