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用户和组,建立相关目录
/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
三实例部署的话,可以同时创建以下目录
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
创建MysqL安装目录
mkdir /usr/local/MysqL chown -R MysqL.MysqL /usr/local/MysqL chown -R MysqL.MysqL /home/MysqL
5 编译MysqL源码&安装MysqL
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
如果日后需要调试MysqL源码,在cmake时候设置 -DWITH_DEBUG=1,即编译为带调试信息的MysqL目标文件
编译
make
根据机器配置等待一段时间,看到100%字样,则说明编译成功
安装到 /usr/local/MysqL 目录下
make install
6.配置MysqL环境变量
在/etc/profile中添加/usr/local/MysqL/bin到PATH变量中
PATH=/usr/local/MysqL/bin:$PATH
执行source /etc/profile 生效
7.初始化MysqL数据库
初始化data文件
MysqLd --defaults-file=/home/MysqL/data/3306/my.cnf --initialize-insecure --user=MysqL --basedir=/usr/local/MysqL --datadir=/home/MysqL/data/3306/data
su - MysqL
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协议登陆MysqL
MysqL -h127.0.0.1 -uroot -p -P3306
8.配置数据库配置文件
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服务(可以不做)
配置MysqL系统服务:
cd /usr/local/MysqL
cp support-files/MysqL.server /etc/init.d/MysqL
chkconfig --add MysqL
chkconfig MysqL on
启动数据库:
service MysqL start
如果想部署多实例情况,重复步骤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 &
原文链接:https://www.f2er.com/centos/377356.html