MySQL 5.7.13 源码编译安装配置方法图文教程
作者:xyang0917 发布时间:2024-01-21 02:03:57
安装环境:CentOS7 64位 MINI版
官网源码编译安装文档:http://dev.mysql.com/doc/refman/5.7/en/source-installation.html
一、系统安装条件
官方文档说明:http://dev.mysql.com/doc/refman/5.7/en/source-installation.html
1> cmake
MySQL使用cmake跨平台工具预编译源码,用于设置mysql的编译参数。如:安装目录、数据存放目录、字符编码、排序规则等。安装最新版本即可。
2> make3.75
mysql源代码是由C和C++语言编写,在linux下使用make对源码进行编译和构建,要求必须安装make 3.75或以上版本
3> gcc4.4.6
GCC是Linux下的C语言编译工具,mysql源码编译完全由C和C++编写,要求必须安装GCC4.4.6或以上版本
4> Boost1.59.0
mysql源码中用到了C++的Boost库,要求必须安 * oost1.59.0或以上版本
5> bison2.1
Linux下C/C++语法分析器
6> ncurses
字符终端处理库
所以在安装前,需先安装相关的依赖库:
shell> sudo yum install -y cmake,make,gcc,gcc-c++,bison, ncurses,ncurses-devel
下载Boost1.59.0源代码,并解压到/usr/local/目录下:
shell> wget -O https://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
shell> tar -zxvf boost_1_59_0.tar.gz -C /usr/local/
二、下载MySQL源码
从github上下载mysql的源码
shell> cd /opt
shell> git clone https://github.com/mysql/mysql-server.git
shell> ls mysql-server
如果没安装git客户端,执行yum install -y git安装。
shell> git branch -r
origin/5.5
origin/5.6
origin/5.7
origin/HEAD -> origin/5.7
origin/cluster-7.2
origin/cluster-7.3
origin/cluster-7.4
origin/cluster-7.5
当前分支默认为5.7版本,如果要安装其它版本,切换到相应的分支即可。如安装5.6版本:git checkout 5.6,这里以安装5.7为例。
搜狐镜像下载地址:
http://mirrors.sohu.com/mysql/MySQL-5.5/
http://mirrors.sohu.com/mysql/MySQL-5.6/
http://mirrors.sohu.com/mysql/MySQL-5.7/
三、安装
1> 添加mysql用户
shell> cd /opt/mysql-server
shell> groupadd mysql #添加mysql用户组
shell> useradd -r -g mysql -s /bin/false mysql #添加mysql用户
2> 配置mysql预编译参数
shell> cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DWITH_BOOST=/usr/local/boost_1_59_0 \
-DSYSCONFDIR=/etc \
-DEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_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:安装所有字符集
更多预编译配置参数请参考mysql官方文档说明:http://dev.mysql.com/doc/refman/5.7/en/source-configuration-options.html#cmake-general-options
3> 编译并安装
shell> make -j `grep processor /proc/cpuinfo | wc -l`
shell> make install
-j参数表示根据CPU核数指定编译时的线程数,可以加快编译速度。默认为1个线程编译,经测试单核CPU,1G的内存,编译完需要将近1个小时。
4> 初始化系统数据库
shell> cd /usr/local/mysql
shell> chown -R mysql:mysql .
# 注意:MySQL 5.7.6之前的版本执行这个脚本初始化系统数据库
shell> ./bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
# 5.7.6之后版本初始系统数据库脚本(本文使用此方式初始化)
shell> ./bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
shell> ./bin/mysql_ssl_rsa_setup
shell> chown -R root .
shell> chown -R mysql data
注意:如果使用–initialize参数初始化系统数据库之后,会在~/.mysql_secret文件中生成root用户的一个临时密码,同时也在初始化日志中打印出来了,如下图红圈中所示:
5、配置文件及参数优化
shell> cp support-files/my-default.cnf /etc/my.cnf
shell> vim /etc/my.cnf
[client]
port=3306
socket=/usr/local/mysql/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
6、配置mysql服务
shell> cp support-files/mysql.server /etc/init.d/mysqld
shell> chkconfig --add mysqld # 添加到系统服务
shell> chkconfig mysqld on # 开机启动
7、启动服务
shell> service mysqld start # 启动mysql服务
shell> service mysqld stop # 停止mysql服务
shell> service mysqld restart # 重新启动mysql服务
8、设置数据库密码
shell> /usr/local/mysql/bin/mysql -e "grant all privileges on *.* to root@'127.0.0.1' identified by "root" with grant option;"
shell> /usr/local/mysql/bin/mysql -e "grant all privileges on *.* to root@'localhost' identified by "root" with grant option;"
# 开启远程登录(将host设为%即可)
/usr/local/mysql/bin/mysql -e "grant all privileges on *.* to root@'%' identified by "root" with grant option;"
9、配置mysql环境变量
shell> vim /etc/profile
shell> export PATH=/usr/local/mysql/bin:$PATH
shell> source /etc/profile
四、其它注意事项
如果中途编译失败了,需要删除cmake生成的预编译配置参数的缓存文件和make编译后生成的文件,再重新编译。
shell> cd /opt/mysql-server
shell> rm -f CMakeCache.txt
shell> make clean
来源:http://blog.csdn.net/xyang81/article/details/51792144


猜你喜欢
- myPhoneBook2.py#!/usr/bin/python# -*- coding: utf-8 -*-import reclass
- 1.remove: 删除单个元素,删除首个符合条件的元素,按值删除,从左向右依次删除符合条件的值举例说明:>>> str=
- 这是解释器设置问题,在设置里找到interpreter 找到合适的目录就可以了。因为重装了python导致pycharm找不到路径了。另外,
- 假如你正在运行使用MySQL的Web应用程序,那么你把密码或者其他敏感信息保存在应用程序里的机会就很大。保护这些数据免受黑客或者窥探者的获取
- 本文实例讲述了php查询mysql数据库并将结果保存到数组的方法。分享给大家供大家参考。具体分析如下:这里主要用到了mysql_fetch_
- 简单方法:models.pyclass IceCreamBar(models.Model): title
- 代码如下:Class Vector Private vector_datas() Private&n
- 这篇文章主要介绍了python误差棒图errorbar()函数实例解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学
- 1、问题描述某厂生产甲乙两种饮料,每百箱甲饮料需用原料6千克、工人10名,获利10万元;每百箱乙饮料需用原料5千克、工人20名,获利9万元。
- 本文实例为大家分享了javascript不同颜色Tab标签切换效果的实现代码,供大家参考,具体内容如下具体代码:<html> &
- 一般的防止被框架方式或者被框架后自动转向,方法如下: if (top.location != self.loc
- 如我们在之前的教程里讨论的那样,分页可以通过两种方法来实现:默认分页– 你仅仅只用选中data Web control的 智能标签的Enab
- 数据准备import numpy as npimport pandas as pdimport jsonimport psycopg2dat
- 本文实例为大家分享了SVM手写数字识别功能的具体代码,供大家参考,具体内容如下1、SVM手写数字识别识别步骤:(1)样本图像的准备。(2)图
- 这篇文章主要介绍了opencv python图像梯度实例详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需
- 1. 准备工作下载源码包wget http://python.org/ftp/python/2.7.3/Python-2.7.3.tar.b
- 前言:项目的成就感来源于大家~~必须先感谢一切该感谢的人!(旁白:写了很多次设计实录分享,这次是最百感交集的一次,话多这习惯还大家海涵~嘻嘻
- 1.用管理员打开cmd2.首先通过pip命令安装wheelpip install wheel如果提示'pip'不是内部或外部
- Python是静态作用域语言,但是它自身是一个动态语言。在Python中变量的作用域是由变量在代码中的位置决定的,与C语言有些相似,但不是完
- 本文实例分析了ThinkPHP中的__initialize()和类的构造函数__construct()。分享给大家供大家参考。具体分析如下: