基于 Linux 安装glibc版mysql 5.7.12

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
云数据库 RDS PostgreSQL,集群系列 2核4GB
简介: 对于mysql的数据库的安装,我们有很多种选择来完成。而最为常用的为二进制安装以及源码安装。

对于mysql的数据库的安装,我们有很多种选择来完成。而最为常用的为二进制安装以及源码安装。二进制安装方式中,包括rpm版本以及glibc版本。rpm版本就是在特定linux版本下编译的,如果你的linux版本匹配,就可以安装,如针对RedHat6或者RedHat7编译好的rpm包,下载对应的安装即可。还有另外一种二进制安装包为基于特定的glibc版本编译的,本文主要描述基于glibc方式安装mysql。

一、准备安装环境

###准备安装介质
下载地址:http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz 

###或者使用wget方式直接下载对应的版本
# wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz

# mkdir -pv /u01/app
# mkdir -pv /u01/soft
# mkdir -pv /u02/mysqldata

# cd /u01/soft
# wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz 
# tar -xf mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz

# ln -sv /u01/soft/mysql-5.7.12-linux-glibc2.5-x86_64 /u01/app/mysql
`/u01/app/mysql' -> `/u01/soft/mysql-5.7.12-linux-glibc2.5-x86_64'

###下面添加mysql用户
# useradd -r mysql -s /sbin/nologin
# chown -R mysql:mysql /u01/app/mysql
# chown -R mysql:mysql /u02/mysqldata 

二、初始化mysql

###使用以下的方式来初始化
# cd /u01/app/mysql/bin
# ./mysqld --initialize --basedir=/u01/app/mysql --datadir=/u02/mysqldata --user=mysql --explicit_defaults_for_timestamp
2016-06-28T02:18:23.437852Z 0 [Warning] InnoDB: New log files created, LSN=45790
2016-06-28T02:18:23.718104Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2016-06-28T02:18:23.866501Z 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: 9731b834-3cd6-11e6-8654-fcaa14e34b30.
2016-06-28T02:18:23.896540Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2016-06-28T02:18:23.898416Z 1 [Note] A temporary password is generated for root@localhost: )%%D0pr,mU.Y

# ls /u02/mysqldata/
auto.cnf    client-cert.pem  ibdata1      performance_schema  sys
ca-key.pem  client-key.pem   ib_logfile0  server-cert.pem
ca.pem      client-req.pem   ib_logfile1  server-key.pem
ca-req.pem  ib_buffer_pool   mysql        server-req.pem
###从上面的结果可以看出 mysql 5.7多出了证书相关文件,安全较5.6有较大提升

###mysql_install_db方式初始化数据已经被废弃
# ./mysql_install_db --basedir=/u01/app/mysql --datadir=/u02/mysqldata --user=mysql
2016-06-28 10:04:56 [WARNING] mysql_install_db is deprecated. 
Please consider switching to mysqld --initialize
2016-06-28 10:05:15 [WARNING] The bootstrap log isn't empty:
2016-06-28 10:05:15 [WARNING] 2016-06-28T02:04:56.688237Z 0 
[Warning] --bootstrap is deprecated. Please consider using --initialize instead
2016-06-28T02:04:56.688654Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2016-06-28T02:04:56.688657Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
###如上书提示,mysql_install_db方式初始化数据已经被废弃,建议使用mysqld --initialize,同时也给出了参数限制的警告

# cp /u01/app/mysql/support-files/my-default.cnf /etc/my.cnf
# cp /u01/app/mysql/support-files/mysql.server /etc/init.d/mysqld
# vim /etc/my.cnf 

[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
basedir=/u01/app/mysql
datadir=/u02/mysqldata
user=mysql
port=3306

# vim /etc/profile.d/mysql.sh
export MYSQL_HOME=/u01/app/mysql
export PATH=$PATH:$MYSQL_HOME/bin

# source /etc/profile.d/mysql.sh

# service mysqld start
Starting MySQL.                                            [  OK  ]

三、配置安全选项

###使用初始化时得到的密码配置安全选项
# /u01/app/mysql/bin/mysql_secure_installation -p)%%D0pr,mU.Y
mysql_secure_installation: [Warning] Using a password on the command line interface can be insecure.

Securing the MySQL server deployment.

The existing password for the user account root has expired. Please set a new password.

New password: 

Re-enter new password: 

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?

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

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2  ###设定密码策略等级
Using existing password for root.

Estimated strength of the password: 100 
Change the password for root ? ((Press y|Y for Yes, any other key for No) : 

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

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.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y  ###是否关闭root远程登陆功能
Success.

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.

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y  ###是否移除测试数据库
 - Dropping test database... 
Success.

 - Removing privileges on test database...
Success.

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) : y  ###是否立即生效权限表
Success.

All done! 

###以下为安全增强相关的部分参数

mysql> show variables like 'valid%';
+--------------------------------------+--------+
| Variable_name                        | Value  |
+--------------------------------------+--------+
| validate_password_dictionary_file    |        |
| validate_password_length             | 8      |
| validate_password_mixed_case_count   | 1      |
| validate_password_number_count       | 1      |
| validate_password_policy             | STRONG |
| validate_password_special_char_count | 1      |
+--------------------------------------+--------+

四、同一主机配置其他实例

###按上面描述的步骤创建其对应的目录及授权后,再执行初始化
###使用新的配置文件,如下文本示例使用的为3317
# mkdir -pv /u02/mysqldata3317
# chown -R mysql:mysql /u02/mysqldata 3317
# grep -v ^# /etc/my3317.cnf

[mysqld]
basedir=/u01/app/mysql
datadir=/u02/mysqldata3317
user=mysql
port=3317
socket=/tmp/mysql3317.sock

# cd /u01/app/mysql/bin
# ./mysqld --defaults-file=/etc/my3317.cnf --initialize --user=mysql --explicit_defaults_for_timestamp
# 2016-06-30T08:32:52.497519Z 0 [Warning] InnoDB: New log files created, LSN=45790
2016-06-30T08:32:52.852457Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2016-06-30T08:32:53.042621Z 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: 3cb1686d-3e9d-11e6-a71f-fcaa14e34b30.
2016-06-30T08:32:53.081210Z 0 [Warning] Gtid table is not ready to be used. 
Table 'mysql.gtid_executed' cannot be opened.
2016-06-30T08:32:53.082538Z 1 [Note] A temporary password is generated for root@localhost: :8#l!MCYoCNY

### Author : Leshami
### Blog   : http://blog.csdn.net/leshami

# mysqld_safe --defaults-file=/etc/my3317.cnf &
[1] 5825
2016-06-30T08:11:49.468176Z mysqld_safe Logging to '/u02/mysqldata3317/ydq4.err'.
2016-06-30T08:11:49.480379Z mysqld_safe The file /usr/local/mysql/bin/mysqld
does not exist or is not executable. Please cd to the mysql installation
directory and restart this script from there as follows:
./bin/mysqld_safe&
See http://dev.mysql.com/doc/mysql/en/mysqld-safe.html for more information

###如果执行mysqld_safe出现上述错误,可以创建软链。这个地方有问题,对于安装在非缺省目录时出现了这个问题。
# mkdir -pv /usr/local/mysql/bin/

# ln -sv /u01/app/mysql/bin/mysqld /usr/local/mysql/bin/mysqld      
"/usr/local/mysql/bin/mysqld" -> "/u01/app/mysql/bin/mysqld"

# ./mysqld_safe --defaults-file=/etc/my3317.cnf &
[1] 8287
2016-06-30T08:38:38.455961Z mysqld_safe Logging to '/u02/mysqldata3317/ydq4.err'.
2016-06-30T08:38:38.471542Z mysqld_safe Starting mysqld daemon with databases from /u02/mysqldata3317

###配置安全选项
# /u01/app/mysql/bin/mysql_secure_installation -P3317 -S /tmp/mysql3317.sock -p  

五、更多mysql安装卸载参考

Linux 5 下安装MySQL 5.6(RPM方式)
Linux 下卸载MySQL 5
Linux下基于源码方式安装MySQL 5.6
Linux 下MySQL源码安装完整版
MySQL 源码scr.rpm安装的一点注意事项

相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
22天前
|
关系型数据库 MySQL 数据库
Docker Compose V2 安装常用数据库MySQL+Mongo
以上内容涵盖了使用 Docker Compose 安装和管理 MySQL 和 MongoDB 的详细步骤,希望对您有所帮助。
122 42
|
1月前
|
安全 关系型数据库 MySQL
CentOS7仅安装部署MySQL80客户端
通过上述步骤,你可以在CentOS 7上成功安装并配置MySQL 8.0客户端。这个过程确保你能够使用MySQL客户端工具连接和管理远程的MySQL数据库,而不需要在本地安装MySQL服务器。定期更新MySQL客户端可以确保你使用的是最新的功能和安全修复。
206 16
|
2月前
|
关系型数据库 MySQL 数据库
【MySQL基础篇】MySQL概述、Windows下载MySQL8.0超详细图文安装教程
在这一章节,主要介绍两个部分,数据库相关概念及MySQL数据库的介绍、下载、安装、启动及连接。接着,详细描述了MySQL 8.0的版本选择与下载,推荐使用社区版(免费)。安装过程包括自定义安装路径、配置环境变量、启动和停止服务、以及客户端连接测试。此外,还提供了在同一台电脑上安装多个MySQL版本的方法及卸载步骤。最后,解释了关系型数据库(RDBMS)的特点,即基于二维表存储数据,使用SQL语言进行操作,格式统一且便于维护。通过具体的结构图展示了MySQL的数据模型,说明了数据库服务器、数据库、表和记录之间的层次关系。
【MySQL基础篇】MySQL概述、Windows下载MySQL8.0超详细图文安装教程
|
2月前
|
NoSQL 关系型数据库 Redis
《docker高级篇(大厂进阶):1.Docker复杂安装详说》包括:安装mysql主从复制、安装redis集群
《docker高级篇(大厂进阶):1.Docker复杂安装详说》包括:安装mysql主从复制、安装redis集群
137 14
|
1月前
|
关系型数据库 MySQL 应用服务中间件
《docker基础篇:8.Docker常规安装简介》包括:docker常规安装总体步骤、安装tomcat、安装mysql、安装redis
《docker基础篇:8.Docker常规安装简介》包括:docker常规安装总体步骤、安装tomcat、安装mysql、安装redis
135 7
|
2月前
|
关系型数据库 MySQL Linux
Linux下mysql数据库的导入与导出以及查看端口
本文详细介绍了在Linux下如何导入和导出MySQL数据库,以及查看MySQL运行端口的方法。通过这些操作,用户可以轻松进行数据库的备份与恢复,以及确认MySQL服务的运行状态和端口。掌握这些技能,对于日常数据库管理和维护非常重要。
147 8
|
2月前
|
安全 关系型数据库 MySQL
Windows Server 安装 MySQL 8.0 详细指南
安装 MySQL 需要谨慎,特别注意安全配置和权限管理。根据实际业务需求调整配置,确保数据库的性能和安全。
302 9
|
18天前
|
Linux
Linux系统之whereis命令的基本使用
Linux系统之whereis命令的基本使用
54 23
Linux系统之whereis命令的基本使用
|
3月前
|
Linux 网络安全 数据安全/隐私保护
Linux 超级强大的十六进制 dump 工具:XXD 命令,我教你应该如何使用!
在 Linux 系统中,xxd 命令是一个强大的十六进制 dump 工具,可以将文件或数据以十六进制和 ASCII 字符形式显示,帮助用户深入了解和分析数据。本文详细介绍了 xxd 命令的基本用法、高级功能及实际应用案例,包括查看文件内容、指定输出格式、写入文件、数据比较、数据提取、数据转换和数据加密解密等。通过掌握这些技巧,用户可以更高效地处理各种数据问题。
384 8
|
5天前
|
缓存 Ubuntu Linux
Linux中yum、rpm、apt-get、wget的区别,yum、rpm、apt-get常用命令,CentOS、Ubuntu中安装wget
通过本文,我们详细了解了 `yum`、`rpm`、`apt-get`和 `wget`的区别、常用命令以及在CentOS和Ubuntu中安装 `wget`的方法。`yum`和 `apt-get`是高层次的包管理器,分别用于RPM系和Debian系发行版,能够自动解决依赖问题;而 `rpm`是低层次的包管理工具,适合处理单个包;`wget`则是一个功能强大的下载工具,适用于各种下载任务。在实际使用中,根据系统类型和任务需求选择合适的工具,可以大大提高工作效率和系统管理的便利性。
54 25