开发者社区> 晨曦蜗牛> 正文

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

简介:
+关注继续查看

一、从官方下载并安装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-创建yum本地源
CentOS-创建yum本地源
32 0
修改yum更新源为CentOS官网。
在Linux系统中使用yum工具可以帮助用户方便的安装软件包。修改yum更新源为CentOS官网。
35 0
CentOS 7使用ISO镜像配置本地yum源
CentOS 7使用ISO镜像配置本地yum源
1305 0
centos7 centos yum 源安装 nginx | centos7.3
centos7 centos yum 源安装 nginx | centos7.3 | centos 7.2 | centos 7.4
79 0
CentOS 7 yum 安装 Nginx
CentOS 7 yum 安装 Nginx
264 0
Centos 7 误删除Python导致yum无法使用
Centos 7 误删除Python导致yum无法使用
21530 0
CentOs系统使用yum安装时报错
CentOs系统使用yum安装时报错
132 0
解决CentOS执行yum命令出现File contains parsing errors:file:///etc/yum.repos.d/CentOS-Base.repo
解决CentOS执行yum命令出现File contains parsing errors:file:///etc/yum.repos.d/CentOS-Base.repo
1014 0
Centos/Redhat 本地yum源配置(Linux)
Centos/Redhat 本地yum源配置(Linux)
102 0
二十二、Centos安装yum,wegt(完全配置篇)
二十二、Centos安装yum,wegt(完全配置篇)
1277 0
+关注
晨曦蜗牛
专注DevOps!
文章
问答
视频
文章排行榜
最热
最新
相关电子书
更多
CentOS Nginx PHP JAVA多语言镜像使用手册
立即下载
低代码开发师(初级)实战教程
立即下载
阿里巴巴DevOps 最佳实践手册
立即下载
相关实验场景
更多
相关镜像