CentOS6.9+Mysql5.7.18源码安装,以下操作均在root用户下执行。
1、安装依赖工具
cmake make3.75+ gcc4.4.6+ Boost1.59.0 bison ncursesyum install -y cmake,make,gcc,gcc-c++,bison, ncurses,ncurses-develcd /opt |
wget https://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
或者向度娘要一个
tar -zxvf boost_1_59_0.tar.gz -C /usr/local/ |
2、下载mysql准备安装
git clone https://github.com/mysql/mysql-server.git
没有git就 yum install git装一个
选择5.7
创建mysql用户,用户组为root
useradd -r -g root -s /bin/false mysql |
3、执行cmake
cd /opt/mysql-server5.7cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql /-DMYSQL_DATADIR=/usr/local/mysql/data /-DWITH_BOOST=/usr/local/boost_1_59_0 /-DMYSQL_UNIX_ADDR=/tmp/mysql.sock /-DSYSCONFDIR=/etc /-DEFAULT_CHARSET=utf8 /-DDEFAULT_COLLATION=utf8_general_ci /-DENABLED_LOCAL_INFILE=1 /-DEXTRA_CHARSETS=all-DCMAKE_INSTALL_PREFIX:安装路径-DMYSQL_DATADIR:数据存放目录-DWITH_BOOST:boost源码路径-DSYSCONFDIR:my.cnf配置文件目录-DEFAULT_CHARSET:数据库默认字符编码-DDEFAULT_COLLATION:默认排序规则-DENABLED_LOCAL_INFILE:允许从本文件导入数据-DEXTRA_CHARSETS:安装所有字符集 4、编译安装make -j `grep processor /proc/cpuinfo | wc -l`make install-j参数表示根据CPU核数指定编译时的线程数,可以加快编译速度。如果中途编译失败了,需要删除cmake生成的预编译配置参数的缓存文件和make编译后生成的文件,再重新编译。cd /opt/mysql-server5.7rm -f CMakeCache.txtmake clean |
5、初始化系统数据库
vim /etc/my.cnf |
进入insert模式,将原来内容替换成如下内容:
[client]port=3306socket=/temp/mysql.sock[mysqld]character-set-server=utf8collation-server=utf8_general_ciskip-external-lockingskip-name-resolveuser=mysqlport=3306basedir=/usr/local/mysqldatadir=/usr/local/mysql/datatmpdir=/usr/local/mysql/temp# server_id = .....socket=/usr/local/mysql/mysql.socklog-error=/usr/local/mysql/logs/mysql_error.logpid-file=/usr/local/mysql/mysql.pidopen_files_limit=10240back_log=600max_connections=500max_connect_errors=6000wait_timeout=605800#open_tables=600#table_cache = 650#opened_tables = 630max_allowed_packet=32Msort_buffer_size=4Mjoin_buffer_size=4Mthread_cache_size=300query_cache_type=1query_cache_size=256Mquery_cache_limit=2Mquery_cache_min_res_unit=16ktmp_table_size=256Mmax_heap_table_size=256Mkey_buffer_size=256Mread_buffer_size=1Mread_rnd_buffer_size=16Mbulk_insert_buffer_size=64Mlower_case_table_names=1default-storage-engine=INNODBinnodb_buffer_pool_size=2Ginnodb_log_buffer_size=32Minnodb_log_file_size=128Minnodb_flush_method=O_DIRECT#####################thread_concurrency=32long_query_time=2slow-query-log=onslow-query-log-file=/usr/local/mysql/logs/mysql-slow.log[mysqldump]quickmax_allowed_packet=32M[mysqld_safe]log-error=/var/log/mysqld.logpid-file=/var/run/mysqld/mysqld.pidcd /usr/local/mysqlmkdir datamkdir logsmkdir tempchmod 0770 -R ../mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql --socket=/tmp/mysql.sock |