在CentOS7上通过Yum Repository安装MySQL5.7.21

本文涉及的产品
云数据库 RDS MySQL,集群版 2核4GB 100GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介:

一、从官方下载并安装Yum Repository

  1. 下载Yum Repository。
[root@GeekDevOps ~]# curl -O https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm
  1. 安装Yum Repository。
[root@GeekDevOps ~]# yum -y localinstall mysql57-community-release-el7-11.noarch.rpm
  1. 查看可用的repo。
[root@GeekDevOps ~]# yum repolist enabled|grep "mysql.*-community.*"
mysql-connectors-community/x86_64        MySQL Connectors Community           45
mysql-tools-community/x86_64             MySQL Tools Community                59
mysql57-community/x86_64                 MySQL 5.7 Community Server          247
  1. 安装MySQL-Server。
[root@GeekDevOps ~]# yum -y install mysql-community-server

二、配置并启动服务

  1. 查找初始密码。
[root@GeekDevOps ~]# grep 'temporary password' /var/log/mysqld.log
2018-03-15T13:37:34.416639Z 1 [Note] A temporary password is generated for root@localhost: hbViaRqXw2;p
  1. 启动服务。
[root@GeekDevOps ~]# systemctl start mysqld
  1. 登录并修改密码。
[root@GeekDevOps ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.21
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> set password=password('test123');
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> set password =password('GeekDevOps../8');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> quit

此处的ERROR是由于密码强度不够造成的,提供一个强度高的密码即可。

三、一些简单配置

MySQL的安装至此已经告一段落,如果没有特殊要求已经可以使用。作为强迫症的我,还是想移除Yum Repository包。

[root@GeekDevOps ~]# yum -y remove mysql57-community-release-el7-11.noarch
[root@GeekDevOps ~]# rm mysql57-community-release-el7-11.noarch.rpm 

这种安装方式非常快,便于那种定制化不高的使用场景,服务管理也在安装的过程中完成,设置开机启动:

[root@GeekDevOps ~]# systemctl enable mysqld

其他设置跟之前glibc版的一致,不赘述。my.cnf文件需要根据实际情况进行配置。在此顺便提一下该种安装方式的安全设置。

[root@GeekDevOps ~]# mysql_secure_installation 
Securing the MySQL server deployment.
Enter password for user root: 
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
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) : n

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

四、写在后面

  1. 该种安装方式在安装的过程中会自动创建mysql用户及同名组关于这个账户的信息我们可以通过finger(需要额外安装)命令来查看。
[root@GeekDevOps system]# finger -l mysql
Login: mysql                      Name: MySQL Server
Directory: /var/lib/mysql               Shell: /bin/false
Never logged in.
No mail.
No Plan.
  1. 该种安装方式安装的mysql服务默认是mysql用户。我们可以以下两条命令来查看。
[root@GeekDevOps /]# ps -ef |grep mysql
mysql      2835      1  0 21:37 ?        00:00:05 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
root      12050   2606  0 23:07 pts/0    00:00:00 mysql -u root -p
root      12144  12055  0 23:46 pts/1    00:00:00 grep --color=auto mysql
[root@GeekDevOps /]# cat /usr/lib/systemd/system/mysqld.service |grep -e 'User' -e 'Group'
User=mysql
Group=mysql

五、参考资料

[1] https://dev.mysql.com/doc/refman/5.7/en/linux-installation-yum-repo.html

相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
29天前
|
安全 关系型数据库 MySQL
CentOS 8 中安装与配置 MySQL
CentOS 8 中安装与配置 MySQL
100 3
|
1月前
|
关系型数据库 MySQL 数据安全/隐私保护
mysql8.0.26忘记密码后重置(centos8)
mysql8.0.26忘记密码后重置(centos8)
28 2
|
1月前
|
安全 关系型数据库 MySQL
Centos、OpenEuler系统安装mysql
Centos、OpenEuler系统安装mysql
24 1
|
21天前
|
关系型数据库 MySQL Linux
Linux部署实战前言,MySQL在CentOS安装【单机软件】,MySQL的安装需要root权限,yum install mysql,systemctl enable mysqld开机自启的意思
Linux部署实战前言,MySQL在CentOS安装【单机软件】,MySQL的安装需要root权限,yum install mysql,systemctl enable mysqld开机自启的意思
|
21天前
|
SQL 关系型数据库 MySQL
MYSQL8.0在CentOS安装[单机软件]
MYSQL8.0在CentOS安装[单机软件]
|
22天前
|
关系型数据库 MySQL Linux
Centos7下在线安装mysql
【7 月更文挑战第 2 天】Centos7、mysql
|
24天前
|
缓存 Linux 开发工具
docker的centos容器使用yum报错
docker的centos容器使用yum报错
74 0
|
1月前
|
关系型数据库 MySQL Linux
蓝易云 - CentOS7用二进制安装MySQL5.7
以上步骤即可完成在CentOS 7上通过二进制包安装MySQL 5.7。
55 2
|
1月前
|
关系型数据库 MySQL Linux
CentOS7.9 安装 mysql-8.0.36 踩坑小记
CentOS7.9 安装 mysql-8.0.36排错指南
282 1
|
1月前
|
存储 关系型数据库 MySQL
CentOS上安装MySQL 8.0的详细教程
CentOS上安装MySQL 8.0的详细教程