前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >在CentOS7上通过Yum Repository安装MySQL5.7.21

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

作者头像
耕耘实录
发布2018-12-20 14:40:30
4810
发布2018-12-20 14:40:30
举报
文章被收录于专栏:耕耘实录耕耘实录

版权声明:本文为耕耘实录原创文章,各大自媒体平台同步更新。欢迎转载,转载请注明出处,谢谢

一、从官方下载并安装Yum Repository
  1. 下载Yum Repository。
代码语言:javascript
复制
[root@GeekDevOps ~]# curl -O https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm
  1. 安装Yum Repository。
代码语言:javascript
复制
[root@GeekDevOps ~]# yum -y localinstall mysql57-community-release-el7-11.noarch.rpm
  1. 查看可用的repo。
代码语言:javascript
复制
[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。
代码语言:javascript
复制
[root@GeekDevOps ~]# yum -y install mysql-community-server
二、配置并启动服务
  1. 查找初始密码。
代码语言:javascript
复制
[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. 启动服务。
代码语言:javascript
复制
[root@GeekDevOps ~]# systemctl start mysqld
  1. 登录并修改密码。
代码语言:javascript
复制
[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是由于密码强度不够造成的,提供一个强度高的密码即可。也可以:

代码语言:javascript
复制
mysql> set global validate_password_mixed_case_count=0;  
Query OK, 0 rows affected (0.00 sec)  
mysql> set global validate_password_number_count=3;  
Query OK, 0 rows affected (0.00 sec)  
mysql> set global validate_password_special_char_count=0;  
Query OK, 0 rows affected (0.00 sec)  
mysql> set global validate_password_length=3;  
Query OK, 0 rows affected (0.00 sec)  
mysql> SHOW VARIABLES LIKE 'validate_password%'; 
三、一些简单配置

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

代码语言:javascript
复制
[root@GeekDevOps ~]# yum -y remove mysql57-community-release-el7-11.noarch
[root@GeekDevOps ~]# rm mysql57-community-release-el7-11.noarch.rpm 

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

代码语言:javascript
复制
[root@GeekDevOps ~]# systemctl enable mysqld

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

代码语言:javascript
复制
[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(需要额外安装)命令来查看。

代码语言:javascript
复制
[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.

2.该种安装方式安装的mysql服务默认是mysql用户。我们可以以下两条命令来查看。

代码语言:javascript
复制
[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
代码语言:javascript
复制
[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

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018年03月16日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、从官方下载并安装Yum Repository
  • 二、配置并启动服务
  • 三、一些简单配置
  • 四、写在后面
  • 五、参考资料
相关产品与服务
云数据库 SQL Server
腾讯云数据库 SQL Server (TencentDB for SQL Server)是业界最常用的商用数据库之一,对基于 Windows 架构的应用程序具有完美的支持。TencentDB for SQL Server 拥有微软正版授权,可持续为用户提供最新的功能,避免未授权使用软件的风险。具有即开即用、稳定可靠、安全运行、弹性扩缩等特点。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档