导读 MySQL 5.7 版本的发布,也就是说从现在开始5.7已经可以在生产环境中使用,有任何问题官方都将立刻修复。

MySQL 5.7主要特性:

原生支持Systemd
更好的性能:对于多核CPU、固态硬盘、锁有着更好的优化
更好的InnoDB存储引擎
更为健壮的复制功能:复制带来了数据完全不丢失的方案,传统金融客户也可以选择使用MySQL数据库。此外,GTID在线平滑升级也变得可能
更好的优化器:优化器代码重构的意义将在这个版本及以后的版本中带来巨大的改进,Oracle官方正在解决MySQL之前最大的难题
原生JSON类型的支持
更好的地理信息服务支持:InnoDB原生支持地理位置类型,支持GeoJSON,GeoHash特性
新增sys库:以后这会是DBA访问最频繁的库
MySQL 5.7已经作为数据库可选项添加到 OneinStack -- lnmp 安装工具中

安装依赖包
yum -y install make gcc-c++ cmake bison-devel ncurses-devel
下载mysql源码包

源码包有两种版本 :
mysql-5.7.11.tar.gz 不带 boost库 ,需要自行下载。

mysql-boost-5.7.11.tar.gz 自带 boost库,在解压后的根目录,推荐下载。

wget http://cdn.mysql.com/Downloads/MySQL-5.7/mysql-boost-5.7.11.tar.gz

curl -O http://cdn.mysql.com/Downloads/MySQL-5.7/mysql-boost-5.7.11.tar.gz

tar -zxf mysql-boost-5.7.11.tar.gz

cd mysql-5.7.11

编译

生成makefile

 

cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \ [字符集]
-DDEFAULT_COLLATION=utf8_general_ci \ [排序规则 必须有,不然初始化数据库困难]
-DDOWNLOAD_BOOST=1 \ [从MySQL 5.7.5开始Boost库是必需的]
-DWITH_BOOST=/root/mysql-5.7.11/boost \
-DWITH_SYSTEMD=1 [支持Systemd]
加上-DWITH_SYSTEMD=1可以使用systemd控制mysql服务,默认是不开启systemd的。

然后

make -j 2 && make install

mysql将会安装到/usr/local/mysql路径
慢慢等……

配置MySQL
添加mysql用户和组
groupadd mysql

useradd -g mysql -s /sbin/nologin mysql

修改/usr/local/mysql权限
chown -R mysql:mysql /usr/local/mysql
创建 mysql PID 默认目录

在 mysqld.service ,把默认的pid文件指定到了 /var/run/mysqld/ 目录,而并没有事先建立该目录,因此要手动建立该目录并把权限赋给 mysql 用户。

mkdir -p /var/run/mysqld
chown mysql:mysql /var/run/mysqld
mysql 三个运行文件默认位置
log : /var/log/mysqld.log
pid : /var/run/mysqld/mysqld.pid
sock : /tmp/mysql.sock
拷贝 my.cnf 和 mysqld.service
cp support-files/my-default.cnf /etc/my.cnf

mysql 5.7 默认将 mysqld.service (/usr/local/mysql/)文件安装到了 mysql 安装目录下的 usr/lib/systemd/system/,将 mysqld.service 复制到/usr/lib/systemd/system/目录下

[root@localhost]/usr/local/mysql#cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system
添加环境变量

-- 编辑/etc/profile文件在最后添加如下两行 --

 

vim /etc/profile

PATH=/usr/local/mysql/bin:$PATH
export PATH

source /etc/profile

初始化 无密码 mysql 数据库
bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
bin/mysql_ssl_rsa_setup

出现下列内容,初始化成功
2016-02-22T03:56:27.254356Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

-–initialize 会生成一个随机密码(保存在~/.mysql_secret),而 -–initialize-insecure 不会生成密码,在MySQL安全配置向导mysql_secure_installation设置密码时,可自由选择 mysql 密码等级。

-–datadir目标目录下不能有数据文件。

之前版本初始化程序 mysql_install_db 是在 /usr/local/mysql/script 下,并会在将来被移除,转而使用mysqld替代 已被废弃 mysql5.7 放在了 /usr/local/mysql/bin 目录下。

启动 mysql

systemctl start mysqld.service

systemctl status mysqld.service

运行 MySQL安全配置向导mysql_secure_installation 设置密码,mysql 服务启动后才可执行

a)为root用户设置密码
b)删除匿名账号
c)取消root用户远程登录
d)删除test库和对test库的访问权限
e)刷新授权表使修改生效

[root@localhost mysql]# mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password. [使用空密码连接到MySQL]

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?[VALIDATE密码插件可以被用来测试密码
并提高安全性。你是否想设置VALIDATE密码插件?]

Press y|Y for Yes, any other key for No: y

There are three levels of password validation policy: [有三种级别的密码验证策略:]

LOW Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file
[最小长度> = 8
中等长度> = 8,数字,大小写混合和特殊字符
最长长度> = 8,数字,混合大小写,特殊字符和字典文件]

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0 [请输入0 =低,1 =中2 =强:0]
Please set the password for root here. [请在这里设置root用户的​​密码。]

New password: [新密码:]

Re-enter new password: [重新输入新密码:]

Estimated strength of the password: 25 [密码的估计强度:25]
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y [您是否希望继续与提供的密码(按y | Y表示是,因为没有任何其他键):Y?]
... Failed! Error: Your password does not satisfy the current policy requirements [ ... 失败!错误:您的密码不符合当前的要求]

New password:

Re-enter new password:

Estimated strength of the password: 50 [密码的估计强度:50]
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
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. [默认情况下,MySQL安装有一个匿名用户,
允许任何人登录到MySQL.]

Remove anonymous users? (Press y|Y for Yes, any other key for No) : 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. [通常情况下,Root 只允许其进行'localhost'(本地) 连接
。]

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n [禁止远程root登录?]

... skipping. [...跳过。]
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. [默认情况下,MySQL带有一个名为“测试”数据库,任何人都可以访问。这也是仅用于测试,并且应该移动到生产之前被删除环境。]

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : n [删除测试数据库和访问权限?]

... skipping. [ ...跳过。]
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately. [刷新授权表以确保所有的变化取得将立即生效。]

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : [现在刷新授权表?]

... skipping.
All done! [全部完成!]

开放 Root 远程连接权限
mysql -u root -p mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION; [password 为远程连接密码] mysql>FLUSH PRIVILEGES; [刷新权限]

本文转载自:http://www.linuxprobe.com/centos7-2-systemd-mysql5-7-11.html

更多Linux干货请访问:http://www.linuxprobe.com/

Centos7.2 Systemd 方式编译 Mysql5.7.11的更多相关文章

  1. centos7上源码安装mysql5.7.11

    由于初学,安装这玩意搞了三天,其间各种报错难以解决,网上各种解答误导.最好的办法还是使用官方的英文文档,建议初学者一定要使用官方的文档,特别是下面两个页面作为初学者一定要细看: Installing ...

  2. CentOS7下yum方式安装mysql5.6

    在Centos7中用MariaDB代替了mysql数据库.所以在新安装MySQL前必须做好对系统的清理工作. 一.清理CentOS7下的MariaDB. [root@localhost ~]#rpm ...

  3. centos7下yum方式安装MySQL5.7

    前言: MySQL作为一款免费.开源数据库产品,已经问世就饱受关注,很多中小企业甚至是大企业都钟爱MySQL,随着大数据的不断发展,我们接触的信息量也越来越多,虽然NoSQL是大数据的宠儿,但MySQ ...

  4. 在centos7中离线方式安装mysql5.7

    第一步:下载mysql 在Linux终端使用wget命令下载网络资源:(可以先下好) wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.17 ...

  5. CentOS7系统yum方式安装MySQL5.7

    参考:https://www.cnblogs.com/bigbrotherer/p/7241845.html#top 1.在CentOS中默认安装有MariaDB,这个是MySQL的分支,但为了需要, ...

  6. centos7使用yum方式安装MySQL5.7

    yum -y localinstall http://mirrors.ustc.edu.cn/mysql-repo/mysql57-community-release-el7.rpm yum inst ...

  7. CentOS_5.6下使用cmake编译MySQL_5.5.11

    MySQL 最新的版本5.5.11需要cmake编译安装,估计以后的版本也会采用这种方式,网上找了一些安装方法有些地方是错的,自己整理一份 所以特地记录一下安装步骤及过程,以供参考!1 mysql 5 ...

  8. CentOS_5.6下使用cmake编译MySQL_5.5.11教程

    注:资料来自网络    Centos 5.6编译安装mysql 5.5.11 2011年06月24日 星期五 05:33 MySQL 最新的版本5.5.11需要cmake编译安装,估计以后的版本也会采 ...

  9. centos7.x下环境搭建(一)--yum方式安装mysql5.7

    前两天因为数据库被黑客攻击,导致数据被删除,数据库被损坏,系统重新安装了一下,所以环境也需要重新再搭一遍,包括mysql.nodejs.git.nginx和redis的安装.由于之前安装的mysql安 ...

随机推荐

  1. Log4Net 配置SQL2008数据库 并传入自定义业务对象

    最近根据业务需要,俺们老大要求我们了解一个c#的组件——Log4Net 这玩意儿从来没弄过,感觉挺深奥的,结果经过2天的研究,还算小有所成吧,基本思路已经清晰明了了,不过过程中遇到一些很奇葩的问题,和 ...

  2. Trying to hack Redis via HTTP requests

    Trying to hack Redis via HTTP requests Context Imagine than you can access a Redis server via HTTP r ...

  3. google protobuf ios开发使用

    简介: protobuf 即 google protocol buffer 是一种数据封装格式协议: 比如其他经常用的xml,json等格式:protobuf的优势是效率高,同样的一份数据使用prot ...

  4. JsTree

    一.JStree的简单介绍 1.关于jstree jsTree 使用了 jQuery 和 Sarissa,是一个是免费的但是设置灵活的,基于 JavaScript 跨浏览器支持的网页树形部件. jsT ...

  5. 常用git命令及问题解决方法

    使用git不久,在这里记录使用git的命令. 1.将本地项目上传git git端 1.[start a project]新建一个项目 example 客户端 1.git init 初始化本地git仓库 ...

  6. c/c++ 软件集成 安装和可卸载软件

    作为一个工程师应具备的一些能力: 1. 首先具备这款软件:  >inno  Setup      免费版还开源,良心货,妥妥的. 2. 这款软件上手也比较款,可自行参考使用文档 3.编译成功,生 ...

  7. 转---- javascript prototype介绍的文章

    JavaScript是基于对象的,任何元素都可以看成对象.然而,类型和对象是不同的.本文中,我们除了讨论类型和对象的一些特点之外,更重要的是研究如何写出好的并且利于重用的类型.毕竟,JavaScrip ...

  8. yii2.0高级框架配置时打开init.bat秒退的解决方法 (两种方法)

    第一种: 这几天刚接触到yii2.0框架,在配置advanced版本时运行init.bat初始化文件时老是闪退: 用cmd运行该文件时显示:The OpenSSL PHP extension is r ...

  9. apache commons工具包

    javqa中,有时候,我们需要重写类的hashCode()和toString()方法,自己去实现,太麻烦. 我们可以用apache的commons工具类来实现. hashCode(): @overri ...

  10. [CQOI 2014] 数三角形 & 机械排序臂

    数三角形 bzoj 3505 要知道一个公式就是(a,b)和(x,y)两点所成线段上面的整点数是gcd(a-x,b-y)-1,通过枚举原点到map上任意一点所能成的三角形,再平移,得到要去掉的三点共线 ...