Centos7 mysql-community-5.7.11编译安装
安装环境
[root@localhost ~]# cat /etc/centos-release
CentOS Linux release 7.0.1406 (Core)
0x01 准备工作
1、到mysql官网下载mysql-community-5.7.11-1.el7.src.rpm源码包
rpm -ih mysql-community-5.7.11-1.el7.src.rpm会在用户目录下生成一个rpmbuild,从SOURCES文件夹内可以获得源码mysql-5.7.11.tar.gz,解压进入源码目录准备安装
2、因为mysql需要使用cmake编译,直接从yum从光盘的源中找到cmake
[root@localhost ~]# yum info cmake
名称 :cmake
架构 :x86_64
版本 :2.8.11
发布 :4.el7
大小 :6.7 M
3、准备开发环境yum groupinstall Additional Development,yum groupinstall Development tools之前的版本是Development tools和Development Libraries两个软件包组,我这里没有安装,因为只需要gcc和gcc-c++
0x02 mysql编译选项
部分常用编译选项
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql [MySQL安装的根目录]
-DMYSQL_DATADIR=/mydata/mysql/data [MySQL数据库文件存放目录]
-DSYSCONFDIR=/etc [MySQL配置文件所在目录]
-DMYSQL_USER=mysql [MySQL用户名]
-DWITH_MYISAM_STORAGE_ENGINE=1 [MySQL的数据库引擎]
-DWITH_INNOBASE_STORAGE_ENGINE=1 [MySQL的数据库引擎]
-DWITH_ARCHIVE_STORAGE_ENGINE=1 [MySQL的数据库引擎]
-DWITH_MEMORY_STORAGE_ENGINE=1 [MySQL的数据库引擎]
-DWITH_READLINE=1 [MySQL的readline library,批量导入数据]
-DMYSQL_UNIX_ADDR=/var/run/mysql/mysql.sock [MySQL的通讯目录]
-DWITH-LIBWRAP=0 [是否支持libwrap]
-DENABLE_DOWNLOADS=1 [编译时允许自主下载相关文件]
-DDEFAULT_CHARSET=utf8 [设置默认字符集为utf8]
-DDEFAULT_COLLATION=utf8_general_ci [设置默认排序字符集规则]
http://dev.mysql.com/doc/refman/5.7/en/source-configuration-options.html 官方文档编译选项说明
0x03 安装过程(gcc / boost_1_59_0 / CURSES_LIBRARY )
[root@localhost ~]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/mymnt/sqldata -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/var/run/mysql/mysql.sock -DWITH-LIBWRAP=0 -DENABLE_DOWNLOADS=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
-- Running cmake version 2.8.11
-- Could NOT find Git (missing: GIT_EXECUTABLE)
-- Configuring with MAX_INDEXES = 64U
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error: your C compiler: "CMAKE_C_COMPILER-NOTFOUND" was not found. Please set CMAKE_C_COMPILER to a valid compiler path or name.
CMake Error: your CXX compiler: "CMAKE_CXX_COMPILER-NOTFOUND" was not found. Please set CMAKE_CXX_COMPILER to a valid compiler path or name.
CMake Error at cmake/os/Linux.cmake:41 (MESSAGE):
Unsupported compiler!
Call Stack (most recent call first):
CMakeLists.txt:162 (INCLUDE)
这是没有安装gcc和gcc-c++
[root@localhost mysql-5.7.11]# yum install gcc gcc-c++
再cmake一次
-- MySQL 5.7.11
-- Packaging as: mysql-5.7.11-Linux-x86_64
-- Looked for boost/version.hpp in and
-- BOOST_INCLUDE_DIR BOOST_INCLUDE_DIR-NOTFOUND
-- LOCAL_BOOST_DIR
-- LOCAL_BOOST_ZIP
-- Could not find (the correct version of) boost.
-- MySQL currently requires boost_1_59_0
CMake Error at cmake/boost.cmake:81 (MESSAGE):
You can download it with -DDOWNLOAD_BOOST=1 -DWITH_BOOST=<directory>
This CMake script will look for boost in <directory>. If it is not there,
it will download and unpack it (in that directory) for you.
If you are inside a firewall, you may need to use an http proxy:
export http_proxy=http://example.com:80
Call Stack (most recent call first):
cmake/boost.cmake:238 (COULD_NOT_FIND_BOOST)
CMakeLists.txt:443 (INCLUDE)
-- Configuring incomplete, errors occurred!
这个就已经说明了You can download it with -DDOWNLOAD_BOOST=1 -DWITH_BOOST=<directory>,Boost库是一个经过千锤百炼、可移植、提供源代码的C++库,作为标准库的后备,是C++标准化进程的发动机之一。
先从boost官网下载这个库boost_1_59_0.tar.gz
解压后把目录添加到-DWITH_BOOST编译选项中
继续编译报错如下
-- Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH)
CMake Error at cmake/readline.cmake:64 (MESSAGE):
Curses library not found. Please install appropriate package,
remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
Call Stack (most recent call first):
cmake/readline.cmake:107 (FIND_CURSES)
cmake/readline.cmake:181 (MYSQL_USE_BUNDLED_EDITLINE)
CMakeLists.txt:471 (MYSQL_CHECK_EDITLINE)
这个错误是说明缺少Curses库yum install ncurses-devel,需要注意的是每次编译错误都要移除CMakeCache.txt,最后出现 Build files have been written 即成功
CMake Warning:
Manually-specified variables were not used by the project:
DOWNLOAD_BOOST
WITH-LIBWRAP
WITH_MEMORY_STORAGE_ENGINE
WITH_READLINE
-- Build files have been written to: /root/mysql-5.7.11
使用make大约两个小时的样子编译完成,到百分之五十几的时候停留的时间比较长。
make install
出现一堆安装信息即完成安装
-- Installing: /usr/local/mysql/mysql-test/./cmake_install.cmake
-- Installing: /usr/local/mysql/mysql-test/./CTestTestfile.cmake
-- Up-to-date: /usr/local/mysql/mysql-test/mtr
-- Up-to-date: /usr/local/mysql/mysql-test/mysql-test-run
-- Installing: /usr/local/mysql/mysql-test/lib/My/SafeProcess/my_safe_process
-- Up-to-date: /usr/local/mysql/mysql-test/lib/My/SafeProcess/my_safe_process
-- Installing: /usr/local/mysql/mysql-test/lib/My/SafeProcess/Base.pm
-- Installing: /usr/local/mysql/support-files/my-default.cnf
-- Installing: /usr/local/mysql/support-files/mysqld_multi.server
-- Installing: /usr/local/mysql/support-files/mysql-log-rotate
-- Installing: /usr/local/mysql/support-files/magic
-- Installing: /usr/local/mysql/share/aclocal/mysql.m4
-- Installing: /usr/local/mysql/support-files/mysql.server
[root@localhost mysql-5.7.11]#
0x04 安装后目录创建
socket=/var/run/mysql/mysql.sock
basedir = /usr/local/mysql
datadir = /mymnt/sqldata
socket=/var/run/mysql/mysql.sock
log-error = /var/log/mysql/error.log
pid-file = /var/log/mysql/mysql.pid
如配置文件关于目录相关的部分,我们需要创建/var/run/mysql , /mymnt/sqldata , /var/log
创建mysql用户和组,将数据目录 /mymnt/sqldata 和安装目录/var/run/mysql的属主(组)更改成mysql
[root@localhost mysql]# groupadd -r mysql
[root@localhost mysql]# useradd -r -g mysql -s /sbin/nologin mysql
[root@localhost mysql]# mkdir /var/run/mysql
[root@localhost mysql]# mkdir /var/log/mysql
[root@localhost mysql]# chown mysql:mysql /var/run/mysql/
[root@localhost mysql]# chown mysql:mysql /var/log/mysql/
[root@localhost mysql]# chown mysql:mysql /mymnt/sqldata/
[root@localhost mysql]# chown -R mysql:mysql /usr/local/mysql
0x05 初始化
1、mysql-5.7版本的my.cnf文件在support-files/下并没有模板文件,自行添加配置文件
2、将安装目录下support-files/mysql.server 启动脚本复制到 /etc/init.d/mysqld,以便实现开机启动。也可以[root@localhost mysql]# ./support-files/mysql.server start 临时启动
未启动时执行mysql命令会报错如下:
[root@localhost mysql]# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysql/mysql.sock' (2)
3、添加环境变量以便使用初始化命令 export PATH=/usr/local/mysql/bin:$PATH
4、初始化
mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/mymnt/sqldata
0x06 其他
1、mysqld_safe
mysqld 和 mysqld_safe都可以启动mysql。直接运行mysqld程序来启动MySQL服务的方法很少见,mysqld_safe脚本会在启动MySQL服务器后继续监控其运行情况,并在其死机时重新启动它。
我们可以发现这是一个shell脚本,在Unix和NetWare中推荐使用mysqld_safe来启动mysqld服务器。mysqld_safe增加了一些安全特性,例如当出现错误时重启服务器并向错误日志文件写入运行时间信息。
[root@localhost mysql]# file bin/mysqld
bin/mysqld: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=0x772828c9d330090391cd89dbe699f041a378944d, not stripped
[root@localhost mysql]# file bin/mysqld_safe
bin/mysqld_safe: POSIX shell script, ASCII text executable
2、mysql_secure_installation
MySQL安全配置向导,运行mysql_secure_installation会执行几个设置:
a)为root用户设置密码
b)删除匿名账号
c)取消root用户远程登录
d)删除test库和对test库的访问权限
e)刷新授权表使修改生效
通过这几项的设置能够提高mysql库的安全。建议生产环境中mysql安装这完成后一定要运行一次mysql_secure_installation
3、为了方便其他程序调用(如php),将MySQL数据库的动态链接库目录添加至系统链接库,echo "/usr/local/mysql/lib" > /etc/ld.so.conf.d/mysql.conf
0x07 附:my.cnf示例
百度到一个mysql配置文件样例:
- 作者:vfhky
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL. [client]
port=3306
socket=/var/run/mysql/mysql.sock [mysqld] # Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M # Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin # These are commonly set, remove the # and set as required.
user = mysql
basedir = /usr/local/mysql
datadir = /mydata/mysql/data
port=3306
server-id = 1
socket=/var/run/mysql/mysql.sock character-set-server = utf8
log-error = /var/log/mysql/error.log
pid-file = /var/log/mysql/mysql.pid
general_log = 1
skip-name-resolve
#skip-networking
back_log = 300 max_connections = 1000
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 128
max_allowed_packet = 4M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 16M read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 28M
key_buffer_size = 4M thread_cache_size = 8 query_cache_type = 1
query_cache_size = 8M
query_cache_limit = 2M ft_min_word_len = 4 log_bin = mysql-bin
binlog_format = mixed
expire_logs_days = 30 performance_schema = 0
explicit_defaults_for_timestamp #lower_case_table_names = 1 myisam_sort_buffer_size = 8M
myisam_repair_threads = 1 interactive_timeout = 28800
wait_timeout = 28800 # Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M # Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0 # Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,NO_AUTO_CREATE_USER,STRICT_TRANS_TABLES [mysqldump]
quick
max_allowed_packet = 16M [myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M
Centos7 mysql-community-5.7.11编译安装的更多相关文章
- mysql5.7.11编译安装以及修改root密码小结
系统是cenos6.7 64位的,默认mysql5.7.11下载到/usr/local/src,安装目录在/app/local/mysql目录下,mysql数据放置目录/app/local/data. ...
- MySQL(MariaDB)基础之一:编译安装
一.cmake介绍 cmake的重要特性之一是其独立于源码的编译功能,即编译工作可以在另一个指定的目录中而非源码目录中进行,这可以保证源码目录不受任何一次编译影响,因此在同一个源码树上可以进行多次不同 ...
- rehat7.X下postgresql 11编译安装
文档目录结构: 一.准备 操作系统版本:rehat7.6 Postgresql:11.2 软件安装目录:/pgsql11/basedir 数据文件存放目录:/pgsql11data/ 11.2的下载地 ...
- mysql 5.6.38 数据库编译安装
一.系统环境: # cat /etc/redhat-release CentOS release 6.9 (Final) 二.mysql 编译安装: 1.安装依赖包: yum install -y n ...
- Centos7通过yum跟源码编译安装Nginx
源码编译安装 http://nginx.org/en/download.html 到官网下载,然后用XFTP上传到root目录 把文件解压出来 tar -zxvf nginx-1.16.0.tar.g ...
- Linux下MySQL 5.6.24的编译安装与部署
MySQL 5.6正式版发布了,相对于5.5版本作出了不少改进,其源码安装配置方式也有所变化,本文根据实际操作,不断尝试,精确还原了安装的具体步骤. 在Linux下安装MySQL前,先确认卸载系统自带 ...
- Linux MySQL单实例源码编译安装5.6
cmake软件 tar -zxvf cmake-2.8.11.2.tar.gz cd cmake-2.8.11.2 ./bootstrap make make install cd ../ 依赖包 ...
- redis(4.0.11)编译安装
一: redis数据库安装 系统环境:linux系统(centos/redhat):Red Hat Enterprise Linux Server release 6.8 (Santiago) red ...
- Linux MySQL单实例源码编译安装5.5.32
cmake软件 tar -zxvf cmake-2.8.8.tar.gz cd cmake-2.8.8 ./bootstrap make make install cd ../ 依赖包 yum i ...
随机推荐
- Access使用参数化UPDATE数据时,数据无法更新的问题
今天update access数据库时,使用了参数化的方式,结果不报错,但是数据也没有更新.经过google发现access使用参数化时,参数位置必须和赋值顺序相同才行,否则更新时就会出现数据无法更新 ...
- ASP.NET MVC路由配置(转载自http://www.cnblogs.com/zeusro/p/RouteConfig.html )
把apress.pro.asp.net.mvc.4.framework里的CHAPTER 13翻译过来罢了. XD 首先说URL的构造. 其实这个也谈不上构造,只是语法特性吧. 命名参数规范+匿名对象 ...
- Drools给日志打标签
一.定义日志模型 public class Logger { // 日志编号 private String id; // 目标IP private String targetIp; // 目标端口 p ...
- ios xmpp开发应用后台模式接收聊天信息处理方案
ios xmpp开发应用后台模式接收聊天信息 最近在使用xmppframwork来实现一个聊天应用,碰到了一个问题,应用进入后台以后,就接收不到消息了: 怎么样才能使应用被切到后台时,应用中的网络连接 ...
- ruby中proc和lambda的return区别
学习ruby有一段时间了,但是我看了好几遍proc和lambda的return区别的区别讲解,始终没明白到底什么区别,今天上午又看,终于感觉是茅塞顿开有点领悟了 一下内容部分来自<<rub ...
- How to force the UI to refresh immediately(WPF)
Question 0 Sign in to vote Folks, In my application, when the user hits "Submit" button, I ...
- UNIX网络编程-基本API介绍(二)
参考链接:http://www.cnblogs.com/riky/archive/2006/11/24/570713.aspx 1.getsockname和getpeername getsocknam ...
- ubuntu 12.04 设置代理
一. Ubuntu 12.04 apt-get 代理设置 由于公司通过代理上网,firefox的代理设置很容易就搞定了,但是通过apt-get安装软件还是不行,于是,查阅了很多资料,最多的方法就是网上 ...
- WinCE系统深度定制汇总
WinCE应用程序崩溃提示框的处理 WinCE6.0多国语言软键盘 定制WinCE6.0标准界面的一种方法 如何禁用WinCE下的沙漏图标 Silent RNAApp.exe for WinCE6.0 ...
- js实现日历卡
效果图如下 首先先添加简单的样式 <style type="text/css"> *{padding:0;margin:0;} #tab { margin:0 auto ...