目次
参考url
- https://dev.mysql.com/doc/refman/8.0/en/installing-source-distribution.html
- https://end0tknr.hateblo.jp/entry/20190602/1559470417
- https://noknow.info/it/os/install_mysql_from_source?lang=ja
依存package install
$ sudo yum install openssl-devel $ sudo yum install ncurses-devel $ sudo yum install libedit-devel $ sudo yum install boost-devel $ sudo yum install gcc-c++
$ sudo yum install centos-release-scl $ sudo yum install devtoolset-10 $ scl enable devtoolset-10 bash
$ wget https://github.com/Kitware/CMake/releases/download/v3.21.0/cmake-3.21.0.tar.gz $ tar -xvf cmake-3.21.0.tar.gz $ cd cmake-3.21.0 $ ./configure $ make $ make test $ sudo make install
mysql install
$ wget https://downloads.mysql.com/archives/get/p/23/file/mysql-boost-8.0.27.tar.gz $ tar -xvf mysql-boost-8.0.27.tar.gz $ cd mysql-8.0.27 $ mkdir build $ cd build $ /usr/local/bin/cmake .. \ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DENABLED_LOCAL_INFILE=true \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_EXTRA_CHARSETS=all \ -DWITH_BOOST=../boost \ -DWITH_SYSTEMD=ON \ -DWITH_ZLIB=system -DWITH_SSL=system \ -DWITH_EDITLINE=system $ make $ make test $ sudo make install
config mysql
$ sudo groupadd mysql $ sudo useradd -r -g mysql mysql
以下のmy.cnf は、以前の https://end0tknr.hateblo.jp/entry/20190602/1559470417 を 参考にしています。
$ sudo vi /etc/my.cnf # For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html [mysqld] max_allowed_packet = 32M innodb_log_file_size = 128MB # Remove leading # and set to the amount of RAM for the most important data # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. # innodb_buffer_pool_size = 128M # Remove leading # to turn on a very important data integrity option: logging # changes to the binary log between backups. # log_bin # These are commonly set, remove the # and set as required. # basedir = ..... # datadir = ..... # port = ..... # server_id = ..... # socket = ..... basedir = /usr/local/mysql datadir = /var/mysql_data skip-grant-tables default_password_lifetime=0 # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. # join_buffer_size = 128M # sort_buffer_size = 2M # read_rnd_buffer_size = 2M sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
以下の「mysqld --initialize --user=mysql」の際、 mysql root用パスワードが表示されますが、 今回の場合、my.cnf で skip-grant-tables を使用していますので PWなしで接続できます。
$ sudo mkdir /var/mysql_data $ sudo chown mysql:mysql /var/mysql_data $ sudo chmod 750 /var/mysql_data $ sudo /usr/local/mysql/bin/mysqld --initialize --user=mysql : A temporary password is generated for root@localhost: m0&kd0W0q,Ez $ sudo /usr/local/mysql/bin/mysql_ssl_rsa_setup
自動起動
$ sudo cp /home/end0tknr/tmp/mysql-8.0.27/build/scripts/mysqld.service \ /etc/systemd/system/ $ sudo systemctl enable mysqld.service $ sudo systemctl start mysqld.service
root パスワードの変更
step1 - skip-grant-tables で、パスワードなし接続を有効化
$ sudo vi /etc/my.cnf skip-grant-tables $ sudo systemctl stop mysqld.service $ sudo systemctl start mysqld.service
step2 - rootパスワードを null 化
$ /usr/local/mysql/bin/mysql -u root mysql> use mysql; mysql> UPDATE mysql.user SET authentication_string=null WHERE User='root';
step3 - skip-grant-tables で、パスワードなし接続を無効化
$ sudo vi /etc/my.cnf #skip-grant-tables $ sudo systemctl stop mysqld.service $ sudo systemctl start mysqld.service
step4 - rootパスワードを設定
$ /usr/local/mysql/bin/mysql -u root mysql> ALTER USER 'root'@'localhost' identified BY 'ないしょ';
先程、設定したパスワードで接続テスト
$ /usr/local/mysql/bin/mysql -u root -p
他ユーザやデータベースの作成
mysql> CREATE USER 'wordpress' IDENTIFIED WITH mysql_native_password BY 'wordpress'; mysql> CREATE DATABASE wordpress; mysql> GRANT ALL ON wordpress.* TO 'wordpress';