[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Mysql Script Wont Connect to Remote Server

Posted on 2008-06-23
11
Medium Priority
?
1,160 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 1500 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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month20 days, 5 hours left to enroll

873 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