LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
Search this Thread
Old 06-18-2007, 05:16 AM   #1
bosworthj
LQ Newbie
 
Registered: Aug 2006
Location: Michigan
Distribution: SUSE 10.1
Posts: 14

Rep: Reputation: 0
Cannot connect to MySQL


I am hoping someone that has more Linux experience than me can help me out here. I inherited support of a 8 year old Redhat 8 box running a work order system for our district using MySQL and PHP webpages. I decided to move the database over to a newer, faster, more stable machine. I have the database moved over okay and I can see the data using phpmyadmin and webmin. My problem now is the php pages don't seem to be connecting to the MySQL database. I am not sure where to look in the files to find that link or if that is even the issue. To keep things cleaner on the new server I stored the databases and the web pages in the default directory rather than a custom path like they were set up on the other server. I initially tried a custom path on the new server, but it broke Apache and I had to re-intall Apache. Any help would be greatly appreciated!!!

Thanks,

Jay
 
Old 06-18-2007, 05:48 AM   #2
SlackDaemon
Member
 
Registered: Mar 2006
Distribution: RedHat, Slackware, Experimenting with FreeBSD
Posts: 222

Rep: Reputation: 30
Did you move both the database and the PHP pages to the new server, or just the database?
Your best bet would be to locate the mysql_connect() entry for your PHP application and change the entries to match the new database servers' entries.
 
Old 06-18-2007, 05:52 AM   #3
bosworthj
LQ Newbie
 
Registered: Aug 2006
Location: Michigan
Distribution: SUSE 10.1
Posts: 14

Original Poster
Rep: Reputation: 0
Cannot Connect to MySQL

I did move the PHP pages and the MySQL database to the new server. I looked at the mysql_connect line in the code of the php page and I tried changing the host to the actual IP address of the computer. I also tried using various combinations of logins and passwords and it still says it can't connect. I tried to look at the info.php page to make sure all of that was working, but I just get a blank page when I tried to bring up that page. Other PHP pages show up fine though.

Thanks,

Jay
 
Old 06-18-2007, 12:06 PM   #4
SlackDaemon
Member
 
Registered: Mar 2006
Distribution: RedHat, Slackware, Experimenting with FreeBSD
Posts: 222

Rep: Reputation: 30
Try to connect to mysql from the command line with the stated username/password in the mysql_connect() function on your script:

mysql -u <username> -p

Then try to access the application database:

use <database_name>

Do you get any errors?

What is the specific error message you see on the screen when you run one of your PHP scripts?

If the phpinfo() page is blank, are you positive that PHP has been installed properly? i.e. Are the PHP functions that do not require a database connection working?

Check the httpd error logs to see if you get any additional information.
 
Old 06-19-2007, 06:27 AM   #5
bosworthj
LQ Newbie
 
Registered: Aug 2006
Location: Michigan
Distribution: SUSE 10.1
Posts: 14

Original Poster
Rep: Reputation: 0
Thank you for your reply. Yes, I do get errors when I try to connect to the database through the command line. I get a Error 1045 (28000) Access denied for user xxx'@'localhost (using password :yes)

I tried several of the usernames and passwords that are in the database.

When I use the root username and password, then I can get in. However when I put that user name and password into the PHP page and try to open the page, I still get this error: Failed to connect to the MySQL Aborting. That is the text that is in the section of code after the login and password. For example if it can't connect it posts that message.

I will move to the actual machine and post to this thread with some of the code from the error log in the apache folder.

Thanks,


Jay
 
Old 06-19-2007, 06:32 AM   #6
bosworthj
LQ Newbie
 
Registered: Aug 2006
Location: Michigan
Distribution: SUSE 10.1
Posts: 14

Original Poster
Rep: Reputation: 0
Here are just a couple of the lines from the error_log file in the /var/log/apache2 folder:

[Tue Jun 19 07:32:44 2007] [error] [client 127.0.0.2] PHP Fatal error: Call to undefined function reportError() in /srv/www/htdocs/julius/index.php on line 9
[Tue Jun 19 07:32:44 2007] [error] Failed to change_hat to 'HANDLING_UNTRUSTED_INPUT'
[Tue Jun 19 07:32:45 2007] [error] [client 127.0.0.2] PHP Warning: mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: Host '10.60.16.247' is not allowed to connect to this MySQL server in /srv/www/htdocs/julius/index.php on line 6

Thanks,

Jay
 
Old 06-19-2007, 07:34 AM   #7
p_s_shah
Member
 
Registered: Mar 2005
Location: India
Distribution: RHEL 3/4, Solaris 8/9/10, Fedora 4/8, Redhat Linux 9
Posts: 228
Blog Entries: 1

Rep: Reputation: 34
Try to connect to mysql from command line with -h [ for host ] option.
mysql -u <username> -p <dbname> -h <hostname/IP>
e.g.
mysql -u user1 -p testdb -h 10.60.16.247
If you are able to connect without any errors then Change your DB host to "10.60.16.247" in your config file and run php page again.
 
Old 06-19-2007, 07:47 AM   #8
bosworthj
LQ Newbie
 
Registered: Aug 2006
Location: Michigan
Distribution: SUSE 10.1
Posts: 14

Original Poster
Rep: Reputation: 0
This is what I get when I try to do that:

weaver:~ # mysql -u root -p maintenance -h 10.60.16.247
Enter password:
ERROR 1130 (00000): Host '10.60.16.247' is not allowed to connect to this MySQL server
weaver:~ #


Thanks,
 
Old 06-19-2007, 10:31 AM   #9
p_s_shah
Member
 
Registered: Mar 2005
Location: India
Distribution: RHEL 3/4, Solaris 8/9/10, Fedora 4/8, Redhat Linux 9
Posts: 228
Blog Entries: 1

Rep: Reputation: 34
Problem is with some missing includes.
Code:
[Tue Jun 19 07:32:44 2007] [error] [client 127.0.0.2] PHP Fatal error: Call to undefined function reportError() in /srv/www/htdocs/julius/index.php on line 9
It tells that your index.php is not able to find reportError() function, which is defined in some include file most probably.

Did location of your webroot is changed between two servers ?
If so, does your config file contains correct include path for site root [if used]?

This is the error, which prevents your page from execution.

#########################################
Once this error is resolved, you will receive lots of warnings for mysql_connect().
This errors are occuring due to GRANT permission for your dbuser on database.

Create testdb.php and put it into web root.
Code:
<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>
First make sure about one username/password pair.
Change host to localhost and check if you are getting error or not.
Change host to IP address of server and check if you are getting error or not.
If in both cases you are getting error, it means your user doesn't have permission on selected database.
So, Connect to mysql server using root login and provide sufficient privileges[ For test purpose you can grant all privileges to user ].
Flush the privileges once.

Update us with your findings for further troubleshooting.
Also tell us which GRANT query you executed for providing privileges to user.

Last edited by p_s_shah; 06-19-2007 at 10:34 AM.
 
Old 06-19-2007, 10:43 AM   #10
bosworthj
LQ Newbie
 
Registered: Aug 2006
Location: Michigan
Distribution: SUSE 10.1
Posts: 14

Original Poster
Rep: Reputation: 0
Thank you, I will check on this. What is the config file that I need to look at? I kept everything default on this server, so any idea where it might be located?

Thanks,

Jay
 
Old 06-19-2007, 10:20 PM   #11
SlackDaemon
Member
 
Registered: Mar 2006
Distribution: RedHat, Slackware, Experimenting with FreeBSD
Posts: 222

Rep: Reputation: 30
The user/password pair that your application is using to connect to the database does not exist on the new database. You will need to create them with the following statements:

grant all on <database_name>.* to <username>@localhost identified by '<password>';

flush privileges;


In the mysql_connect() function, replace the host IP with localhost

Besides this you also have the problem that p_s_shah pointed out (your missing an include). The old server's php.ini file would have told you where those files would be located. I hope that it hasn't been formatted!
 
Old 06-20-2007, 12:47 AM   #12
p_s_shah
Member
 
Registered: Mar 2005
Location: India
Distribution: RHEL 3/4, Solaris 8/9/10, Fedora 4/8, Redhat Linux 9
Posts: 228
Blog Entries: 1

Rep: Reputation: 34
For finding config file of DB Connection :
1. Go to the Webroot from command line.
2. Run following command after changing db name.
#grep "DBName" * -r
You will find which file contains DB connection settings.

For finding include file for particular function like reportError():
1. Go to the Webroot from command line.
2. Run following command.
# grep "function reportError(" * -r
If the above command shows zero result, means you are missing include file.

For finding Siteroot :
1. Check what was the web root on older server.
2. grep [Check for escape character] the complete path of older server's webroot on new server.

Note : This steps may vary according to your configuration. Don't stick on it. I suggested steps which works in most cases.
 
Old 06-20-2007, 06:17 AM   #13
bosworthj
LQ Newbie
 
Registered: Aug 2006
Location: Michigan
Distribution: SUSE 10.1
Posts: 14

Original Poster
Rep: Reputation: 0
Okay, let me try going about this another way I guess... I tried to run those grep commands and I couldn't find anything that stood out to me as what I was supposed to be looking for. Apparently the guy who set the server up had things hidden away in special directories. The result of the second grep command didn't find anything, but I know the include files have to be there because it was working fine. I was just moving it so it would be on a more stable server. Right now I just have the hard drive from the old server hooked up to the new server and I am using the mount command to get to the contents of it. If I could get it back in the old server and have that up and running that might help me find things better. Even though the old server was running fine, now when I try to start it, I get these errors on startup: Welcome to /etc/rc.d/rc.sysinit : Line 70 35 segmentation fault, Mounting proc File System failed line 70 90 segmentation fault, /proc must be mounted, line 182 65 segmentation fault, line 182 67 segmentation fault.

Any ideas on how to get the old server back up and running?

Thanks,

Jay
 
Old 07-30-2007, 06:30 PM   #14
walterbyrd
Member
 
Registered: Apr 2004
Posts: 565

Rep: Reputation: 30
When you installed php, did you also install the php4-mysql library? It has to be seperately installed. Once you install that, you need to /etc/php4/apache and edit the php.ini file. You need to uncomment this line.

;extensions=mysql.so

I think there is more to it than that. But that might get you started.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
ERROR 2002: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql. NoviceW Linux - Networking 17 09-17-2014 02:13 PM
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock welery Linux - Software 19 03-06-2014 07:19 AM
ERROR 2002: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql. suziecorbett Linux - Software 8 10-09-2008 01:52 AM
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' mohadesz Linux - Server 3 03-15-2008 05:06 AM
mysql error Can't connect to local MySQL server through socket '/var/lib/mysql/mysql. Dannux Linux - Software 3 03-24-2006 08:44 AM


All times are GMT -5. The time now is 09:34 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration