Gruzin Posted January 10, 2007 Share Posted January 10, 2007 Hi guys,I want to connect to my mysql db from another server, but I get this error:[code]I cannot connect to the database because: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)[/code]Here it the code:[code]<?php$dbh = mysql_connect ("host", "user", "pass") or die ('I cannot connect to the database because: ' . mysql_error());mysql_select_db ("db_name");?>[/code]Thanks for any help,George Quote Link to comment https://forums.phpfreaks.com/topic/33578-mysql-connect-question/ Share on other sites More sharing options...
ted_chou12 Posted January 10, 2007 Share Posted January 10, 2007 from the looks of this path:'/tmp/mysql.sock' I dont think you can connect to mysql of the other server, because tmp is a directory that only works for the current server.btw, for the host, do you have "localhost" or specified host? Quote Link to comment https://forums.phpfreaks.com/topic/33578-mysql-connect-question/#findComment-157264 Share on other sites More sharing options...
Gruzin Posted January 10, 2007 Author Share Posted January 10, 2007 Yes it's localhost. I could change '/tmp/mysql.sock' in my php.ini...Thanks,George Quote Link to comment https://forums.phpfreaks.com/topic/33578-mysql-connect-question/#findComment-157265 Share on other sites More sharing options...
ted_chou12 Posted January 10, 2007 Share Posted January 10, 2007 if you want to connect to the mysql database of a foreign server, then you would need to change localhost to something else, see the user panel they give you (*that of the foreign server). Quote Link to comment https://forums.phpfreaks.com/topic/33578-mysql-connect-question/#findComment-157266 Share on other sites More sharing options...
Gruzin Posted January 10, 2007 Author Share Posted January 10, 2007 ummm.... let me see, can I use server ip instead of localhost? Quote Link to comment https://forums.phpfreaks.com/topic/33578-mysql-connect-question/#findComment-157268 Share on other sites More sharing options...
ted_chou12 Posted January 10, 2007 Share Posted January 10, 2007 I think you can, but I am not sure, if not, try the port as well.Ted Quote Link to comment https://forums.phpfreaks.com/topic/33578-mysql-connect-question/#findComment-157269 Share on other sites More sharing options...
Gruzin Posted January 10, 2007 Author Share Posted January 10, 2007 Thanks Ted,I've tryed everything but result is the same... :(<?php$dbh = mysql_connect ("10.10.10.100:19663", "user", "pass") or die ('I cannot connect to the database because: ' . mysql_error());mysql_select_db ("db_name");?>19663 - this is a REMOTE_PORT I've found in phpinfo of the server i want to connect Quote Link to comment https://forums.phpfreaks.com/topic/33578-mysql-connect-question/#findComment-157273 Share on other sites More sharing options...
ted_chou12 Posted January 10, 2007 Share Posted January 10, 2007 your last change is the server address, try to find it in your user panel, it will look similar to this:sql.server.comor something like that, try putting that into your php code... for host.Ted Quote Link to comment https://forums.phpfreaks.com/topic/33578-mysql-connect-question/#findComment-157278 Share on other sites More sharing options...
Gruzin Posted January 10, 2007 Author Share Posted January 10, 2007 I'am looking at cpanel and can't find it... I'am sorry but I don't know what do u mean under [b]user panel[/b]Thanks for your help Ted!George Quote Link to comment https://forums.phpfreaks.com/topic/33578-mysql-connect-question/#findComment-157310 Share on other sites More sharing options...
ted_chou12 Posted January 10, 2007 Share Posted January 10, 2007 you welcome George, most hosts provide their users a user panel, most user panels will have some file manager of their sort as well as a mysql manager of their sort. If you are not sure about where it is, you can always email your support for it.Ted Quote Link to comment https://forums.phpfreaks.com/topic/33578-mysql-connect-question/#findComment-157312 Share on other sites More sharing options...
Gruzin Posted January 10, 2007 Author Share Posted January 10, 2007 OK, I'll try my best :)Thanks a lot!George Quote Link to comment https://forums.phpfreaks.com/topic/33578-mysql-connect-question/#findComment-157313 Share on other sites More sharing options...
HuggieBear Posted January 10, 2007 Share Posted January 10, 2007 Don't bother with the port just yet. I connect to a remote server with this code:[code]<?php$user="my_username";$pass="my_password";$host="xxx.xxx.xxx.xxx"; // I just use the server IP address here, no port as it's the standard one (3306)$dbname="gallery";$connection = mysql_connect($host, $user, $pass);if (!$connection){ echo "Could not connect to database: " .mysql_error();}$founddb = mysql_select_db($dbname, $connection);if (!$founddb){ echo "Could not find DB: " .mysql_error();}?>[/code]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/33578-mysql-connect-question/#findComment-157364 Share on other sites More sharing options...
Gruzin Posted January 10, 2007 Author Share Posted January 10, 2007 Thanks Huggie, but I get this error:[code]Warning: mysql_query(): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in /home/content/n/y/c/nycstore/html/n/index.php on line 3[/code]Do I have to change something in php.ini? Quote Link to comment https://forums.phpfreaks.com/topic/33578-mysql-connect-question/#findComment-157413 Share on other sites More sharing options...
HuggieBear Posted January 10, 2007 Share Posted January 10, 2007 With that error, you can refer to the MySQL manual.Read [url=http://dev.mysql.com/doc/refman/5.0/en/can-not-connect-to-server.html]this article[/url]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/33578-mysql-connect-question/#findComment-157420 Share on other sites More sharing options...
stualk Posted January 10, 2007 Share Posted January 10, 2007 I think i'm having a similar problem to this. I'm currently in the process of moving all the sites I host from an old server to a new one. The problem is that the new server has PHP 5.1.6 installed, whereas the old one used PHP 4.4.4.When I have transferred all the dbs and all web files I am getting errors with every site that uses php/mysql. I am aware of the register_globals change in the latest version of php and I have now managed to get this turned on so that can't be the problem.Here's an example problem, bearing in mind I have merely copied the web pages and database from one server to another it 'should' work the same, i.e. successfully! Here's an error:Warning: mysql_connect() [function.mysql-connect]: Lost connection to MySQL server during query in /home/vhost/DOMAIN.co.uk/html/database.php on line 7Could not connect to database: Lost connection to MySQL server during queryWarning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /home/vhost/DOMAIN.co.uk/html/database.php on line 11Could not find DB: Lost connection to MySQL server during queryIt appears to be struggling to connect to the database despite me using the same code to connect!Not sure what to do to resolve this. Quote Link to comment https://forums.phpfreaks.com/topic/33578-mysql-connect-question/#findComment-157427 Share on other sites More sharing options...
HuggieBear Posted January 10, 2007 Share Posted January 10, 2007 Hey stu,Happy New Year...This is a host/server setup issue, I believe probably time-out related. Check [url=http://dev.mysql.com/doc/refman/5.0/en/gone-away.html]here[/url]RegardsRich Quote Link to comment https://forums.phpfreaks.com/topic/33578-mysql-connect-question/#findComment-157432 Share on other sites More sharing options...
stualk Posted January 10, 2007 Share Posted January 10, 2007 Cheers Rich, i'll take a look at that and see if I can get round it. If I can all my problems are solved! My host company gave me access to SSH so that I could login and change the PHP settings to more or less match those on our old server so hopefully i'll be alright (otherwise I have some late nights ahead of me doing some serious re-coding!)Happy New Year - have you had any emails from me? Sent you a couple I think. Quote Link to comment https://forums.phpfreaks.com/topic/33578-mysql-connect-question/#findComment-157438 Share on other sites More sharing options...
HuggieBear Posted January 10, 2007 Share Posted January 10, 2007 I had one at New Year, I believe it had an attachment, but it never made it to me, wouldn't open!RegardsRich Quote Link to comment https://forums.phpfreaks.com/topic/33578-mysql-connect-question/#findComment-157525 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.