[iyunv@bogon software]# yum localinstall mysql-community-release-el7-5.noarch.rpm
已加载插件:fastestmirror
正在检查 mysql-community-release-el7-5.noarch.rpm: mysql-community-release-el7-5.noarch
mysql-community-release-el7-5.noarch.rpm 将被安装
正在解决依赖关系
--> 正在检查事务
---> 软件包 mysql-community-release.noarch.0.el7-5 将被 安装
--> 解决依赖关系完成
依赖关系解决
================================================================================
Package 架构 版本 源 大小
================================================================================
正在安装:
mysql-community-release
noarch el7-5 /mysql-community-release-el7-5.noarch 4.3 k
事务概要
================================================================================
安装 1 软件包
总计:4.3 k
安装大小:4.3 k
Is this ok [y/d/N]
提示是否 OK ,输入 y
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : mysql-community-release-el7-5.noarch 1/1
验证中 : mysql-community-release-el7-5.noarch 1/1
已安装:
mysql-community-release.noarch 0:el7-5
完毕!
提示“完成!”,则说明 源添加成功。
验证下是否添加成功
yum repolist enabled | grep "mysql.*-community.*"
可以看到下面内:
[iyunv@bogon software]# yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community/x86_64 MySQL Connectors Community 1
mysql-tools-community/x86_64 MySQL Tools Community 1
mysql56-community/x86_64 MySQL 5.6 Community Server 13
选择要启用 MySQL 版本
查看 MySQL 版本,执行
yum repolist all | grep mysql
可以看到 5.5, 5.7 版本是默认禁用的,因为现在最新的稳定版是 5.6
[iyunv@bogon software]# yum repolist all | grep mysql
mysql-connectors-community/x86_64 MySQL Connectors Community 启用: 14
mysql-connectors-community-source MySQL Connectors Community - Sourc 禁用
mysql-tools-community/x86_64 MySQL Tools Community 启用: 17
mysql-tools-community-source MySQL Tools Community - Source 禁用
mysql55-community/x86_64 MySQL 5.5 Community Server 禁用
mysql55-community-source MySQL 5.5 Community Server - Sourc 禁用
mysql56-community/x86_64 MySQL 5.6 Community Server 启用: 139
mysql56-community-source MySQL 5.6 Community Server - Sourc 禁用
mysql57-community-dmr/x86_64 MySQL 5.7 Community Server Develop 禁用
mysql57-community-dmr-source MySQL 5.7 Community Server Develop 禁用
# Enable to use MySQL 5.6
[mysql56-community]
name=MySQL 5.6 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[iyunv@bogon software]# yum repolist enabled | grep mysql
mysql-connectors-community/x86_64 MySQL Connectors Community 14
mysql-tools-community/x86_64 MySQL Tools Community 17
mysql56-community/x86_64 MySQL 5.6 Community Server 139
[iyunv@localhost ~]# whereis mysql
mysql: /usr/bin/mysql /usr/lib64/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz
启动和关闭 MySQL Server
启动 MySQL Server
systemctl start mysqld
查看 MySQL Server 状态
systemctl status mysqld
关闭 MySQL Server
systemctl stop mysqld
测试是否安装成功
mysql
可以进入 mysql 命令行界面
[iyunv@bogon software]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.24 MySQL Community Server (GPL)
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
在里面加入这2行:
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m udp -p udp –dport 3306 -j ACCEPT
改为
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m udp -p udp –dport 3306 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
[iyunv@bogon software]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
此时输入 root 原始密码(初始化安装的话为空),接下来,为了安全,MySQL 会提示你重置 root 密码,移除其他用户账号,禁用 root 远程登录,移除 test 数据库,重新加载 privilege 表格等,你只需输入 y 继续执行即可。
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
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? [Y/n] 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? [Y/n] 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? [Y/n] y
- Dropping test database...
ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist
... Failed! Not critical, keep moving...
- 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? [Y/n] y
... Success!
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!