CentOS7编译安装mysql-5.6.28和编译参数

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介:

    MySQL 5.5之后的源码包版本,安装方式采用CMake工具编译进行安装,因此在安装最新版MySQL之前,需要提前安装它。CMake是一个跨平台、开源软件构建系统,用于控制软件编译过程及生成独立的配置文件(makefile或者project),可以在编译时选择CMake编译器进行安装需要的软件。CMake官网https://cmake.org/,目前最新版本是3.4.3。

CMake安装方法

# wget https://cmake.org/files/v3.4/cmake-3.4.3.tar.gz
# yum install gcc gcc-c++ make automake

# ./bootstrap && make && make install

MySQL 5.6新特性

MySQL官网对MySQL 5.6的介绍:

    MySQL5.6是有史以来最好的版本,是世界上最广为使用的开源数据库,它提供了一套新的、先进的功能,使我们能建设的新一代基于网络和嵌入式应用和服务。

MySQL5.6的功能和特性

1、更好的性能和可扩展性

  • 改进InnoDB存储引擎所带来更好的交易吞吐量

  • 改良的优化所带来更好的查询执行时间和诊断能力

2、在线DDL /架构操作所带来更好的应用程序可用性

3、通过Memcached的API以NoSQL访问InnoDB所带来的更好的开发速度

4、改进复制技术所带来的高性能和能自行修复的集群部署

5、改进的Performance Schema所带来的更好的侦测和监测能力

6、改进的安全控制,使您部署应用程序时不需担心

7、其他重要的增强功能


MySQL5.6编译参数

官方文档:http://dev.mysql.com/doc/refman/5.6/en/source-configuration-options.html


编译安装mysql-5.6.28

step1:创建mysql用户、组

[root@www ~]# groupadd mysql

[root@www ~]# useradd -r -g mysql mysql

[root@www ~]# id mysql

uid=996(mysql) gid=1000(mysql) groups=1000(mysql)


[root@www ~]# mkdir /usr/local/mysql

[root@www ~]# mkdir /data/mysqldb


step2:安装必须的软件包

[root@www src]#  yum install gcc gcc-c++ ncurses-devel bison bison-devel


step3:编译安装MySQL

1、将下载的mysql源码包解压,并进入其解压目录下

[root@www mysql-5.6.28]# cmake . \

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \

-DMYSQL_DATADIR=/data/mysqldb \

-DSYSCONFDIR=/etc \

-DMYSQL_TCP_PORT=3306 \ 

-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_MYISAM_STORAGE_ENGINE=1 \

-DENABLED_LOCAL_INFILE=1 \

-DWITH_PARTITION_STORAGE_ENGINE=1 \

-DDEFAULT_CHARSET=utf8 \

-DEXTRA_CHARSETS=all \

-DDEFAULT_COLLATION=utf8_general_ci \

-DWITH_DEBUG=0


重新cmake需要删除CMakeCache.txt文件

[root@www mysql-5.6.28]# gmake

[root@www mysql-5.6.28]# gmake install

[root@www mysql-5.6.28]# ls /usr/local/mysql/
COPYING         README  data  include  man         scripts  sql-bench
INSTALL-BINARY  bin     docs  lib      mysql-test  share    support-files

2、设置MySQL目录权限

[root@www mysql-5.6.28]# chown -R root:mysql /usr/local/mysql/
[root@www mysql-5.6.28]# chown -R mysql:mysql /data/mysqldb/

3、安装系统数据库

[root@www scripts]# chmod +x mysql_install_db
[root@www scripts]# ./mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysqldb --no-defaults --user=mysql
[root@www scripts]# ls /data/mysqldb/
ib_logfile0  ib_logfile1  ibdata1  mysql  performance_schema  test


4、拷贝配置文件my.cnf

[root@www mysql-5.6.28]# cd support-files/
[root@www support-files]# cp my-default.cnf /etc/my.cnf
[root@www support-files]# vim /etc/my.cnf 
[mysqld]
basedir = /usr/local/mysql
datadir = /data/mysqldb
port = 3306
# server_id = .....
socket = /var/lib/mysql/mysql.sock


5、拷贝启动脚本

[root@www support-files]# cp mysql.server /etc/init.d/mysqld
[root@www support-files]# chmod 755 /etc/init.d/mysqld 
[root@www support-files]# chkconfig mysqld on

[root@www ~]# service mysqld restart
Shutting down MySQL. SUCCESS! 
Starting MySQL. SUCCESS! 

[root@www ~]# netstat -ntlp |grep mysqld
tcp6       0      0 :::3306                 :::*                    LISTEN      20708/mysqld


6、设置mysql环境变量

[root@www ~]# vim /etc/profile.d/path.sh
#!/bin/bash
export PATH=$PATH:/usr/local/mysql/bin
[root@www ~]# source /etc/profile

[root@www ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.28 Source distribution

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>


7、初始化MySQL及相关安全选项配置

[root@www ~]# mysql_secure_installation 



NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 ... Success!

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!




All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!


Cleaning up...


MySQL优化配置

[root@www ~]# vim /etc/my.cnf

[mysqld]
basedir = /usr/local/mysql
datadir = /data/mysqldb
port = 3306
socket = /var/lib/mysql/mysql.sock

key_buffer_size = 256M
sort_buffer_size = 2M
read_buffer_size = 1M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
net_buffer_length = 8K

table_open_cache = 1024
query_cache_size = 32M
thread_cache_size = 8

max_connections = 1000
max_allowed_packet = 4M
tmp_table_size = 16M
thread_concurrency = 8
skip-name-resolve

interactive_timeout = 8
wait_timeout  = 8
long_query_time = 2

slow_query_log=on
slow_query_log_file = /data/mysql/mysql.slow
long_query_time = 1


[root@www ~]# systemctl restart mysqld.service 


防火墙配置

[root@www ~]# firewall-cmd --permanent --add-port=3306/tcp

[root@www ~]# firewall-cmd --reload 

本文转自 HMLinux 51CTO博客,原文链接:http://blog.51cto.com/7424593/1740042

相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
9天前
|
应用服务中间件 Linux 网络安全
CentOS 7.4源码编译nginx1.12 并且隐藏nginx的版本
CentOS 7.4源码编译nginx1.12 并且隐藏nginx的版本
14 0
|
1月前
|
Linux 开发工具 C语言
Centos8下编译安装最新版ffmpeg解决方案(含Centos8换源阿里云)
Centos8下编译安装最新版ffmpeg解决方案(含Centos8换源阿里云)
142 3
|
9天前
|
关系型数据库 MySQL Linux
linux CentOS 7.4下 mysql5.7.20 密码改简单的方法
linux CentOS 7.4下 mysql5.7.20 密码改简单的方法
17 0
|
14天前
|
缓存 关系型数据库 MySQL
MySQL查询优化:提速查询效率的13大秘籍(合理使用索引合并、优化配置参数、使用分区优化性能、避免不必要的排序和group by操作)(下)
MySQL查询优化:提速查询效率的13大秘籍(合理使用索引合并、优化配置参数、使用分区优化性能、避免不必要的排序和group by操作)(下)
|
1月前
|
SQL 关系型数据库 MySQL
【Mysql】MYSQL参数max_allowed_packet 介绍
【Mysql】MYSQL参数max_allowed_packet 介绍
67 0
|
1月前
|
分布式计算 关系型数据库 MySQL
Sqoop【部署 01】CentOS Linux release 7.5 安装配置 sqoop-1.4.7 解决警告并验证(附Sqoop1+Sqoop2最新版安装包+MySQL驱动包资源)
【2月更文挑战第8天】Sqoop CentOS Linux release 7.5 安装配置 sqoop-1.4.7 解决警告并验证(附Sqoop1+Sqoop2最新版安装包+MySQL驱动包资源)
92 1
|
2天前
|
关系型数据库 MySQL Linux
centos7安装mysql-带网盘安装包
centos7安装mysql-带网盘安装包
28 2
|
9天前
|
关系型数据库 MySQL Linux
CentOS 7 下使用yum安装MySQL5.7.20 最简单 图文详解
CentOS 7 下使用yum安装MySQL5.7.20 最简单 图文详解
44 0
|
存储 关系型数据库 MySQL
【MYSQL】—— MySQL 在 Centos 7环境安装
【MYSQL】—— MySQL 在 Centos 7环境安装
|
1月前
|
关系型数据库 MySQL Linux
【VMware安装+centos 7Linux系统+MySQL安装】——在Linux系统中安装MySQL步骤,以及遇见的各种问题(如:vm两个虚拟网卡消失、vm网络适配器有感叹号等等)
【VMware安装+centos 7Linux系统+MySQL安装】——在Linux系统中安装MySQL步骤,以及遇见的各种问题(如:vm两个虚拟网卡消失、vm网络适配器有感叹号等等)
178 0