专栏首页耕耘实录在CentOS7上通过Yum Repository安装MySQL5.7.21

在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> 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包。

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

2.该种安装方式安装的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

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

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

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

    耕耘实录
  • PHP学习笔记(2)--PHP数据库操作基本知识

    耕耘实录
  • 忘记MySQL数据库root密码,使用安全模式巧妙重置密码

    忘记MySQL的root登录密码这种事情还是会发生的,很不幸,这事今天被我遇到了,顿时不知道怎么办了!百度了好一阵,上面的各种方法都使用了一遍,还是不奏效!可能...

    耕耘实录
  • (三)centos7下安装MariaDB 10.0/MySQL数据库

    来自官网的包源 https://downloads.mariadb.org/mariadb/repositorie

    botkenni
  • module 'scipy.misc' has no attribute 'imread'-------AttributeError: 'module' object has no attrib...

    官方scipy中提到,imread is deprecated! imread is deprecated in SciPy 1.0.0, and will b...

    水球喵子
  • 国庆节前端技术栈充实计划(7):为 Vue 项目写单元测试

    众所周知,Vue.js 是一个非常牛逼的 JavaScript 框架,对于创建复杂功能的前端项目是非常有用的。不管是什么项目,检查应用是否正常工作,运行是否为预...

    疯狂的技术宅
  • 【死磕 Spring】----- IOC 之 加载 Bean

    这段代码是 Spring 中编程式使用 IOC 容器,通过这四段简单的代码,我们可以初步判断 IOC 容器的使用过程。

    用户1655470
  • (4)交换排序之直接选择排序

    版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

    suveng
  • 腾讯报告TensorFlow首个安全风险 谷歌确认并致谢

    日前,腾讯发现谷歌人工智能学习系统TensorFlow存在严重安全风险,可被黑客利用带来安全威胁。据悉,该风险是TensorFlow首个自身安全风险,腾讯安全...

    腾讯技术工程官方号
  • 美国空军与贝索斯、波音等签署23亿美元合同,旨在为国家安全任务开发火箭发射系统

    这3份合同是国防部计划的一部分,最终目标是为了从军事角度,支持美国持续利用太空资源并减少对国外公司开发的火箭发动机的依赖。

    镁客网

扫码关注云+社区

领取腾讯云代金券