LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 07-07-2009, 02:41 PM   #1
cooljkb14
LQ Newbie
 
Registered: Jun 2008
Posts: 18

Rep: Reputation: 0
connection problem with mysql server through php


i m having a problem::
i m using fedora 10...
and when i tried to run a simple php program (code is given below)

<?php
$dbhost = 'localhost.localdomain.com:3306';
$dbuser = 'root';
$dbpass = 'root123';
$link = mysql_connect($dbhost,$dbuser,$dbpass);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>

the browser shows the following error message....

"Could not connect: Can't connect to MySQL server on 'localhost.localdomain.com' (4)"

httpd is assign a 8080 port no.
if you know any solution then help me out.........

Last edited by cooljkb14; 07-07-2009 at 02:43 PM.
 
Old 07-07-2009, 04:01 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by cooljkb14 View Post
i m having a problem::
i m using fedora 10...
and when i tried to run a simple php program (code is given below)

<?php
$dbhost = 'localhost.localdomain.com:3306';
$dbuser = 'root';
$dbpass = 'root123';
$link = mysql_connect($dbhost,$dbuser,$dbpass);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>

the browser shows the following error message....

"Could not connect: Can't connect to MySQL server on 'localhost.localdomain.com' (4)"

httpd is assign a 8080 port no.
if you know any solution then help me out.........
As your error message says:

Quote:
Can't connect to MySQL server on 'localhost.localdomain.com'
Your web server is up, but it appears that MySQL isn't running. If MySQL isn't running, you won't be able to connect to the database. Start MySQL up with the "/etc/init.d/mysql start" command.

And http is usually running on port 80, unless you configure it otherwise, or your distro ships with the config set to 8080. You can run it on alot of different ports...

Last edited by TB0ne; 07-07-2009 at 04:04 PM.
 
Old 07-08-2009, 03:25 AM   #3
ap0calypse
Member
 
Registered: Jul 2009
Location: Austria
Distribution: Slackware
Posts: 38

Rep: Reputation: 16
Is your MySQL-Daemon configured to listen on Port 3306? Have a look at your corresponding my.cnf in your mysqld config directory.
 
Old 07-08-2009, 12:57 PM   #4
cooljkb14
LQ Newbie
 
Registered: Jun 2008
Posts: 18

Original Poster
Rep: Reputation: 0
i m using fedora 10
php5 and mysql-5.0.67 and the packages are updated. also i can use the services separately but not able to connect php and mysql..
and when i simply run this code

<?php
$link=mysql_connect('localhost.localdomain:3306',"root","123");
if($link)
echo "connected";
else
echo "1";
?>

and i get "1" as a result.........

changes in /etc/php.ini

\\\extension=mysql.so
mysql_default_port=3306
mysql_socket_port=3306///

changes in /etc/httpd/conf/httpd.conf

\\\listen:10.2.13.124:8080
servername www.localhost.localdomain.com:8080

but still i m not able to connect to the mysql database.........
wat i m doing wrong????????

i would really appreciate if u help.......
 
Old 07-09-2009, 01:27 AM   #5
ap0calypse
Member
 
Registered: Jul 2009
Location: Austria
Distribution: Slackware
Posts: 38

Rep: Reputation: 16
You misunderstood me.

There is a mysqld configuration file (in slackware it's /etc/my.cnf). There are the settings for the database server itself. You should have a look especially at these lines:

port = 3306
skip-networking


What do they say in your configuration?

Last edited by ap0calypse; 07-09-2009 at 01:28 AM.
 
Old 07-09-2009, 06:38 AM   #6
cooljkb14
LQ Newbie
 
Registered: Jun 2008
Posts: 18

Original Poster
Rep: Reputation: 0
file configuration

Quote:
Originally Posted by ap0calypse View Post
You misunderstood me.

There is a mysqld configuration file (in slackware it's /etc/my.cnf). There are the settings for the database server itself. You should have a look especially at these lines:

port = 3306
skip-networking


What do they say in your configuration?

here's the my.cnf file
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=root
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=123

# To allow mysqld to connect to a MySQL Cluster management daemon, uncomment
# these lines and adjust the connectstring as needed.
ndbcluster
ndb-connectstring="nodeid=4;host=localhost.localdomain:3306"

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

[ndbd]
# If you are running a MySQL Cluster storage daemon (ndbd) on this machine,
# adjust its connection to the management daemon here.
# Note: ndbd init script requires this to include nodeid!
connect-string="nodeid=2;host=localhost.localdomain:3306"

[ndb_mgm]
# connection string for MySQL Cluster management tool
connect-string="host=localhost.localdomain:3306"
 
Old 07-10-2009, 01:16 AM   #7
ap0calypse
Member
 
Registered: Jul 2009
Location: Austria
Distribution: Slackware
Posts: 38

Rep: Reputation: 16
Ok. Append this to your [mysqld]-part:
port = 3306


and then restart the mysqld and look for a listening connection on port 3306.

you can do this with nmap:
nmap localhost -p3306

or with netstat:
netstat -tan | grep 3306

Tell me if this helped.
 
Old 07-10-2009, 01:41 AM   #8
cooljkb14
LQ Newbie
 
Registered: Jun 2008
Posts: 18

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by ap0calypse View Post
Ok. Append this to your [mysqld]-part:
port = 3306


and then restart the mysqld and look for a listening connection on port 3306.

you can do this with nmap:
nmap localhost -p3306

or with netstat:
netstat -tan | grep 3306

Tell me if this helped.
thanks for ur help i really apreciate it.. but i changed my.cnf by adding "skip-grant-tables" and then restarting again and reseting the password of root user in mysql.user table and then deleting the "skip" line and restarting the service again and it worked thanx for ur help anywayz....

Now can u tell me how to import the access file through mysql commands.. or any other method
 
Old 07-10-2009, 01:06 PM   #9
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by cooljkb14 View Post
thanks for ur help i really apreciate it.. but i changed my.cnf by adding "skip-grant-tables" and then restarting again and reseting the password of root user in mysql.user table and then deleting the "skip" line and restarting the service again and it worked thanx for ur help anywayz....

Now can u tell me how to import the access file through mysql commands.. or any other method
You might want to check the other thread you opened, asking how to import Access data into MySQL. There are answers there.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
is there a client install for MySql so PHP can connect to MySQL Server? alar Linux - Software 8 07-03-2007 07:42 PM
MySQL client/server connection problem crashsystems Linux - Server 2 02-06-2007 12:05 PM
php-mysql connection pb abd_bela Debian 2 09-23-2005 04:07 AM
php / mysql connection problem . MikeFoo1 Programming 3 05-02-2004 05:22 PM
MySQL server connection problem aeshley Programming 1 03-05-2002 09:59 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 01:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration