LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-23-2011, 08:14 AM   #1
iamsamhk
LQ Newbie
 
Registered: Jul 2011
Posts: 2

Rep: Reputation: Disabled
Trouble when connecting to mysql database remotely via port 3306


Hi all,

I'm new to linux, and setting up the mysql database server.
I've search for the solution for 4 hours... but I'm failed..
Here are my situation:

OS: CentOS 6
mysql version: 5.5


I tried to use MySQL Administrator to connect to my database on the host 192.168.1.120
and my computer is under the same network with ip: 192.168.1.105

But it shows the error msg:

Could not connect to MySQL instance at 192.168.1.120
Error: Can't connect to MySQL server on '192.168.1.120'(61)(code 2003)



On the server side
I've tried:
Code:
mysql> SHOW VARIABLES LIKE 'skip_networking';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| skip_networking | OFF   |
+-----------------+-------+
1 row in set (0.00 sec)

mysql> SHOW VARIABLES LIKE 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port          | 3306  |
+---------------+-------+
1 row in set (0.01 sec)
skip_networking is off and I've set the port for it.

When I check the process in OS:
Code:
[samuel.chan@dev etc]$ ps ax | grep mysql
 4308 pts/0    T      0:00 mysql -u xxxxx -p
 5292 pts/1    S+     0:00 mysql -u root -p
11230 pts/2    S      0:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysql
11498 pts/2    Sl     0:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock --port=3306
11584 pts/2    S+     0:00 grep mysql

When I try netstat:
Code:
[samuel.chan@dev etc]$ netstat -a | grep mysql
tcp        0      0 *:mysql                     *:*                         LISTEN      
unix  2      [ ACC ]     STREAM     LISTENING     40793  /var/lib/mysql/mysql.sock
unix  3      [ ]         STREAM     CONNECTED     41023  /var/lib/mysql/mysql.sock

I thought it's the problem of firewall, so I have check it also:
Code:
[samuel.chan@dev etc]$ sudo iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED 
ACCEPT     icmp --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere            
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:ssh 
REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited 
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:mysql 

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited 

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination


Now I have no idea what's the problem, could anyone please advice?
 
Old 07-23-2011, 11:21 AM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 650Reputation: 650Reputation: 650Reputation: 650Reputation: 650Reputation: 650
Quote:
...
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
ACCEPT tcp -- anywhere anywhere tcp dpt:mysql
...
Here's your problem, you've added the ACCEPT rule after the "deny all" rule - change the order and you'll be fine. Use '-I' to insert the mysql rule at a specific line number above the reject rule or edit the iptables config file and restart the service.
 
Old 07-23-2011, 11:44 AM   #3
4play
LQ Newbie
 
Registered: Oct 2003
Location: london
Distribution: Centos
Posts: 25

Rep: Reputation: 15
I have exactly the same problem even when I move the mysql rule before the Default Reject.

If I switch iptables off it works perfectly. I ended up adding another rule for udp traffic being allowed and it now works.
 
Old 07-23-2011, 01:25 PM   #4
iamsamhk
LQ Newbie
 
Registered: Jul 2011
Posts: 2

Original Poster
Rep: Reputation: Disabled
Really thanks kbp for helping, it's solved !!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
mysqld running and reading for connections on port 3306, no port 3306 found from scan darkenigmaa Linux - Networking 10 07-13-2016 12:53 PM
MySQL not listening on port 3306 mr_sarge Linux - Newbie 14 12-03-2013 05:17 AM
Issue connecting to mySQL port 3306. JeffJustCollect Linux - Newbie 2 12-13-2009 07:24 PM
Mysql - port 3306 - turn it off rjcrews Linux - Security 5 01-11-2007 01:18 PM
mysql port 3306 bulliver Linux - Security 4 04-17-2003 09:00 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration