CentOS7中mysql-5.7.21-el7-x86_64.tar.gz版MySQL的安装与配置

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

通常情况下,MySQL在CentOS下主要使用glibc、rpm、yum等方式进行安装,使用mysql-5.7.21-el7-x86_64.tar.gz包进行安装的很少见,网上资料也较少。通过一上午的摸索,总结出如下安装方法。

下载安装包:

[root@GeekDevOps ~]# curl -C - -O https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.21-el7-x86_64.tar.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  674M  100  674M    0     0  4311k      0  0:02:40  0:02:40 --:--:-- 4067k

创建安装账户:

[root@GeekDevOps ~]# useradd -s /bin/false -d /usr/local/mysql  mysql
[root@GeekDevOps ~]# id mysql
uid=1000(mysql) gid=1000(mysql) 组=1000(mysql)
二、安装过程
[root@GeekDevOps ~]# tar -xvzf mysql-5.7.21-el7-x86_64.tar.gz -C /usr/local/mysql/
[root@GeekDevOps mysql]# cd /usr/local/mysql/mysql-5.7.21-el7-x86_64/
[root@GeekDevOps mysql-5.7.21-el7-x86_64]# mv * ../
[root@GeekDevOps mysql-5.7.21-el7-x86_64]# cd ..
[root@GeekDevOps mysql]# rmdir mysql-5.7.21-el7-x86_64/
[root@GeekDevOps mysql]# mkdir data
[root@GeekDevOps mysql]# chown -R mysql.mysql ../mysql
[root@GeekDevOps mysql]# cd bin
[root@GeekDevOps bin]# ./mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize
[root@GeekDevOps bin]# tail -100f ../data/error.log 
2018-03-14T06:32:34.966407Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-03-14T06:32:36.208273Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-03-14T06:32:36.367294Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-03-14T06:32:36.522777Z 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: 7c405e3f-2751-11e8-8be8-000c29fb0102.
2018-03-14T06:32:36.525594Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-03-14T06:32:36.526540Z 1 [Note] A temporary password is generated for root@localhost: 7Eu;dsRqkY.3
[root@GeekDevOps bin]# cp ../support-files/mysql.server /etc/init.d/mysqld
三、配置过程
[root@GeekDevOps ~]# vi /etc/my.cnf
[mysqld]
port = 3306
basedir = /usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
pid-file=/usr/local/mysql/data/mysql.pid
log-error=/usr/local/mysql/data/error.log
character_set_server=utf8
user=mysql
max_connections=1500
symbolic-links=0
!includedir /etc/my.cnf.d
四、启动服务并登陆
[root@GeekDevOps ~]# service mysqld start
Starting MySQL. SUCCESS! 
[root@GeekDevOps mysql]# ./bin/mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.21
Copyright (c) 2000, 2018, 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> 

在此过程中要求输入密码,在第三步中我们可以看到安装完成后的密码:7Eu;dsRqkY.3,输入即可登陆成功。

五、修改密码
mysql> set password=password('GeekDevOps');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> quit
Bye

下次登录即可使用新密码进行登录。安装过程至此结束,其他配置与我之前写的glibc版的别无二致,此处不再赘述,其他配置请在my.cnf按照自己的需求进行配置。

六、安装过程中出现的问题
  1. 在安装完成之后,查看日志我们看到:TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details)。这是一个常见问题,在配置文件/etc/my.cnf的mysqld块添加:explicit_defaults_for_timestamp=1,重启数据库服务。
  2. 在完成上一步操作的过程中,查看日志发现提示:--secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled。意思是与导出、导入有关的操作都是被禁用的,我们需要导出、导入的话就需要设置,在配置文件/etc/my.cnf中mysqld下加入:secure_file_priv=/test(目录可以按需求更改),这一项也可以在安装初始化的时候加入:--secure-file-priv=/test。
七、总结

mysql-5.7.21-el7-x86_64.tar.gz该版本的MySQL安装教程在网上并不常见,我是通过tar.gz包内的文档(/usr/local/mysql/docs/INFO_BIN)受到启发才进行安装的,从文档中我们可以看到编译的详细信息。

===== Information about the build process: =====
Build was run at 2017-12-28 05:42:32 on host 'vale08'
Build was done on  Linux-4.1.12-61.1.27.el7uek.x86_64 using x86_64
Build was done using cmake 2.8.12 
 ===== Compiler flags used (from the 'sql/' subdirectory): =====
# compile C with /bin/cc
# compile CXX with /bin/c++
C_FLAGS =  -fPIC -Wall -Wextra -Wformat-security -Wvla -Wwrite-strings -Wdeclaration-after-statement -O3 -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -DDBUG_OFF -I/export/home/pb2/build/sb_0-26514852-1514435436.48/release/include -I/export/home/pb2/build/sb_0-26514852-1514435436.48/mysql-5.7.21/extra/rapidjson/include -I/export/home/pb2/build/sb_0-26514852-1514435436.48/release/libbinlogevents/include -I/export/home/pb2/build/sb_0-26514852-1514435436.48/mysql-5.7.21/libbinlogevents/export -I/export/home/pb2/build/sb_0-26514852-1514435436.48/mysql-5.7.21/include -I/export/home/pb2/build/sb_0-26514852-1514435436.48/mysql-5.7.21/sql/conn_handler -I/export/home/pb2/build/sb_0-26514852-1514435436.48/mysql-5.7.21/libbinlogevents/include -I/export/home/pb2/build/sb_0-26514852-1514435436.48/mysql-5.7.21/sql -I/export/home/pb2/build/sb_0-26514852-1514435436.48/mysql-5.7.21/sql/auth -I/export/home/pb2/build/sb_0-26514852-1514435436.48/mysql-5.7.21/regex -I/export/home/pb2/build/sb_0-26514852-1514435436.48/mysql-5.7.21/zlib -I/export/home/pb2/build/sb_0-26514852-1514435436.48/mysql-5.7.21/extra/yassl/include -I/export/home/pb2/build/sb_0-26514852-1514435436.48/mysql-5.7.21/extra/yassl/taocrypt/include -I/export/home/pb2/build/sb_0-26514852-1514435436.48/release/sql -I/export/home/pb2/build/sb_0-26514852-1514435436.48/mysql-5.7.21/extra/lz4    -DHAVE_YASSL -DYASSL_PREFIX -DHAVE_OPENSSL -DMULTI_THREADED
C_DEFINES = -DHAVE_CONFIG_H -DHAVE_LIBEVENT1 -DHAVE_REPLICATION -DMYSQL_SERVER -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
7天前
|
关系型数据库 MySQL Linux
linux CentOS 7.4下 mysql5.7.20 密码改简单的方法
linux CentOS 7.4下 mysql5.7.20 密码改简单的方法
14 0
|
7天前
|
SQL 缓存 关系型数据库
mysql性能优化-慢查询分析、优化索引和配置
mysql性能优化-慢查询分析、优化索引和配置
66 0
|
4天前
|
关系型数据库 MySQL 数据安全/隐私保护
MySQL 安装及连接
MySQL 安装及连接
22 0
|
7天前
|
网络协议
centos8 网卡 Nmcli(是network的简写 Nmcli)配置网络
centos8 网卡 Nmcli(是network的简写 Nmcli)配置网络
11 0
|
7天前
|
关系型数据库 MySQL 数据库
docker自定义安装mysql 5.7
docker自定义安装mysql 5.7
15 0
|
7天前
|
关系型数据库 MySQL Linux
CentOS 7 下使用yum安装MySQL5.7.20 最简单 图文详解
CentOS 7 下使用yum安装MySQL5.7.20 最简单 图文详解
32 0
|
7天前
|
关系型数据库 MySQL Linux
win安装mysql5.7 和安装出现的问题
win安装mysql5.7 和安装出现的问题
9 0
|
Linux 虚拟化
CentOS 7.X配置连接网络
应用场景 Linux虚拟机,系统安装完毕后,无法连接网络,由于是最小化安装,很多命令无法直接yum安装,无法连接外网wget下载资源等等,造成很大的不便,因此需要进行配置连接外网! 操作指南 1. 开启VMware NAT Service 右击“计算机”,选择“管理”,在“服务和应用程序”中,选择“服务”,在右边找到“VMware NAT Service”服务,进行开启。
1129 0
|
Linux 虚拟化 网络协议
CentOS 6.X配置连接网络
应用场景 Linux虚拟机,系统安装完毕后,无法连接网络,由于是最小化安装,很多命令无法直接yum安装,无法连接外网wget下载资源等等,造成很大的不便,因此需要进行配置连接外网! 操作指南 1. 开启VMware NAT Service 右击“计算机”,选择“管理”,在“服务和应用程序”中,选择“服务”,在右边找到“VMware NAT Service”服务,进行开启。
802 0
|
1月前
|
Linux 网络安全 数据安全/隐私保护
如何在 VM 虚拟机中安装 CentOS Linux 9 操作系统保姆级教程(附链接)
如何在 VM 虚拟机中安装 CentOS Linux 9 操作系统保姆级教程(附链接)
138 0