Solved

Mysql Script Wont Connect to Remote Server

Posted on 2008-06-23
11
1,146 Views
Last Modified: 2013-12-12
My coder recently parted ways, and I recently moved to a new mysql server, this is causing a script he made to break. Unfortunately I have no familiarity with php and only slight familiarity with mysql, so I'm looking to the experts for some help.

I seem to be getting quite a few mysql errors, I have already changed the script to reflect the new server.

Here is the part in the script that has connection info, it all seems to be right:

function tc_mq($query) {
      $host = 'panel.*******.com';
      $username = 'dbname';
      $password = '*****';
      $db = 'dbname';
      mysql_pconnect($host,$username,$password);
      mysql_select_db($db);
      return mysql_query($query);
}


I made sure that info is correct, I also issued the GRANT command on the new mysql server to allow that remote ip to connect, what else could I be doing wrong?

Thanks, Brad
Warning: mysql_pconnect() [function.mysql-pconnect]: Lost connection to MySQL server at 'reading initial communication packet', system error: 111 in /home/admin/public_html/testserver/create.server.php on line 294
 
Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'admin'@'localhost' (using password: NO) in /home/admin/public_html/testserver/create.server.php on line 295
 
Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in /home/admin/public_html/testserver/create.server.php on line 295
 
Warning: mysql_query() [function.mysql-query]: Access denied for user 'admin'@'localhost' (using password: NO) in /home/admin/public_html/testserver/create.server.php on line 296
 
Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/admin/public_html/testserver/create.server.php on line 296
 
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/admin/public_html/testserver/create.server.php on line 67
 
Warning: mysql_pconnect() [function.mysql-pconnect]: Lost connection to MySQL server at 'reading initial communication packet', system error: 111 in /home/admin/public_html/testserver/create.server.php on line 294
 
Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'admin'@'localhost' (using password: NO) in /home/admin/public_html/testserver/create.server.php on line 295
 
Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in /home/admin/public_html/testserver/create.server.php on line 295
 
Warning: mysql_query() [function.mysql-query]: Access denied for user 'admin'@'localhost' (using password: NO) in /home/admin/public_html/testserver/create.server.php on line 296
 
Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/admin/public_html/testserver/create.server.php on line 296
 
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/admin/public_html/testserver/create.server.php on line 106
 
Warning: mysql_pconnect() [function.mysql-pconnect]: Lost connection to MySQL server at 'reading initial communication packet', system error: 111 in /home/admin/public_html/testserver/create.server.php on line 294
 
Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'admin'@'localhost' (using password: NO) in /home/admin/public_html/testserver/create.server.php on line 295
 
Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in /home/admin/public_html/testserver/create.server.php on line 295
 
Warning: mysql_query() [function.mysql-query]: Access denied for user 'admin'@'localhost' (using password: NO) in /home/admin/public_html/testserver/create.server.php on line 296
 
Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/admin/public_html/testserver/create.server.php on line 296
 
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/admin/public_html/testserver/create.server.php on line 214

Open in new window

0
Comment
Question by:mindlessacts
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 2

Expert Comment

by:CurtinProp
ID: 21852884
Have you granted access/created for Admin on the mysql server? If not that would be a great start
0
 

Author Comment

by:mindlessacts
ID: 21852888
I dont know how to do that :/

Could you point me in the right direction
0
 
LVL 2

Accepted Solution

by:
CurtinProp earned 500 total points
ID: 21853091
The manual teaches you how to add users and permissions to go with that user;
http://dev.mysql.com/doc/refman/5.0/en/adding-users.html

I suggest reading this page for a full understanding.
mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'localhost'
    ->     IDENTIFIED BY 'some_pass' WITH GRANT OPTION;
mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'%'
    ->     IDENTIFIED BY 'some_pass' WITH GRANT OPTION;
mysql> GRANT RELOAD,PROCESS ON *.* TO 'admin'@'localhost';
mysql> GRANT USAGE ON *.* TO 'dummy'@'localhost';

Open in new window

0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 29

Expert Comment

by:fosiul01
ID: 21855378
Hi as CurtinProp said,
its a permission issue

if your server is from Web host company, ask them what is the "root" username for mysql database.

or if you are hosting your own mysql server

then you should have a user called "Root" try with that username and password

becuase your Error is saying, you are trying with "admin" username, which is not authorized by mysql.


0
 
LVL 8

Expert Comment

by:CoyotesIT
ID: 21857365
One other thing you may want to make sure of is that your server's name is actually panel.***.com

typically MySQL is setup using sockets which do not allow communication/connections over TCP/IP

for starters I would suggest that you do what fosiul01 suggested with the user name, but also try putting 'localhost' in for your host name as well.

You may also want to (and i'm just guessing that you have cPanel) go into the mysql portion and ensure you have a user created.

This is where you will setup the MySQL users for your account if this is a hosted account.

function tc_mq($query) {
      $host = 'localhost';
      $username = '<mysql_user>';
      $password = '*****';
      $db = 'dbname';
      mysql_pconnect($host,$username,$password);
      mysql_select_db($db);
      return mysql_query($query);
}

0
 

Author Comment

by:mindlessacts
ID: 21861704
I do not have cpanel and I have already tried changing the permissions as stated in the original post (used the exact same command as "CurtinProp" suggested)

Also to make clear, I'm trying to connect remotely to this mysql server, it is not on localhost.

Anyways it seems I have everything correct and it just flat out wont work, any other suggestions?
0
 
LVL 2

Expert Comment

by:CurtinProp
ID: 21861809
If this is a remote server then maybe you should add the remote host in your php code instead of localhost.

As your code states;
admin'@'localhost

So really it should be admin@remotehost or what ever your remote database server is called.
0
 

Author Comment

by:mindlessacts
ID: 21861833
Well here is the thing, all we did was change to a new mysql server, so I went into the script and changed it to the new mysql server....

for example it was:
function tc_mq($query) {
      $host = 'panel.com';
      $username = 'root';
      $password = 'fakepass';
      $db = 'tcadmin';
      mysql_pconnect($host,$username,$password);
      mysql_select_db($db);
      return mysql_query($query);
}

once we changed mysql servers, all i did was change the following:

function tc_mq($query) {
      $host = 'newpanel.com';
      $username = 'tcadmin';
      $password = 'fakepass';
      $db = 'tcadmin';
      mysql_pconnect($host,$username,$password);
      mysql_select_db($db);
      return mysql_query($query);
}

Basically just changed the host, and switched from root to having the specific user connect, I have also tested that username and pass and they do work.

It seems like it would be a permissions error, but I used the reccomended command for EVERY ip on that box and it still isnt working.

Maybe I'm doing the command wrong? What would be the exact permissions command if I wanted to give full permissions to the ip: 37.32.32.32

Thanks for any help, this is making me crazy, I know it has to be something simple
0
 

Author Comment

by:mindlessacts
ID: 21861882
Ok I changed the script to:
 
$host = 'panel.com';  
$username = 'root';  
$password = 'ch@*******';  
$db = 'tcadmin';

I then issued the following command in the mysql command line:

GRANT ALL ON tcadmin.* TO root@'38.99.249.126' IDENTIFIED BY 'ch@*******';

Still get the same error:

Warning: mysql_pconnect() [function.mysql-pconnect]: Lost connection to MySQL server at 'reading initial communication packet', system error: 111 in /home/admin/public_html/testserver/create.server.php on line 294

Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'admin'@'localhost' (using password: NO) in /home/admin/public_html/testserver/create.server.php on line 295

Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in /home/admin/public_html/testserver/create.server.php on line 295

Warning: mysql_query() [function.mysql-query]: Access denied for user 'admin'@'localhost' (using password: NO) in /home/admin/public_html/testserver/create.server.php on line 296



I'm lost :/ I had this same issue with the same db for a different script, and it worked fine once I added permissions to the remote IP
0
 
LVL 2

Expert Comment

by:CurtinProp
ID: 21862343
Hi mindlessacts, i'm at a dead end as well. What I have suggested is what i'd do if I had this issue. If I were to fix it would require further investigation. The only other suggestion I can give is to try using

mysql_connect instead of mysql_pconnect
0
 

Author Comment

by:mindlessacts
ID: 21862908
Finally!

I feel so dumb that I didn't try this, but the dns I was using was set to permanently resolve to a different IP, but only on that box. So when I pinged that DNS from my local machine the IP was correct, but when the box pinged the dns it was the old IP.

Anyways all the info you guys gave was correct, so I will give points accordingly tomorrow when I go through the posts again.

Thanks Guys

--Brad
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question