CentOS6.9+Mysql5.7.18源码安装详细教程

时间:2021-05-25

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

在MySQL 5.7.6版本以前是 bin/mysql_install_db --user

执行完成后,查看 logs/mysql_error.log文件,将里面的临时root密码记下来

A temporary password is generated for root@localhost: xxxxxxxxxx

6、配置mysql

chkconfig --add mysqld # 添加到系统服务chkconfig mysqld on # 开机启动service mysqld start启动不成功,使用safe模式启动 chown -R mysql:root /var/run/mysqld./bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql &./mysql -uroot -p

输入mysql_error.log中的临时密码登入mysql控制台

set password='asdfghjkl'';Query OK, 0 rows affected (0.00 sec)show warnings;

停止mysql

mysqladmin -u root -p shutdown

输入刚才设置的密码,停止成功

接下来可以使用系统服务来启动mysql了:

service mysqld start # 启动mysql服务

以上所述是小编给大家介绍的CentOS6.9+Mysql5.7.18源码安装,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章