centos中mysql远程连接失败解决方案

本文档介绍了在CentOS系统中,当遇到MySQL远程连接失败时的解决方案。包括检查MySQL服务状态,确认数据库是否正常,修改用户权限,以及通过iptables开启3306端口以允许远程访问。
摘要由CSDN通过智能技术生成

#######-------说明:查看所有linux版本的信息

[root@homename etc]# lsb_release -a
LSB Version:    :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID: CentOS
Description:    CentOS release 6.5 (Final)
Release:        6.5
Codename:       Final

#######-------说明:查看服务器是否安装了mysql

[root@homename etc]# rpm -qa | grep mysql
qt-mysql-4.6.2-26.el6_4.x86_64
mysql-libs-5.1.71-1.el6.x86_64
mysql-5.1.71-1.el6.x86_64
mysql-server-5.1.71-1.el6.x86_64

#######-------说明:查看mysql服务是否启动正常
[root@homename etc]# service mysqld status
mysqld (pid  10053) 正在运行...

#######-------说明:进入mysql 
[root@homename etc]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.1.71 Source distribution

Copyright (c) 2000, 2013, 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.


#######-------说明:确认myqls数据库是否正常
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+
3 rows in set (0.00 sec)

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

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

mysql> exit
Bye
[root@homename etc]# vi /etc/sysconfig/iptables
# Generated by iptables-save v1.4.7 on Sat Jun  6 13:48:25 2015
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [6400198:1533000000]
-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 -p tcp -m state --state NEW -m tcp --dport 9080 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 9000 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
# mysql start
 -A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
# mysql stop

# add cluster start
-A INPUT -p tcp -m state --state NEW -m tcp --dport 4000 -j ACCEPT
-A OUTPUT -p tcp -m state --state NEW -m tcp --sport 4000 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 4001 -j ACCEPT
-A OUTPUT -p tcp -m state --state NEW -m tcp --sport 4001 -j ACCEPT
-A INPUT -p udp -m state --state NEW -m udp --dport 45564 -j ACCEPT
-A OUTPUT -p udp -m state --state NEW -m udp --sport 45564 -j ACCEPT
# add cluster end
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
# Completed on Sat Jun  6 13:48:25 2015

~                                                                                     
~                                                                                     
~                                                                                     
~                                                                                     
~                                                                                     
                                                                          
[root@homename etc]# service iptables restart
iptables:将链设置为政策 ACCEPT:filter                    [确定]
iptables:清除防火墙规则:                                 [确定]
iptables:正在卸载模块:    

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值