您现在的位置是:网站首页 > 代码编程 > 服务器服务器

【原】linux环境下mysql5.7二进制方式安装教程

不忘初心 不忘初心 2017-10-10 围观() 评论() 点赞() 服务器

简介:在之前的文章中,我们讲过了如何在windows环境下安装绿色版的mysql,在linux环境中,除了使用yum来安装,还可以使用二进制方式来安装mysql,也相

在之前的文章中,我们讲过了如何在windows环境下安装绿色版的mysql5.7,在linux环境中,除了使用 yum 来安装,还可以使用二进制方式来安装mysql,也相当于是绿色版。

打开官网,进入到下载页 http://dev.mysql.com/downloads/mysql,滚动到最下面,找到linux版本的安装包下载下来(上篇文章中已经截图描述过了,这里就不再细说)。

本文以 mysql-5.7.17 版本为例,linux版本是 CentOS 7.3 64位,由于是linux环境中,可以直接使用wget下载

[root@jdu4e00u53f7 soft]# wget http://downloads.mysql.com/archives/get/file/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz

使用tar命令解压,复制到 /usr/local 下面

[root@jdu4e00u53f7 soft]# tar -zxvf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz

注意:在linux上安装很多软件时,默认配置中的目录都是 /usr/local,所以建议自己安装时也放到此目录,可以省去很多麻烦。

解压完毕,进入到mysql目录

[root@jdu4e00u53f7 soft]# cd /usr/local/mysql/

创建用户组,名字不一定非要叫“mysql”

[root@jdu4e00u53f7 mysql]# groupadd mysql

创建用户,名字不一定非要叫“mysql”,后面两个参数,第一个是组名,第二个是用户名

[root@jdu4e00u53f7 mysql]# useradd -r -g mysql mysql

给用户组和用户赋权,否则会导致后面的操作权限不够

[root@jdu4e00u53f7 mysql]# chown -R mysql:mysql /usr/local/mysql

设置环境变量,也可以直接修改 /ect/profile 文件

[root@jdu4e00u53f7 mysql]# export PATH=/usr/local/mysql/bin:$PATH

查看变量是否设置成功

[root@jdu4e00u53f7 mysql]# echo $PATH
/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

安装db文件,此命令必须在mysql目录下执行,前几个命令不在mysql目录下没有关系

[root@jdu4e00u53f7 mysql]# ./bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/

收到了一记暴击,直接秒秒钟安装失败

2017-10-11 15:54:29 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2017-10-11 15:54:29 [ERROR]   Child process: /usr/local/mysql/bin/mysqldterminated prematurely with errno= 32
2017-10-11 15:54:29 [ERROR]   Failed to execute /usr/local/mysql/bin/mysqld --bootstrap --datadir=/usr/local/mysql/data --lc-messages-dir=/usr/local/mysql/share --lc-messages=en_US --basedir=/usr/local/mysql
-- server log begin --

-- server log end --

mysql_install_db is deprecated,命令过期,查阅资料发现,5.7版本以上需要使用 mysqld --initialize 命令

so,赶紧切换命令,却又收到一记暴击,再次失败

[root@jdu4e00u53f7 mysql]# ./bin/mysqld --initialize
./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

查看错误信息,libaio.so这个东西缺失了,这到底是个啥东西?

查阅资料后发现,这个东西是linux环境下的异步IO机制,虽然不知道为啥要这个,但是既然少了,那就安装一个,直接yum即可

[root@jdu4e00u53f7 mysql]# yum install -y libaio
Loaded plugins: fastestmirror
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
base                                                                                                                                           | 3.6 kB  00:00:00     
extras                                                                                                                                         | 3.4 kB  00:00:00     
updates                                                                                                                                        | 3.4 kB  00:00:00     
(1/4): base/7/x86_64/group_gz                                                                                                                  | 156 kB  00:00:00     
(2/4): extras/7/x86_64/primary_db                                                                                                              | 110 kB  00:00:00     
(3/4): updates/7/x86_64/primary_db                                                                                                             | 2.7 MB  00:00:00     
(4/4): base/7/x86_64/primary_db                                                                                                                | 5.7 MB  00:00:00     
Determining fastest mirrors
Resolving Dependencies
--> Running transaction check
---> Package libaio.x86_64 0:0.3.109-13.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

======================================================================================================================================================================
 Package                               Arch                                  Version                                        Repository                           Size
======================================================================================================================================================================
Installing:
 libaio                                x86_64                                0.3.109-13.el7                                 base                                 24 k

Transaction Summary
======================================================================================================================================================================
Install  1 Package

Total download size: 24 k
Installed size: 38 k
Downloading packages:
libaio-0.3.109-13.el7.x86_64.rpm                                                                                                               |  24 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : libaio-0.3.109-13.el7.x86_64                                                                                                                       1/1 
  Verifying  : libaio-0.3.109-13.el7.x86_64                                                                                                                       1/1 

Installed:
  libaio.x86_64 0:0.3.109-13.el7                                                                                                                                      

Complete!

再来一次安装命令

[root@jdu4e00u53f7 mysql]# ./bin/mysqld --initialize
2017-10-11T08:31:03.947580Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-10-11T08:31:04.567507Z 0 [Warning] InnoDB: New log files created, LSN=45790
2017-10-11T08:31:04.682456Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-10-11T08:31:04.741489Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 8576f7de-ae5e-11e7-a7c2-fa163e0ba239.
2017-10-11T08:31:04.742847Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2017-10-11T08:31:04.743794Z 1 [Note] A temporary password is generated for root@localhost: +AqqV*AXy7Ih

没有[ERROR]信息,貌似可以了,此处再来一次暴击,启动不起来

[root@jdu4e00u53f7 mysql]# ./support-files/mysql.server start
Starting MySQL... ERROR! The server quit without updating PID file (/usr/local/mysql/data/jdu4e00u53f7.pid).

跑到 /user/data 下面一看,别说 pid 文件不存在,好家伙,毛都没有,并没有生成mysql的系统文件,比对了一下 mysql_install_db 命令,好像我们并没有手动指定系统文件位置,不知道它把文件生成到哪里去了

[root@jdu4e00u53f7 mysql]# ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/
2017-10-12T01:36:56.956816Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-10-12T01:36:56.956886Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2017-10-12T01:36:56.956893Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
2017-10-12T01:36:57.235696Z 0 [Warning] InnoDB: New log files created, LSN=45790
2017-10-12T01:36:57.288768Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-10-12T01:36:57.348650Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: d5ad7526-aeed-11e7-9c55-fa163e0ba239.
2017-10-12T01:36:57.349765Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2017-10-12T01:36:57.350646Z 1 [Note] A temporary password is generated for root@localhost: Hu*B2HshcFvg

注意:最后一行,给出了root的默认密码,最好记一下,方便后面修改密码

再次执行安装命令,除了这次的信息多了几行,并没有其他错误信息,保险起见,还是去文件夹里面看一下

[root@jdu4e00u53f7 mysql]# ll data
total 110628
-rw-r----- 1 mysql mysql       56 Oct 11 16:55 auto.cnf
-rw-r----- 1 mysql mysql      413 Oct 11 16:55 ib_buffer_pool
-rw-r----- 1 mysql mysql 12582912 Oct 11 16:55 ibdata1
-rw-r----- 1 mysql mysql 50331648 Oct 11 16:55 ib_logfile0
-rw-r----- 1 mysql mysql 50331648 Oct 11 16:55 ib_logfile1
drwxr-x--- 2 mysql mysql     4096 Oct 11 16:55 mysql
drwxr-x--- 2 mysql mysql     8192 Oct 11 16:55 performance_schema
drwxr-x--- 2 mysql mysql     8192 Oct 11 16:55 sys

系统文件已经生成出来了,增加一个my.cnf文件(低版本中,系统文件中包含my.cnf文件)

# 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.

[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.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....

# 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 

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 

basedir = /usr/local/mysql
datadir = /usr/local/mysql/data

innodb_file_per_table = 1

#skip-grant-tables = 1

复制 my.cnf 到 /ect/my.cnf,当做默认启动文件(/etc下面可能有my.cnf,直接覆盖掉)

[root@jdu4e00u53f7 mysql]# cp my.cnf /etc/my.cnf

走到这一步,基本上就安装完了,启动服务

[root@jdu4e00u53f7 mysql]# ./support-files/mysql.server start
Starting MySQL. SUCCESS! 
[root@jdu4e00u53f7 mysql]# ps -ef|grep mysql
root      2963     1  0 17:06 pts/0    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/jdu4e00u53f7.pid
mysql     3153  2963  2 17:06 pts/0    00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/jdu4e00u53f7.err --pid-file=/usr/local/mysql/data/jdu4e00u53f7.pid
root      3190 29339  0 17:07 pts/0    00:00:00 grep --color=auto mysql

如果想关闭服务,直接将上面命令中的 start 换成 stop 

[root@jdu4e00u53f7 mysql]# ./support-files/mysql.server stop
Shutting down MySQL.. SUCCESS!

上面的命令,十分繁琐,可以将 mysql.server 添加到系统级服务里面,这样就可以简化输入

[root@jdu4e00u53f7 mysql]# cp support-files/mysql.server /etc/init.d/mysql
[root@jdu4e00u53f7 mysql]# service mysql start
Starting MySQL. SUCCESS! 
[root@jdu4e00u53f7 mysql]# service mysql stop
Shutting down MySQL.. SUCCESS!

至此,linux环境下的mysql-5.7.17就已经安装完毕了!

mysql5.7mysql二进制linux mysql

看完文章,有任何疑问,请加入群聊一起交流!!!

很赞哦! ()

文章评论

  • 请先说点什么
    人参与,条评论

请使用电脑浏览器访问本页面,使用手机浏览器访问本页面会导致下载文件异常!!!

雨落无影

关注上方公众号,回复关键字【下载】获取下载码

用完即删,每次下载需重新获取下载码

若出现下载不了的情况,请及时联系站长进行解决

站点信息

  • 网站程序:spring + freemarker
  • 主题模板:《今夕何夕》
  • 文章统计:篇文章
  • 标签管理标签云
  • 微信公众号:扫描二维码,关注我们