MySQL 5.7.19 编译安装与配置
<!-- 作者区域 -->
<div class="author">
<a class="avatar" href="/u/6196900dec0f">
<img src="//upload.jianshu.io/users/upload_avatars/7351260/047bb37f-7f00-44e0-a26a-021d5c7e4aed.jpg?imageMogr2/auto-orient/strip|imageView2/1/w/96/h/96" alt="96">
pijh
关注
2017.09.24 11:53*
字数 1994
阅读 4709
喜欢 6
<!-- 文章内容 -->
<div data-note-content="" class="show-content">
<div class="show-content-free">
<blockquote>
背景:本人博客 自2014年上线以来,一直使用阿里云ECS
最低配的实例,由于最近阿里云ECS
进行了升级迁移,原来的低配实例已经不存在了,升级后实例的配置有所提升,当然价格更高了,为了更好的发挥服务器性能,所以就想利用空闲时间对整站进行升级,包含阿里云ecs更换系统盘
,MySQL 5.7.19 编译安装与配置
, Nginx 1.12.1 编译安装与配置
, PHP 7.1.9 编译安装与配置
等。
服务器环境 CentOS 6.3 64位 全新纯净的系统
/ 1核1GB
/ 经典网络 1MB
进入MySQL Community Edition下载页面
点击进入MySQL Community Edition下载页面
选择操作系统为Source Code
,选择操作系统版本为Generic Linux
,选择Compressed TAR Archive, Includes Boost Headers
版本或Compressed TAR Archive
版本,暂未研究两个版本的区别,开始以为Includes Boost Headers不用再去下载Boost库,然而安装时发现还是需要,所以此处先任意选择一个版本,选择点击 Download 进行下载
进入/usr/local/src
目录,一般我喜欢把下载的文件放在此目录,根据自己的喜好设定
[root@iZ2864f6btwZ src]# cd /usr/local/src
下载MySQL文件,如果wget没有安装,yum -y install wget
即可安装
[root@iZ2864f6btwZ src]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.19.tar.gz
问题错误: 如果此处下载遇到如下问题,说明你没有安装openssl,此问题一般只会出现在全新的机器上 [root@iZ2864f6btwZ src]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.19.tar.gz--2017-09-22 16:20:26-- https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.19.tar.gz Resolving dev.mysql.com (dev.mysql.com)... 137.254.60.11 Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:443... connected. Unable to establish SSL connection.
解决方案: 安装opensll,yum -y install openssl
再次执行下载命令即可
由于MySQL 5.7需要boost 1.59以及以上版本,所以还需要下载boost库,根据本人测试1.59版本的最为适合,其它高版本在安装的时候遇到了一些问题,目前未解决;下载地址 ,你也可以点击此处 直接下载boost_1_59_0.tar.gz
,如果wget无法下载,建议使用迅雷下载后再上传到服务器目录
[root@iZ2864f6btwZ src]# wget http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
解压 boost并拷贝 boost 到 /usr/local/boost 目录
[root@iZ2864f6btwZ src]
[root@iZ2864f6btwZ src]
安装编译所需的常用组件和依赖包 [ 参考于网络博客 ]
[root@iZ2864f6btwZ src]# yum -y install gcc gcc-c++ ncurses ncurses-devel bison libgcrypt perl make cmake
创建mysql用户组和用户,用来运行mysql服务器, -g
指定用户组, -r
创建系统用户
[root@iZ2864f6btwZ src]
[root@iZ2864f6btwZ src]
解压MySQL,进入 mysql-5.7.19 目录
[root@iZ2864f6btwZ src]
[root@iZ2864f6btwZ src]
新建MySQL安装所需要目录
[root@iZ2864f6btwZ mysql-5.7.19]# mkdir -p /usr/local/mysql /usr/local/mysql/{data,logs,pids}
修改 /usr/local/mysql 目录所有者权限
[root@iZ2864f6btwZ mysql-5.7.19]# chown -R mysql:mysql /usr/local/mysql
使用cmake命令进行编译
[root@iZ2864f6btwZ mysql-5.7.19]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_TCP_PORT=3306 -DMYSQL_USER=mysql -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DENABLE_DOWNLOADS=1 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost
使用make命令进行编译,接下来你将经历漫长的等待~
[root@iZ2864f6btwZ mysql-5.7.19]# make
问题错误: 编译出现错误,查询得知可能是由于内存不足导致的
解决方案: 临时增加交换空间 ( 虚拟内存 )
[root@iZ2864f6btwZ mysql-5.7 .19 ]
2048000 +0 records in
2048000 +0 records out
2097152000 bytes (2.1 GB) copied, 34.6782 s, 60.5 MB/s
[root@iZ2864f6btwZ mysql-5.7 .19 ]
Setting up swapspace version 1 , size = 2047996 KiB
no label, UUID=56026239 -26 e6-40 d9-b080 -b95acd9db058
[root@iZ2864f6btwZ mysql-5.7 .19 ]
swapon: /swapfile: insecure permissions 0644 , 0600 suggested.
[root@iZ2864f6btwZ mysql-5.7 .19 ]
查看创建的交换空间
[root@iZ2864f6btwZ mysql-5.7 .19 ]# free -m
total used free shared buff/cache available
Mem: 992 51 70 0 869 789
Swap: 1999 0 1999
继续执行make
命令
[root@iZ2864f6btwZ mysql-5.7 .19 ]
[root@iZ2864f6btwZ mysql-5.7 .19 ]
如果你编译完成后不再想要此交换空间,你可以执行如下命令:
[root@iZ2864f6btwZ mysql-5.7 .19 ]
[root@iZ2864f6btwZ mysql-5.7 .19 ]
温馨提示: MySQL编译过程等待时间会比较久,有时都以为是“卡”住了,你可以使用top
命令查看资源状态,看看cc1plus、make等进程是否在跳动,如果有跳动说明安装还在继续,由于我的 ecs 配置较低,此过程大约经历了几个小时,特别是在29%和74%的时候,几乎都要快放弃了, 如果有经济的能力的话,建议服务器配置还是尽量买高一点。 [root@iZ2864f6btwZ mysql-5.7.19]# top
make编译完成
编译完成后执行 make install
进行安装
[root@iZ2864f6btwZ mysql-5.7.19]# make install
将mysql添加到环境变量,修改/etc/profile文件,在文件最末尾添加export PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
[root@iZ2864f6btwZ mysql-5.7 .19 ]
...
unset i
unset -f pathmunge
export PATH=/usr/local /mysql/bin :/usr/local/mysql/lib : $PATH
更新配置文件
[root@iZ2864f6btwZ mysql-5.7.19]# source /etc/profile
初始化数据库, –initialize 表示默认生成一个安全的密码,–initialize-insecure 表示不生成密码
[root@iZ2864f6btwZ mysql-5.7.19]# mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
将mysql服务文件拷贝到/etc/init.d/
目录,并给出执行权限
[root@iZ2864f6btwZ mysql-5.7 .19 ]
[root@iZ2864f6btwZ mysql-5.7 .19 ]
将MySQL并加入开机自动启动
[root@iZ2864f6btwZ mysql-5.7 .19 ]
[root@iZ2864f6btwZ mysql-5.7 .19 ]
[root@iZ2864f6btwZ mysql-5.7 .19 ]
Note: This output shows SysV services only and does not include native systemd services. SysV configuration data might be overridden by native systemd configuration.
If you want to list systemd services use <span class="hljs-string">'systemctl list-unit-files'</span>.
To see services enabled on particular target use
<span class="hljs-string">'systemctl list-dependencies [target]'</span>.
mysqld 0 :off 1 :off 2 :on 3 :on 4 :on 5 :on 6 :off
修改/etc/my.cnf
文件,编辑配置文件如下,仅供参考
[root@iZ2864f6btwZ mysql-5.7.19]
[mysqld] datadir=/usr/local /mysql/data socket=/usr/local /mysql/mysql.sock
[mysqld_safe] log -error=/usr/local /mysql/logs/mysqld.log pid-file=/usr/local /mysql/pids/mysqld.pid
symbolic-links=0
[client] default-character-set=utf8 socket=/usr/local /mysql/mysql.sock
[mysql] default-character-set=utf8 socket=/usr/local /mysql/mysql.sock
!includedir /etc/my.cnf.d
启动MySQL
[root@iZ2864f6btwZ local ]
Starting MySQL.2017-09-23T16:13:16.049373Z mysqld_safe error: log -error set to '/usr/local/mysql/logs/mysqld.log' , however file don't exists. Create writable for user ' mysql'.
The server quit without updating PID file (/usr/local/mysql[FAILED]2864f6btwZ.pid).
问题错误: 由于缺少 mysqld.log
和 mysqld.pid
文件导致无法正常启动
解决方案: 创建 mysqld.log
和 mysqld.pid
文件
[root@iZ2864f6btwZ mysql-5.7 .19 ]
[root@iZ2864f6btwZ mysql-5.7 .19 ]
修改 /usr/local/mysql 的权限 [root@iZ2864f6btwZ mysql-5.7.19]# chown mysql.mysql -R /usr/local/mysql/
再次启动MySQL [root@iZ2864f6btwZ local]# service mysqld start
查看MySQL运行状态
[root@iZ2864f6btwZ local]
MySQL is not running, but lock file (/var/lock /subsys/mysql [FAILED]
问题错误: MySQL is not running, but lock file (/var/lock/subsys/mysql[FAILED]
解决方案: 删除/var/lock/subsys/mysql
文件,重新启动MySQL
[root@iZ2864f6btwZ local ]
[root@iZ2864f6btwZ local ]
Starting MySQL. [ OK ]
连接MySQL
[root@iZ2864f6btwZ mysql-5.7 .19 ]
ERROR 2002 (HY000 ): Can't connect to local MySQL server through socket ' /tmp/mysql.sock' (2)
[root@iZ2864f6btwZ mysql-5.7.19]#
问题错误: /etc/my.cnf 文件配置不正确 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
解决方案: 参考上述步骤 修改 /etc/my.cnf 文件
[root@iZ2864f6btwZ local]
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7 .19 Source distribution
Copyright © 2000 , 2017 , 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>
查看数据库,如果看到以下几个数据库说明数据库初始化成功
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0 .00 sec)
mysql>
进入mysql库,查看用户表信息
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed mysql> mysql> select host,user,password from user; ERROR 1054 (42 S22): Unknown column ‘password’ in ‘field list’ mysql>
问题错误: ERROR 1054 (42S22): Unknown column 'password' in 'field list'
解决方案: 由于MySQL 5.7版本下的mysql数据库下已经没有password这个字段了,password字段改成了authentication_string,查询时使用authentication_string字段即可
mysql> select host,user,authentication_string from user;
+-----------+---------------+-------------------------------------------+
| host | user | authentication_string |
+-----------+---------------+-------------------------------------------+
| localhost | root | |
| localhost | mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| localhost | mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
+-----------+---------------+-------------------------------------------+
3 rows in set (0 .00 sec)
设置密码(推荐),注意此方法必须使用flush privileges
命令刷新一下权限才能生效
mysql> UPDATE user SET authentication_string=PASSWORD('newpassword' ) WHERE user='root' ;
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
mysql>
另外一种方法可以快速密码,但此方法设置的密码使用history
命令可以看到,所以不太推荐
[root@iZ2864f6btwZ ~]
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
结尾: 至此,MySQL 5.7.19 编译安装及配置已经全部完成,有疑问的朋友可以给我留言,若有毛病,欢迎指正。
</div>
</div>
</div>
<!-- 如果是付费文章,未购买,则显示购买按钮 -->
<!-- 连载目录项 -->
<!-- 如果是付费文章 -->
<!-- 如果是付费连载,已购买,且作者允许赞赏,则显示付费信息和赞赏 -->
<div id="free-reward-panel" class="support-author"><p>坚持创作简单易懂的文章,喜欢就打赏一下吧!</p> <div class="btn btn-pay">赞赏支持</div> <div class="supporter"><ul class="support-list"></ul> <!----></div> <!----> <!----></div>
<div class="show-foot">
<a class="notebook" href="/nb/15327428">
<i class="iconfont ic-search-notebook"></i>
<span>LNMP</span>
© 著作权归作者所有
<!-- 文章底部作者信息 -->
<div class="follow-detail">
<div class="info">
<a class="avatar" href="/u/6196900dec0f">
<img src="//upload.jianshu.io/users/upload_avatars/7351260/047bb37f-7f00-44e0-a26a-021d5c7e4aed.jpg?imageMogr2/auto-orient/strip|imageView2/1/w/96/h/96" alt="96">
关注 pijh
写了 9101 字,被 6 人关注,获得了 26 个喜欢
PHP开发者
<div class="meta-bottom">
<div data-v-6ddd02c6="" class="like"><div data-v-6ddd02c6="" class="btn like-group"><div data-v-6ddd02c6="" class="btn-like"><a data-v-6ddd02c6="">喜欢</a></div> <div data-v-6ddd02c6="" class="modal-wrap"><a data-v-6ddd02c6="">6</a></div></div> <!----></div>
<div class="share-group">
<a class="share-circle" data-action="weixin-share" data-toggle="tooltip" data-original-title="分享到微信">
<i class="iconfont ic-wechat"></i>
</a>
<a class="share-circle" data-action="weibo-share" data-toggle="tooltip" href="javascript:void((function(s,d,e,r,l,p,t,z,c){var%20f='http://v.t.sina.com.cn/share/share.php?appkey=1881139527',u=z||d.location,p=['&url=',e(u),'&title=',e(t||d.title),'&source=',e(r),'&sourceUrl=',e(l),'&content=',c||'gb2312','&pic=',e(p||'')].join('');function%20a(){if(!window.open([f,p].join(''),'mb',['toolbar=0,status=0,resizable=1,width=440,height=430,left=',(s.width-440)/2,',top=',(s.height-430)/2].join('')))u.href=[f,p].join('');};if(/Firefox/.test(navigator.userAgent))setTimeout(a,0);else%20a();})(screen,document,encodeURIComponent,'','','', '推荐 @JANCE2016 的文章《MySQL 5.7.19 编译安装与配置》( 分享自 @简书 )','https://www.jianshu.com/p/4416792750c7?utm_campaign=maleskine&utm_content=note&utm_medium=reader_share&utm_source=weibo','页面编码gb2312|utf-8默认gb2312'));" data-original-title="分享到微博">
<i class="iconfont ic-weibo"></i>
</a>
<a class="share-circle" data-toggle="tooltip" id="longshare" target="_blank" data-original-title="" title="">
<div class="qrcode" id="qrcode">
<img src="//cdn2.jianshu.io/assets/web/download-index-side-qrcode-cb13fc9106a478795f8d10f9f632fccf.png" alt="Download index side qrcode">
<p>下载app生成长微博图片</p>
</div>
<i class="iconfont ic-picture"></i>
</a>
<a class="share-circle more-share" tabindex="0" data-toggle="popover" data-placement="top" data-html="true" data-trigger="focus" href="javascript:void(0);" data-content="
<ul class="share-list">
<li><a href="javascript:void(function(){var d=document,e=encodeURIComponent,r='http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url='+e('https://www.jianshu.com/p/4416792750c7?utm_campaign=maleskine&utm_content=note&utm_medium=reader_share&utm_source=qzone')+'&title='+e('推荐 pijh 的文章《MySQL 5.7.19 编译安装与配置》'),x=function(){if(!window.open(r,'qzone','toolbar=0,resizable=1,scrollbars=yes,status=1,width=600,height=600'))location.href=r};if(/Firefox/.test(navigator.userAgent)){setTimeout(x,0)}else{x()}})();"><i class="social-icon-sprite social-icon-zone"></i><span>分享到QQ空间</span></a></li>
<li><a href="javascript:void(function(){var d=document,e=encodeURIComponent,r='https://twitter.com/share?url='+e('https://www.jianshu.com/p/4416792750c7?utm_campaign=maleskine&utm_content=note&utm_medium=reader_share&utm_source=twitter')+'&text='+e('推荐 pijh 的文章《MySQL 5.7.19 编译安装与配置》( 分享自 @jianshucom )')+'&related='+e('jianshucom'),x=function(){if(!window.open(r,'twitter','toolbar=0,resizable=1,scrollbars=yes,status=1,width=600,height=600'))location.href=r};if(/Firefox/.test(navigator.userAgent)){setTimeout(x,0)}else{x()}})();"><i class="social-icon-sprite social-icon-twitter"></i><span>分享到Twitter</span></a></li>
<li><a href="javascript:void(function(){var d=document,e=encodeURIComponent,r='https://www.facebook.com/dialog/share?app_id=483126645039390&display=popup&href=https://www.jianshu.com/p/4416792750c7?utm_campaign=maleskine&utm_content=note&utm_medium=reader_share&utm_source=facebook',x=function(){if(!window.open(r,'facebook','toolbar=0,resizable=1,scrollbars=yes,status=1,width=450,height=330'))location.href=r};if(/Firefox/.test(navigator.userAgent)){setTimeout(x,0)}else{x()}})();"><i class="social-icon-sprite social-icon-facebook"></i><span>分享到Facebook</span></a></li>
<li><a href="javascript:void(function(){var d=document,e=encodeURIComponent,r='https://plus.google.com/share?url='+e('https://www.jianshu.com/p/4416792750c7?utm_campaign=maleskine&utm_content=note&utm_medium=reader_share&utm_source=google_plus'),x=function(){if(!window.open(r,'google_plus','toolbar=0,resizable=1,scrollbars=yes,status=1,width=450,height=330'))location.href=r};if(/Firefox/.test(navigator.userAgent)){setTimeout(x,0)}else{x()}})();"><i class="social-icon-sprite social-icon-google"></i><span>分享到Google+</span></a></li>
<li><a href="javascript:void(function(){var d=document,e=encodeURIComponent,s1=window.getSelection,s2=d.getSelection,s3=d.selection,s=s1?s1():s2?s2():s3?s3.createRange().text:'',r='http://www.douban.com/recommend/?url='+e('https://www.jianshu.com/p/4416792750c7?utm_campaign=maleskine&utm_content=note&utm_medium=reader_share&utm_source=douban')+'&title='+e('MySQL 5.7.19 编译安装与配置')+'&sel='+e(s)+'&v=1',x=function(){if(!window.open(r,'douban','toolbar=0,resizable=1,scrollbars=yes,status=1,width=450,height=330'))location.href=r+'&r=1'};if(/Firefox/.test(navigator.userAgent)){setTimeout(x,0)}else{x()}})()"><i class="social-icon-sprite social-icon-douban"></i><span>分享到豆瓣</span></a></li>
</ul>
" data-original-title="" title="">更多分享</a>
</div>
</div>
<a id="web-note-ad-1" target="_blank" href="/apps/redirect?utm_source=note-bottom-click"><img src="//cdn2.jianshu.io/assets/web/web-note-ad-1-c2e1746859dbf03abe49248893c9bea4.png" alt="Web note ad 1"></a>
<!--
<div id="note-comment-above-ad-container">
<span id="youdao-comment-ad" class="ad-badge">广告</span>
</div>
-->
<div><div id="comment-list" class="comment-list"><div><form class="new-comment"><a class="avatar"><img src="//cdn2.jianshu.io/assets/default_avatar/avatar_default-78d4d1f68984cd6d4379508dd94b4210.png"></a> <div class="sign-container"><a href="/sign_in?utm_source=desktop&utm_medium=not-signed-in-comment-form" class="btn btn-sign">登录</a> <span>后发表评论</span></div></form> <!----></div> <!----> <div class="comments-placeholder" style="display: none;"><div class="author"><div class="avatar"></div> <div class="info"><div class="name"></div> <div class="meta"></div></div></div> <div class="text"></div> <div class="text animation-delay"></div> <div class="tool-group"><i class="iconfont ic-zan-active"></i><div class="zan"></div> <i class="iconfont ic-list-comments"></i><div class="zan"></div></div></div> <div id="normal-comment-list" class="normal-comment-list"><div><!----> <div><div class="top-title"><span>评论</span> <a class="close-btn" style="display: none;">关闭评论</a></div> <div class="no-comment"></div> <div class="text">
智慧如你,不想<a href="/sign_in?utm_source=desktop&utm_medium=not-signed-in-nocomments-text">发表一点想法</a>咩~
</div></div> <!----> <div class="comments-placeholder" style="display: none;"><div class="author"><div class="avatar"></div> <div class="info"><div class="name"></div> <div class="meta"></div></div></div> <div class="text"></div> <div class="text animation-delay"></div> <div class="tool-group"><i class="iconfont ic-zan-active"></i><div class="zan"></div> <i class="iconfont ic-list-comments"></i><div class="zan"></div></div></div> </div></div> <!----> <div><!----></div></div></div>