CentOS7 yum 安装 mysql5.6

来源:互联网 发布:客户数据库管理软件 编辑:程序博客网 时间:2024/06/05 03:53

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

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


本文分为

1:安装mysql

2:mysql初始配置

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

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


第一部分:安装数据库

step1:查看已有的yum资源库

[root@iZ2zeczh9tfpmxmijw5qppZ mysql]# yum repolistLoaded plugins: fastestmirrorLoading mirror speeds from cached hostfile * base: mirrors.aliyuncs.com * epel: mirrors.aliyuncs.com * extras: mirrors.aliyuncs.com * updates: mirrors.aliyuncs.comrepo id                                                                              repo name                                                                                                           statusbase/7/x86_64                                                                        CentOS-7 - Base                                                                                                      9,363epel/x86_64                                                                          Extra Packages for Enterprise Linux 7 - x86_64                                                                      11,808extras/7/x86_64                                                                      CentOS-7 - Extras                                                                                                      381updates/7/x86_64                                                                     CentOS-7 - Updates                                                                                                   1,859repolist: 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.rpmResolving dev.mysql.com (dev.mysql.com)... 137.254.60.11Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:80... connected.HTTP request sent, awaiting response... 301 Moved PermanentlyLocation: 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.rpmConnecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:443... connected.HTTP request sent, awaiting response... 302 FoundLocation: 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.rpmResolving repo.mysql.com (repo.mysql.com)... 23.10.6.195Connecting to repo.mysql.com (repo.mysql.com)|23.10.6.195|:443... connected.HTTP request sent, awaiting response... 200 OKLength: 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.rpmPreparing...                          ################################# [100%]Updating / installing...   1:mysql-community-release-el7-5    ################################# [100%]

yum install

[root@iZ2zeczh9tfpmxmijw5qppZ mysql]# yum install mysql-community-serverLoaded plugins: fastestmirrormysql-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.comResolving 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 repolistLoaded plugins: fastestmirrorLoading mirror speeds from cached hostfile * base: mirrors.aliyuncs.com * epel: mirrors.aliyuncs.com * extras: mirrors.aliyuncs.com * updates: mirrors.aliyuncs.comrepo 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,859repolist: 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 -Vmysql  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 -urootmysql> set password for ‘root’@‘localhost’ = password('mypasswd');

Query OK, 0 rows affected (0.00 sec)


setp2:设置远程账户

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

mysql> use mysqlReading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changedmysql> 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 --permanentsuccess[root@iZ2zeczh9tfpmxmijw5qppZ ~]# firewall-cmd --reloadsuccess[root@iZ2zeczh9tfpmxmijw5qppZ ~]# firewall-cmd --staterunning[root@iZ2zeczh9tfpmxmijw5qppZ ~]#[root@iZ2zeczh9tfpmxmijw5qppZ ~]# firewall-cmd --zone=public --query-port=3306/tcpyes[root@iZ2zeczh9tfpmxmijw5qppZ ~]#



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

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

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




















原创粉丝点击