LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Problem connecting to MySQL (https://www.linuxquestions.org/questions/programming-9/problem-connecting-to-mysql-159359/)

griffey 03-18-2004 07:43 AM

Problem connecting to MySQL
 
Hi folks,

I'm having a bit of a problem using a Mac OS sql client called CocoaMySQL.

I've set up a database on a test webserver using MySQL and PHP. I can look at those database tables (and edit them) from my OS X machine using the aforementioned Cocoa program.

Today I'm getting ready to move my stuff into production, but CocoaMySQL won't let me connect to the production websever. The PHP pages work fine and can create databases, tables, enter data, etc., but when I try to connect using CocoaMySQL I get a "Connection failed!" dialog box.

At first I thought it was a problem with having only granted privileges for the new sql user on localhost, but I just added not only my Mac's IP address, but then finally '%' as well, and still no luck.

The test server is running RedHat 9. The production server is running RedHat ES 3.

While neither machine accepts Telnet connections, I can telnet port 3306 on the test server and get the version of MySQL returned. Doing the same for the production server just returns a message of connection refused.

Using netstat -a I can see my connection to the test server, but obviously there is no connection on the production machine.

Again, everything else is working normally, it is just nice to use the GUI program to peek into the database and make sure rows are being written as expected, etc., while using the web-based tools that I've created for this project.

Thanks in advance for any advice.

G.--

griffey 04-06-2004 10:37 AM

Solution
 
Hi folks. I'm not intentionally trying to simply return this back to the top of the list, and I apologize for doing so. But I found a solution and thought I'd come back and post it here on the very slight off-chance that someone else runs into the same problem some day (there's nothing worse than finally finding what you think might be a good link on Google only to have it be another dead end...).

Anyway, here's what I did. (With a lot of help from a good friend that knows what he's doing...).

The problem is that my firewall settings are set to "high" on the production box. So I needed to poke a small hole in the firewall to let me connect. I did that with the iptables configuration file.

You'll need to open a terminal and log in as root (using su -l).

First I made a backup copy of that file.

cd /etc/sysconfig
cp iptables iptables.bak

Then I used vi editor (you can use your editor of choice, of course) and modified that file.

After the last "ACCEPT" line and before the "REJECT" line I added the following line:

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp -s 192.168.123.123 --dport 3306 -j ACCEPT

All on one line. And of course, substitute your own IP address for 192.168.123.123 (by "own IP" I mean the IP address of the OS X machine that you are using to connect to the server, NOT the IP address of the server itself--what this is doing is allowing the OS X box with the IP address specified to connect to the server through the closed-to-everyone-else port 3306, which is what MySQL uses).

After saving that file you have to restart iptables. Do this by typing:

service iptables restart

You should get an [OK] message that they shut down and then two or three more [OK] messages as they start back up. If you get an error, it most likely means that you typed that line wrong (or that I typed it wrong and you copied it correctly...). Either way, your firewall is down so you'll need to go move that file that we just edited, and copy the backup file again.

cp iptables.bak iptables

Now do service iptables restart and it should start up with the old (working) settings.

Check the file that you edited for a typo, and if it still doesn't work maybe the typo is mine (I checked it several times so I think it should be okay...).

Good luck. I hope this helps someone out in the future. Actually, I hope noone else has this problem, but if they do--oh, well, nevermind. :)

G.--


All times are GMT -5. The time now is 03:39 AM.