Solved

Mysql Script Wont Connect to Remote Server

Posted on 2008-06-23
11
1,126 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
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
 
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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now