1.依賴包安裝
yum install gdb gcc gcc-c++ ncurses-devel cmake libaio bison zlib-devel openssl openssl-devel patch
2.下載mysql源碼包和boost庫
- 下載最新mysql源碼
https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-boost-5.7.18.tar.gz
- 下載boost庫宦棺,版本 boost_1_59_0
http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.bz2
mysql-8.0需要boost_1_63_0版本
3.上傳并解壓
上傳并解壓安裝包:
[root@localhost MySQL]# tar -xzvf mysql-boost-5.7.18.tar.gz
[root@localhost MySQL]# tar -xzvf boost_1_59_0.tar.bz2
4 建立mysql用戶和組塔橡,建立相關(guān)目錄
/usr/sbin/groupadd mysql
/usr/sbin/useradd mysql -g mysql -d /home/mysql -s /sbin/nologin
mkdir /home/mysql/data/3306/data
mkdir /home/mysql/data/3306/log
mkdir /home/mysql/data/3306/tmp
mkdir /home/mysql/data/3306/binlog
三實例部署的話添谊,可以同時創(chuàng)建以下目錄
mkdir /home/mysql/data/3307/data
mkdir /home/mysql/data/3307/log
mkdir /home/mysql/data/3307/tmp
mkdir /home/mysql/data/3307/binlog
mkdir /home/mysql/data/3308/data
mkdir /home/mysql/data/3308/log
mkdir /home/mysql/data/3308/tmp
mkdir /home/mysql/data/3308/binlog
創(chuàng)建mysql安裝目錄
mkdir /usr/local/mysql
chown -R mysql.mysql /usr/local/mysql
chown -R mysql.mysql /home/mysql
5 編譯MySQL源碼&安裝mysql
生成makefile文件
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/home/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_EDITLINE=bundled \
-DMYSQL_UNIX_ADDR=/home/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DWITH_DEBUG=0 \
-DDOWNLOAD_BOOST=1 -DWITH_BOOST=/xxx/xxx/boost_1_59_0 -DDOWNLOAD_BOOST_TIMEOUT=60000
**如果日后需要調(diào)試mysql源碼仁锯,在cmake時候設(shè)置 -DWITH_DEBUG=1吃环,即編譯為帶調(diào)試信息的mysql目標(biāo)文件 **
編譯
make
根據(jù)機器配置等待一段時間计露,看到100%字樣啤挎,則說明編譯成功
安裝到 /usr/local/mysql 目錄下
make install
6.配置mysql環(huán)境變量
在/etc/profile中添加/usr/local/mysql/bin到PATH變量中
PATH=/usr/local/mysql/bin:$PATH
執(zhí)行source /etc/profile 生效
7.初始化mysql數(shù)據(jù)庫
初始化data文件
mysqld --defaults-file=/home/mysql/data/3306/my.cnf --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/home/mysql/data/3306/data
切換到mysql用戶
su - mysql
生成ssl所需文件
mysql_ssl_rsa_setup --user=mysql --basedir=/usr/local/mysql --datadir=/home/mysql/data/3306/data
啟動mysql
mysqld --defaults-file=/home/mysql/data/3306/my.cnf --user=mysql
先通過unix socket修改mysql root用戶密碼
mysql -uroot -p -S /home/mysql/data/3306/mysql.sock
UPDATE mysql.user SET authentication_string = PASSWORD('mysql') WHERE USER LIKE '%root%';
grant all privileges on *.* to 'root'@'%' identified by 'mysql' with grant option;
flush privileges;
驗證通過tcp/ip協(xié)議登陸mysql
mysql -h127.0.0.1 -uroot -p -P3306
8.配置數(shù)據(jù)庫配置文件
cd /usr/local/mysql/
cp support-files/my-default.cnf /etc/my.cnf
>/etc/my.cnf
vi /etc/my.cnf
[client]
socket=/home/mysql/mysql.sock
[mysqld]
symbolic-links=0
server_id = 120
default_storage_engine = Innodb
user = mysql
port = 3306
basedir = /usr/local/mysq
datadir = /home/mysql/data
tmpdir = /home/mysql/tmp
socket = /home/mysql/mysql.sock
pid_file = /home/mysql/mysql.pid
character_set_server = utf8
collation_server = utf8_general_ci
open_files_limit = 10240
explicit_defaults_for_timestamp
max_allowed_packet = 256M
max_heap_table_size = 256M
net_buffer_length = 8K
sort_buffer_size = 2M
join_buffer_size = 4M
read_buffer_size = 2M
read_rnd_buffer_size = 16M
log_error = /home/mysql/log/error.log
log_bin = /home/mysql/binlog/mysql-bin
binlog_cache_size = 32M
max_binlog_cache_size = 2G
max_binlog_size = 500M
binlog_format = mixed
log_output = FILE
expire_logs_days = 5
slow_query_log = 1
long_query_time = 3
slow_query_log_file = /home/mysql/log/slow-query.log
innodb_buffer_pool_size = 500M
innodb_log_file_size = 200M
innodb_log_files_in_group = 3
innodb_lock_wait_timeout = 20
[mysql]
no_auto_rehash
[mysqld_safe]
log-error=/home/mysql/log/error.log
9 配置mysql成功centos服務(wù)(可以不做)
配置mysql系統(tǒng)服務(wù):
cd /usr/local/mysql
cp support-files/mysql.server /etc/init.d/mysql
chkconfig --add mysql
chkconfig mysql on
啟動數(shù)據(jù)庫:
service mysql start
如果想部署多實例情況,重復(fù)步驟7到8即可
我的多實例啟動腳本:
mysqld_safe --defaults-file=/home/mysql/data/3306/my.cnf --user=mysql &
mysqld_safe --defaults-file=/home/mysql/data/3307/my.cnf --user=mysql &
mysqld_safe --defaults-file=/home/mysql/data/3308/my.cnf --user=mysql &