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

  1. 云栖社区>
  2. 博客>
  3. 正文

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

耕耘实录 2018-03-16 00:08:06 浏览2176
展开阅读全文

一、从官方下载并安装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

网友评论

登录后评论
0/500
评论
耕耘实录
+ 关注