Ubuntu 18.10でMySQL 8.0.13 コンパイル


# ソースコードダウンロード
https://dev.mysql.com/downloads/mysql/

Select Operating SystemでSource Codeを選択して
Generic Linux (Architecture Independent), Compressed TAR Archive Includes Boost Headers (mysql-boost-8.0.13.tar.gz)
をダウンロード

# コンパイル
以下の環境でコンパイルしてます．パスとかは適当に置き換えてください．

|  |  version|
|:-----------------|-----------------:|
| gcc              |             8.2.0|
| CMake            |            3.13.2|
| ncurses          |              6.1 |
|libssl-dev        | 1.1.1-1ubuntu2.1 amd64|


```
cd ~/work/
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-boost-8.0.13.tar.gz
tar zxvf mysql-boost-8.0.13.tar.gz
cd mysql-8.0.13

cmake . -DCMAKE_INSTALL_PREFIX=${HOME}/mysql_work \
-DWITH_BOOST=./boost \
-DMYSQL_DATADIR=${HOME}/mysql_work/data \
-DMYSQL_UNIX_ADDR=${HOME}/mysql_work/mysql.sock \
-DSYSCONFDIR=/etc \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_C_FLAGS_RELWITHDEBINFO="-O2 -g" \
-DCMAKE_CXX_FLAGS_RELWITHDEBINFO="-O2 -g" \
-DENABLED_LOCAL_INFILE=1 \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_ja_0900_as_cs

make
make install
```

# 初期化作業

my.cnfを/etc/にコピー

```my.cnf
[client]
default-character-set=utf8mb4
port=3306
socket=${HOME}/mysql_work/mysql.sock

[mysql]
default-character-set=utf8mb4

[mysqld]
#init_connect='SET collation_connection = utf8mb4_ja_0900_as_cs'
#init_connect='SET NAMES utf8mb4'
datadir=${HOME}/mysql_work/data
socket=${HOME}/mysql_work/mysql.sock
user=myuser

# database settings
port=3306
log-bin=${HOME}/mysql_work/log/mysql-bin
binlog_expire_logs_seconds=86400
log_timestamps=SYSTEM

default-storage-engine=InnoDB
max_connections=64
tmp_table_size=34M
thread_cache_size=8
sort_buffer_size=256K

sql_mode='TRADITIONAL,ONLY_FULL_GROUP_BY,NO_AUTO_VALUE_ON_ZERO'
secure-file-priv=''

default_authentication_plugin=mysql_native_password
character_set_server=utf8mb4
collation-server=utf8mb4_ja_0900_as_cs

skip-character-set-client-handshake

# *** MyISAM options ***
myisam_max_sort_file_size=512M
myisam_sort_buffer_size=1M
key_buffer_size=16K
read_buffer_size=8K
read_rnd_buffer_size=4K

# *** InnoDB options ***
innodb_open_files=1000
innodb_flush_log_at_trx_commit=1
innodb_log_buffer_size=2M
innodb_buffer_pool_size=2G
innodb_thread_concurrency=10
innodb_file_per_table

[mysqld_safe]
log-error=${HOME}/mysql_work/log/mysqld.log
pid-file=${HOME}/mysql_work/run/mysqld.pid
```

データディレクトリ初期化

```
mkdir ${HOME}/mysql_work/log
bin/mysqld --initialize --user=myuser --basedir=${HOME}/mysql_work --datadir=${HOME}/mysql_work/data
```
ここでrootの一時パスワードが作成されるのでメモっておく．

```
A temporary password is generated for root@localhost: ******
```
あとはシンボリックリンク作成したりパスを通したりして起動

```
sudo ln -s ${HOME}/mysql_work/bin/mysql /usr/local/bin/mysql
sudo ln -s ${HOME}/mysql_work/bin/mysqldump /usr/local/bin/mysqldump

sed -i -e "$ a PATH=\"\$PATH\":\/usr\/local\/mysql\/bin" ~/.bashrc
source ~/.bashrc

nohup ${HOME}/mysql_work/bin/mysqld_safe --datadir=${HOME}/mysql_work/data --socket=${HOME}/mysql_work/mysql.sock --pid-file=${HOME}/mysql_work/run/mysqld.pid --basedir=${HOME}/mysql_work --user=myuser &
```
先程メモったパスでrootでアクセスができる．適当なパスワードに変更をしておく(下記だと''にしているのでパス無しでアクセス出来るようになる)．

```
mysql -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED BY '';
FLUSH PRIVILEGES;
```
作業用ユーザ作成

```
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypass';
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'localhost' WITH GRANT OPTION;
```

defaults-extra-filesを作成しておくと便利

```${HOME}/mysql_work/defaults_extra.conf
[client]
user=myuser
password="mypass"

[mysqldump]
user=myuser
password="mypass"
```
アクセス方法

```
mysql --defaults-extra-file=${HOME}/mysql_work/defaults_extra.conf
```
シャットダウン

```
${HOME}/mysql_work/bin/mysqladmin -uroot shutdown
```