MySQL 5.7主要特性

  1. 更好的性能
    对于多核CPU、固态硬盘、锁有着更好的优化,每秒100W QPS已不再是MySQL的追求,下个版本能否上200W QPS才是用户更关心的。
  • 更好的InnoDB存储引擎
  • 更为健壮的复制功能
    复制带来了数据完全不丢失的方案,传统金融客户也可以选择使用。MySQL数据库。此外,GTID在线平滑升级也变得可能。
  • 更好的优化器
    优化器代码重构的意义将在这个版本及以后的版本中带来巨大的改进,Oracle官方正在解决MySQL之前最大的难题。
  • 原生JSON类型的支持
  • 更好的地理信息服务支持
    InnoDB原生支持地理位置类型,支持GeoJSON,GeoHash特性
  • 新增sys库
    以后这会是DBA访问最频繁的库MySQL 5.7

安装准备

安装依赖包

1
[root@snails ~]# yum -y install gcc gcc-c++ ncurses ncurses-devel cmake bison

下载相应源码包

1
2
[root@snails ~]# wget https://sourceforge.net/projects/boost/files/boost/1.65.0/boost_1_65_0.tar.gz/
[root@snails ~]# wget http://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.19.tar.gz

也可以使用官方下载链接 进行下载。

新建MySQL用户和用户组

1
[root@snails ~]# groupadd -r mysql && useradd -r -g mysql -s /sbin/nologin -M mysql

预编译

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[root@snails ~]# tar -zxvf boost_1_65_0.tar.gz
[root@snails data]# md5sum mysql-5.7.19.tar.gz
8fab75dbcafcd1374d07796bff88ae00 mysql-5.7.19.tar.gz
[root@snails ~]# tar -zxvf mysql-5.7.19.tar.gz
[root@snails data]# mkdir -p /data/mysql
[root@snails data]# cd mysql-5.7.19
[root@snails data]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysql \
-DWITH_BOOST=../boost_1_65_0 \
-DSYSCONFDIR=/etc \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DENABLE_DTRACE=0 \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DWITH_EMBEDDED_SERVER=1

编译安装

1
2
3
[root@snails mysql-5.7.19]# make -j `grep processor /proc/cpuinfo | wc -l`
#编译很消耗系统资源,小内存可能编译通不过make install
[root@snails mysql-5.7.19]# make install

设置启动脚本,开机自启动

1
2
3
4
5
6
[root@snails mysql-5.7.19]# ls -lrt /usr/local/mysql
[root@snails mysql-5.7.19]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@snails mysql-5.7.19]# chmod +x /etc/init.d/mysqld
[root@snails mysql-5.7.19]# systemctl enable mysqld
mysqld.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig mysqld on

配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/etc/my.cnf,仅供参考 
[root@snails mysql-5.7.19]# cat > /etc/my.cnf << EOF
[client]
port = 3306
socket = /dev/shm/mysql.sock
[mysqld]
port = 3306
socket = /dev/shm/mysql.sock
basedir = /usr/local/mysql
datadir = /data/mysql
pid-file = /data/mysql/mysql.pid
user = mysql
bind-address = 0.0.0.0
server-id = 1
init-connect = 'SET NAMES utf8mb4'
character-set-server = utf8mb4
#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 = 8M
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
log_error = /data/mysql/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /data/mysql/mysql-slow.log
performance_schema = 0
explicit_defaults_for_timestamp
#lower_case_table_names = 1
skip-external-locking
default_storage_engine = InnoDB
#default-storage-engine = MyISAM
innodb_file_per_table = 1
innodb_open_files = 500
innodb_buffer_pool_size = 64M
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 32M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
interactive_timeout = 28800
wait_timeout = 28800
[mysqldump]
quick
max_allowed_packet = 16M
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M
EOF

添加mysql的环境变量

1
[root@snails mysql-5.7.19]# echo -e '\n\nexport PATH=/usr/local/mysql/bin:$PATH\n' >> /etc/profile && source /etc/profile

初始化数据库

1
[root@snails mysql-5.7.19]# mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql

注:

  • MySQL之前版本mysql_install_db是在mysql_basedir/script下
  • MySQL 5.7直接放在了mysql_install_db/bin目录下。
  • “–initialize”已废弃,生成一个随机密码(~/.mysql_secret)
  • “–initialize-insecure”不会生成密码
  • “–datadir”目录下不能有数据文件

启动数据库

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@snails mysql-5.7.19]# systemctl start mysqld
[root@snails mysql-5.7.19]# systemctl status mysqld
● mysqld.service - LSB: start and stop MySQL
Loaded: loaded (/etc/rc.d/init.d/mysqld)
Active: active (running) since 一 2016-07-18 11:15:35 CST; 8s ago
Docs: man:systemd-sysv-generator(8)
Process: 23927 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=0/SUCCESS)
CGroup: /system.slice/mysqld.service
├─23940 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/mysql.pid
└─24776 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/mysql-err... 7月 18 11:15:32 snails systemd[1]: Starting LSB: start and stop MySQL...
7月 18 11:15:35 snails mysqld[23927]: Starting MySQL..[ OK ]
7月 18 11:15:35 snails systemd[1]: Started LSB: start and stop MySQL.

查看MySQL服务进程和端口

1
2
3
4
5
[root@snails mysql-5.7.19]# ps -ef | grep mysql
root 23940 1 0 11:15 ? 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/mysql.pid
mysql 24776 23940 0 11:15 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/mysql-error.log --open-files-limit=65535 --pid-file=/data/mysql/mysql.pid --socket=/dev/shm/mysql.sock --port=3306
[root@snails mysql-5.7.19]# netstat -tunpl | grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 24776/mysqld

设置数据库root用户密码

  MySQL和Oracle数据库一样,数据库也默认自带了一个 root 用户(这个和当前Linux主机上的root用户是完全不搭边的),我们在设置好MySQL数据库的安全配置后初始化root用户的密码。配制过程中,一路输入 y 就行了。这里只说明下MySQL5.7.13版本中,用户密码策略分成低级 LOW 、中等 MEDIUM 和超强 STRONG 三种,推荐使用中等 MEDIUM 级别!

1
[root@snails mysql-5.7.19]# mysql_secure_installation

常用操作

将MySQL数据库的动态链接库共享至系统链接库

  一般MySQL数据库还会被类似于PHP等服务调用,所以我们需要将MySQL编译后的lib库文件添加至当前Linux主机链接库 /etc/ld.so.conf.d/
下,这样MySQL服务就可以被其它服务调用了。

1
2
3
4
5
6
7
8
9
10
11
12
 [root@snails mysql-5.7.19]# ldconfig |grep mysql
[root@snails mysql-5.7.19]# echo "/usr/local/mysql/lib" > /etc/ld.so.conf.d/mysql.conf
[root@snails mysql-5.7.19]# ldconfig
[root@snails mysql-5.7.19]# ldconfig -v |grep mysql
ldconfig: 无法对 /libx32 进行 stat 操作: 没有那个文件或目录
ldconfig: 多次给出路径“/usr/lib”
ldconfig: 多次给出路径“/usr/lib64”
ldconfig: 无法对 /usr/libx32 进行 stat 操作: 没有那个文件或目录
/usr/lib64/mysql:
libmysqlclient.so.18 -> libmysqlclient.so.18.0.0
/usr/local/mysql/lib:
libmysqlclient.so.20 -> libmysqlclient.so.20.3.0

创建其它MySQL数据库用户

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@snails mysql-5.7.19]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.13-log Source distribution Copyright (c) 2000, 2016, 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>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
mysql>CREATE DATABASE `tonnydb` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
Query OK, 1 row affected (0.01 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| tonnydb |
+--------------------+
5 rows in set (0.00 sec)
mysql> grant all privileges on tonnydb.* to 'tonny@%' identified by 'Hi.Tonny@888';
Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec) mysql> exit
Bye

在CentOS上编译安装MySQL 5.7.13步骤详解的更多相关文章

  1. 在VM虚拟机Windows Server r2上部署安装Microsoft Dynamics CRM 2016 步骤详解(一)

    应公司需求,最近在学微软的Dynamics CRM.在搭建环境的过程中也遇到了一些雷坑,在这里分享一下安装部署过程当中所遇到的一些问题, 安装Microsoft Dynamics CRM 2016的几 ...

  2. gcc/g++等编译器 编译原理: 预处理,编译,汇编,链接各步骤详解

    摘自http://blog.csdn.net/elfprincexu/article/details/45043971 gcc/g++等编译器 编译原理: 预处理,编译,汇编,链接各步骤详解 C和C+ ...

  3. CentOS下编译安装MySQL 5.6.21

    一.编译安装MySQL前的准备工作 安装编译源码所需的工具和库 yum install gcc gcc-c++ ncurses-devel perl 安装cmake:http://www.cnblog ...

  4. centos上如何安装mysql

    centos可以使用yum安装mysql 但是版本很低,且不灵活. 本文将介绍如何使用安装包安装mysql http://dev.mysql.com/downloads/mysql/ 下载mysql ...

  5. CentOS 下编译安装MySQL

    CnetOS 下编译安装 MySql 查看是否存在旧版本: rpm -qa | grep mysql 卸载旧版本: rpm -e mysql   #普通删除模式 rpm -e --nodeps mys ...

  6. CentOS上编译安装OpenCV-2.3.1与ffmpeg-2.1.2

    已測试环境: CentOS 6.3 32bit CentOS 6.5 64bit 以前在CentOS 6.3 32bit安装过OpenCV,參见CentOS 6.3中安装OpenCV2.3.1,现在换 ...

  7. centos 7 编译安装mysql 详细过程

    一.配置防火墙,开启80端口.3306端口 CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙. 1.关闭firewall: systemctl stop fi ...

  8. 在centos上编译安装mariadb数据库

    一.安装前提(准备数据文件.安装其他依赖的软件) 1.准备数据存放的目录 [root@localhost ~]# fdisk /dev/sdb  (fdisk /dev/sdb 创建一个逻辑分区/de ...

  9. centos 7编译安装mysql 5.7.17

    1.进入MySQL官网下载MySQL源代码 依次点击Downloads -> Community -> MySQL Community Server 源代码1.Select Operati ...

随机推荐

  1. sql语句查询某一天数据

    --如果还有今天以后的数据 --一周内呢SELECT * FROM TB WHERE datediff(dd,DATE_TIME,getdate()) between 0 and 7 --从现在起往前 ...

  2. 利用exif.js解决ios或Android手机上传竖拍照片旋转90度问题

    html5+canvas进行移动端手机照片上传时,发现ios手机上传竖拍照片会逆时针旋转90度,横拍照片无此问题:Android手机没这个问题. 因此解决这个问题的思路是:获取到照片拍摄的方向角,对非 ...

  3. C++ 第十二课 其它标准C函数

    abort() 停止程序执行 assert() 当表达式非真,停止程序执行 atexit() 当程序退出执行设定的程序 bsearch() 执行折半查找 exit() 停止程序执行 getenv() ...

  4. SQL中Union和UnionAll的使用

    SQL中Union和UnionAll的使用 1.建立一个Student表 ,如下: 2.建立一个Teacher表,如下: 3.使用Union,将去重并组合表,效果: 4.使用Union All,不去重 ...

  5. Wrong FS: hdfs://xxx/xxx expected: file:///

    Eclipse调用HDFS API上传文件时出现了如下错误: Exception in thread "main" java.lang.IllegalArgumentExcepti ...

  6. achartengine(Google给android提供的画图工具包)的介绍和使用

    AChartEngine(ACE)是Google为Android提供的一个开源绘制工具包.它集成了绘制多种图形的功能:折线图.散点图.气泡图.柱状图.饼图.仪表图等图形. 下载地址:http://do ...

  7. Cas Server源码编译现场实例

    最近公司有项目需要做单点登录,根据要求就写下这篇从github上下载的包到项目编译通过,再到修改原代码实现自己的特殊逻辑. 前提: java环境 tomcat环境 maven环境 MyEclipse开 ...

  8. 转发:centos彻底删除文件夹、文件命令(centos 新建、删除、移动、复制等命令)

    http://blog.csdn.net/lpdx111/article/details/16877725 centos彻底删除文件夹.文件命令(centos 新建.删除.移动.复制等命令: 1.新建 ...

  9. urllib2特点--超时设置

    # -*- coding: cp936 -*- #python 27 #xiaodeng #urllib2特点--超时设置 import urllib2 def urlopen(): url='htt ...

  10. java while循环语句

    //循环语句 //符合条件,循环继续执行,否则循环退出. //特点: //先判断,后执行 public class Test16{ public static void main(String arg ...