CentOS7 yum 安装 mysql5.6

前言:CentOS7的默认yum资源库中没有mysql的安装文件,需要手动获取对应的文件;本次安装的mysql版本号为5.6;

    因为mysql安装时的依赖较多,目前为止还是习惯于使用yum进行安装。


本文分为

1:安装mysql

2:mysql初始配置

3:配置防火墙,开放端口

     注:CentOS7 默认使用firewall,本次关闭了firewall,启用iptables进行防火墙设置(第三部分详解)


第一部分:安装数据库

step1:查看已有的yum资源库

[root@iZ2zeczh9tfpmxmijw5qppZ mysql]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyuncs.com
 * epel: mirrors.aliyuncs.com
 * extras: mirrors.aliyuncs.com
 * updates: mirrors.aliyuncs.com
repo id                                                                              repo name                                                                                                           status
base/7/x86_64                                                                        CentOS-7 - Base                                                                                                      9,363
epel/x86_64                                                                          Extra Packages for Enterprise Linux 7 - x86_64                                                                      11,808
extras/7/x86_64                                                                      CentOS-7 - Extras                                                                                                      381
updates/7/x86_64                                                                     CentOS-7 - Updates                                                                                                   1,859
repolist: 23,411

step2:获取安装文件
[root@iZ2zeczh9tfpmxmijw5qppZ mysql]# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
--2017-06-20 19:38:43--  http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
Resolving dev.mysql.com (dev.mysql.com)... 137.254.60.11
Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm [following]
--2017-06-20 19:38:44--  https://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://repo.mysql.com//mysql-community-release-el7-5.noarch.rpm [following]
--2017-06-20 19:38:45--  https://repo.mysql.com//mysql-community-release-el7-5.noarch.rpm
Resolving repo.mysql.com (repo.mysql.com)... 23.10.6.195
Connecting to repo.mysql.com (repo.mysql.com)|23.10.6.195|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 6140 (6.0K) [application/x-redhat-package-manager]
Saving to: 鈥榤ysql-community-release-el7-5.noarch.rpm鈥

PS:在做本次手稿的时候,CRT会话忘记了调整编码,中文文本出现了乱码,见谅。

step3:Install

rpm

 [root@iZ2zeczh9tfpmxmijw5qppZ mysql]# rpm -ivh mysql-community-release-el7-5.noarch.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-release-el7-5    ################################# [100%]

yum install

[root@iZ2zeczh9tfpmxmijw5qppZ mysql]# yum install mysql-community-server
Loaded plugins: fastestmirror
mysql-connectors-community                                                                                                                                                              | 2.5 kB  00:00:00     
mysql-tools-community                                                                                                                                                                   | 2.5 kB  00:00:00     
mysql56-community                                                                                                                                                                       | 2.5 kB  00:00:00     
(1/3): mysql-connectors-community/x86_64/primary_db                                                                                                                                     |  14 kB  00:00:00     
(2/3): mysql-tools-community/x86_64/primary_db                                                                                                                                          |  33 kB  00:00:00     
(3/3): mysql56-community/x86_64/primary_db                                                                                                                                              | 168 kB  00:00:00     
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyuncs.com
 * epel: mirrors.aliyuncs.com
 * extras: mirrors.aliyuncs.com
 * updates: mirrors.aliyuncs.com
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.6.36-2.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.6.36-2.el7 for package: mysql-community-server-5.6.36-2.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.6.10 for package: mysql-community-server-5.6.36-2.el7.x86_64
--> Processing Dependency: perl(Data::Dumper) for package: mysql-community-server-5.6.36-2.el7.x86_64
--> Processing Dependency: perl(DBI) for package: mysql-community-server-5.6.36-2.el7.x86_64
--> Processing Dependency: libaio.so.1(LIBAIO_0.4)(64bit) for package: mysql-community-server-5.6.36-2.el7.x86_64
--> Processing Dependency: libaio.so.1(LIBAIO_0.1)(64bit) for package: mysql-community-server-5.6.36-2.el7.x86_64
--> Processing Dependency: libaio.so.1()(64bit) for package: mysql-community-server-5.6.36-2.el7.x86_64
--> Running transaction check
---> Package libaio.x86_64 0:0.3.109-13.el7 will be installed

step4: Review

yum check

[root@iZ2zeczh9tfpmxmijw5qppZ ~]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyuncs.com
 * epel: mirrors.aliyuncs.com
 * extras: mirrors.aliyuncs.com
 * updates: mirrors.aliyuncs.com
repo id                                                                                       repo name                                                                                                  status
!base/7/x86_64                                                                                CentOS-7 - Base                                                                                             9,363
!epel/x86_64                                                                                  Extra Packages for Enterprise Linux 7 - x86_64                                                             11,808
!extras/7/x86_64                                                                              CentOS-7 - Extras                                                                                             381
!mysql-connectors-community/x86_64                                                            MySQL Connectors Community                                                                                     36
!mysql-tools-community/x86_64                                                                 MySQL Tools Community                                                                                          47
!mysql56-community/x86_64                                                                     MySQL 5.6 Community Server                                                                                    327
!updates/7/x86_64                                                                             CentOS-7 - Updates                                                                                          1,859
repolist: 23,821
[root@iZ2zeczh9tfpmxmijw5qppZ ~]# 

对应的新增了

mysql-connectors-community/x86_64/primary_db                                                                                                                                 

mysql-tools-community/x86_64/primary_db                                                                                                                                         

mysql56-community/x86_64/primary_db    


mysql -V

[root@iZ2zeczh9tfpmxmijw5qppZ ~]# mysql -V
mysql  Ver 14.14 Distrib 5.6.36, for Linux (x86_64) using  EditLine wrapper
[root@iZ2zeczh9tfpmxmijw5qppZ ~]# 


step5:设置开机启动

[root@iZ2zeczh9tfpmxmijw5qppZ ~]# systemctl enable mysqld
[root@iZ2zeczh9tfpmxmijw5qppZ ~]# 

启动mysqld服务

service mysqld restart


第二部分:mysql初始配置

step1: 设置root密码

初次安装mysql后root账户默认是没有密码的

[root@iZ2zeczh9tfpmxmijw5qppZ ~]# mysql -uroot
mysql> set password for ‘root’@‘localhost’ = password('mypasswd');

Query OK, 0 rows affected (0.00 sec)


setp2:设置远程账户

这里使用root账户,单独设置远程密码

mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> grant all privileges on *.* to 'root'@'%' identified by 'your_range_passwd';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql>

使用mysql数据库(真正的数据库,而非数据库软件),

将所有数据库的所有表(*.*)的所有权限(all privileges),

授予通过任何ip(%)访问的root用户,

密码为 your_range_passwd,

最后刷新(flush privileges)即可。


step3:开放3306接口用于远程连接

方法一:iptables

修改/etc/sysconfig/iptables,添加下面的记录

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT   #允许3306数据库端口通过防火墙


cat /etc/sysconfig/iptables3306这条信息

service iptables restart


备注:如果规则有不生效的情况试着关闭SELINUX。

方法二:使用默认的firewall

[root@iZ2zeczh9tfpmxmijw5qppZ ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
[root@iZ2zeczh9tfpmxmijw5qppZ ~]# firewall-cmd --reload
success
[root@iZ2zeczh9tfpmxmijw5qppZ ~]# firewall-cmd --state
running
[root@iZ2zeczh9tfpmxmijw5qppZ ~]#
[root@iZ2zeczh9tfpmxmijw5qppZ ~]# firewall-cmd --zone=public --query-port=3306/tcp
yes
[root@iZ2zeczh9tfpmxmijw5qppZ ~]#



备注:由于CentOS7默认使用firewall,默认没有iptables,也就没有上述的/etc/sysconfig/iptables配置文件。

相比较而言我们更倾向于iptables,需要我们停用firewall和安装iptables;

CentOS7停用firewall和安装使用iptables相关文章:




















评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值