PHP connection to mySQL

I have setup a PHP /MySQL in my  internal network. The server can be access through a IP http://10.1.3.3. I can also access to MySQL using mySQL Workbench installed in my PC.

In my PHP statement, if replace the server "localhost" with the actual IP address, the php page can't connect and return with a error :

Any idea why does it happen ?

Connection error: Can't connect to MySQL server on '10.1.3.3' (4)

Thx
AXISHKAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
What happens if you use the IP address in MySQL Workbench?  On this page https://dev.mysql.com/doc/refman/5.7/en/mysql-installer-workflow.html , it says...
You may enable TCP/IP Networking here as otherwise only local host connections are allowed.
0
David FavorLinux/LXD/WordPress/Hosting SavantCommented:
This is best behavior.

Connecting through an IP runs at speed of your network stack, where using localhost connect through a unix domain socket which runs at speed of your filesystem. Connecting through localhost will run roughly twice as fast as using 127.0.0.1 as filesystem i/o normal occurs out of memory buffers in memory.

You should be able to connect to 127.0.0.1 with no problem.

To connect to any other IP, you'll have to GRANT specific users the ability to connect through any IP (wildcard) or your specific IP.

You'll only be able to connect with a specific GRANT.

Something like this...

GRANT ALL PRIVILEGES ON *.* TO 'root'@'10.1.3.3'
    IDENTIFIED BY 'password'  
    WITH GRANT OPTION;
FLUSH PRIVILEGES;

Open in new window


Be aware. Once you do this any computer connected to your ISP on the same class C network + sometimes even more people will be able to scrape your user/pass + access your database too.

This occurs when ISPs incorrectly partition off traffic from users.

If you must do this, then best to setup a full SSL stack for your MySQL connections, else there's a good likelihood one or more people will be accessing + changing your data.

I host 100s of high speed sites, so I see MySQL port probes all the time... on my servers + my residential net connection.

If you think this won't happen... you may be surprised...

Best to SSL wrap all non-localhost connections in SSL.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AXISHKAuthor Commented:
If there is a entry in user table , root with host '%', does it mean root can access the MySQL from anywhere ?

Thx
0
arnoldCommented:
Yes.
Root@localhost is not the same as root@%
It depends on which rights you grant to the root@%
Though usually it is best to use a separate dedicate account for the php application that has a limited scope and can only access specific databases.
1
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.