Linux yum安装MySQL5.7,及远程连接mysql(亲测有效!)

一、安装配置MySQL的yum源

1

2

3

4

5

6

7

8

9

10

# 安装MySQL的yum源,下面是RHEL6系列的下载地址

rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm

# 安装yum-config-manager

yum install yum-utils -y

# 禁用MySQL5.6的源

yum-config-manager --disable mysql56-community

# 启用MySQL5.7的源

yum-config-manager --enable mysql57-community-dmr

# 用下面的命令查看是否配置正确

yum repolist enabled | grep mysql

Linux yum安装MySQL5.7,及远程连接mysql(亲测有效!)_第1张图片

 检查是否有mysql57-community-dmr这个源,如上图所示。

二、yum安装MySQL5.7

# 安装MySQL5.7

yum install mysql-community-server

 

报错; 您可以尝试添加 --skip-broken 选项来解决该问题  您可以尝试执行:rpm -Va --nofiles --nodigest

修改/etc/yum.repos.d/mysql-community.repo 源文件

vim /etc/yum.repos.d/mysql-community.repo

Linux yum安装MySQL5.7,及远程连接mysql(亲测有效!)_第2张图片

然后再次执行yum install mysql-community-server

Linux yum安装MySQL5.7,及远程连接mysql(亲测有效!)_第3张图片

Linux yum安装MySQL5.7,及远程连接mysql(亲测有效!)_第4张图片

Linux yum安装MySQL5.7,及远程连接mysql(亲测有效!)_第5张图片

 

三、启动MySQL

# 禁用selinux

setenforce 0

sed -i '/^SELINUX=/c\SELINUX=disabled' /etc/selinux/config 

# 启动mysqld,启动之前先修改/etc/my.cnf配置文件,本文用默认的配置。

service mysqld start

Linux yum安装MySQL5.7,及远程连接mysql(亲测有效!)_第6张图片

 

、连接MySQL并修改密码

[root@iZ2zeintcn2jtegaarzs4yZ ~]#  grep "password" /var/log/mysqld.log

[root@iZ2zeintcn2jtegaarzs4yZ ~]# mysql -uroot -p

Linux yum安装MySQL5.7,及远程连接mysql(亲测有效!)_第7张图片

mysql> set global validate_password_policy=0;

mysql> set global validate_password_length=1;

mysql> set password=password('123456');

Linux yum安装MySQL5.7,及远程连接mysql(亲测有效!)_第8张图片

 

、使用Navicat远程连接MySQL报错1103

 

1

"font-size: 14px;">#给用户授权
"font-size: 14px;">我用的用户:root ,密码:@Wtt102501@
"font-size: 14px;">grant all privileges on *.* to 'root'@'%' identified by '@Wtt102501@' with grant option;
"font-size: 14px;">#执行完后刷新权限
"font-size: 14px;">flush privileges;

mysql> grant all privileges on *.* to 'root'@'%' identified by 'Password123@mysql' with grant option;

mysql> flush privileges; Linux yum安装MySQL5.7,及远程连接mysql(亲测有效!)_第9张图片

开放3306端口;

[root@iZrj98hvt5pgeax2pgdjw3Z ~]# vi  /etc/sysconfig/iptables

防火墙开放3306端口

1、打开防火墙配置文件

vi  /etc/sysconfig/iptables

如果没有这个文件,需要安装iptables

#先检查是否安装了iptables
service iptables status
#安装iptables
yum install -y iptables
#升级iptables
yum update iptables 
#安装iptables-services
yum install iptables-services

禁用/停止自带的firewalld服务

#停止firewalld服务
systemctl stop firewalld
#禁用firewalld服务
systemctl mask firewalld

开启iptables服务 

复制代码

#注册iptables服务
#相当于以前的chkconfig iptables on
systemctl enable iptables.service
#开启服务
systemctl start iptables.service
#查看状态
systemctl status iptables.service

vi /etc/sysconfig/iptables

2、增加下面一行

注意:增加的开放3306端口的语句一定要在icmp-host-prohibited之前

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

3、重启防火墙

service  iptables restart

附:个人配置

复制代码

# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -i eth0 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
-A FORWARD -p icmp -j ACCEPT
-A FORWARD -i lo -j ACCEPT
-A FORWARD -i eth0 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

 

你可能感兴趣的:(mysql)