CentOS6.9+Mysql5.7.18源码安装详细教程
CentOS6.9+Mysql5.7.18源码安装,以下操作均在root用户下执行。
1、安装依赖工具
cmake make3.75+ gcc4.4.6+ Boost1.59.0 bison ncurses yum install -y cmake,make,gcc,gcc-c++,bison, ncurses,ncurses-devel cd /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.7 cmake . -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.7 rm -f CMakeCache.txt make clean
5、初始化系统数据库
vim /etc/my.cnf
进入insert模式,将原来内容替换成如下内容:
[client] port=3306 socket=/temp/mysql.sock [mysqld] character-set-server=utf8 collation-server=utf8_general_ci skip-external-locking skip-name-resolve user=mysql port=3306 basedir=/usr/local/mysql datadir=/usr/local/mysql/data tmpdir=/usr/local/mysql/temp # server_id = ..... socket=/usr/local/mysql/mysql.sock log-error=/usr/local/mysql/logs/mysql_error.log pid-file=/usr/local/mysql/mysql.pid open_files_limit=10240 back_log=600 max_connections=500 max_connect_errors=6000 wait_timeout=605800 #open_tables=600 #table_cache = 650 #opened_tables = 630 max_allowed_packet=32M sort_buffer_size=4M join_buffer_size=4M thread_cache_size=300 query_cache_type=1 query_cache_size=256M query_cache_limit=2M query_cache_min_res_unit=16k tmp_table_size=256M max_heap_table_size=256M key_buffer_size=256M read_buffer_size=1M read_rnd_buffer_size=16M bulk_insert_buffer_size=64M lower_case_table_names=1 default-storage-engine=INNODB innodb_buffer_pool_size=2G innodb_log_buffer_size=32M innodb_log_file_size=128M innodb_flush_method=O_DIRECT ##################### thread_concurrency=32 long_query_time=2 slow-query-log=on slow-query-log-file=/usr/local/mysql/logs/mysql-slow.log [mysqldump] quick max_allowed_packet=32M [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid cd /usr/local/mysql mkdir data mkdir logs mkdir temp chmod 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源码安装,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对我们网站的支持!
赞 (0)