简述

MySQL提供了二进制包,但是有时候,我们的环境包版本不一样,导致二进制包无法正常使用,就不需要手动编译安装一个版本。

环境介绍

操作系统:CentOS 7.6.1810

MySQL版本:5.6.34

安装

创建执行用户

useradd -s /sbin/nologin mysql
passwd mysql

安装依赖包

yum -y install wget cmake ncurses-devel bzr gcc-c++ gcc bison make perl-Module-Install.noarch 

下载源码包

wget -c http://mirror.bit.edu.cn/mysql/Downloads/MySQL-5.6/mysql-5.6.34.tar.gz

解压编译

tar  zxvf  mysql-5.6.34.tar.gz

cd mysql-5.6.34

cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DENABLED_LOCAL_INFILE=1 -DINSTALL_PLUGINDIR=/usr/local/mysql/plugin

make  && make install 

设置配置文件啊

cat > /etc/my.cnf <<END
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port = 3306
socket = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
log-bin=mysql-bin
binlog_format=mixed
server-id = 1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
END

设置启动文件

cp -f /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

初始化数据库

mkdir -p  /usr/local/mysql/data

chown mysql.mysql /usr/local/mysql/data -R 

cd /usr/local/mysql

./scripts/mysql_install_db --defaults-file=/etc/my.cnf --user=mysql

启动数据库

/etc/init.d/mysql  start 

总结

源码编译需要的时间比较久,但是一般编译完一份,就可以拷贝到其他同系统的机器上运行了。