• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 6072
  • Last Modified:

Dreamweaver - localhost mySQL database won't connect to my php site

I have a php site that has been running off a mySQL database very well.

I want to make some changes to the site but I want to run a testing environment on my local computer.

I'm using a Macintosh running Leopard. I installed MySQL and activated php and have the site running locally except that I can't connect to the local database from my local site. I'm using Dreamweaver to make the connection file. I'm using local host with root and no password.

I used navicat to duplicate the database from what it online. I am able to connect to this database on my localhost and everything seems fine until I try to connect to it using my Dreamweaver. Then it can't locate the database. I checked the settings and they are the same as on Navicat, which sees the database fine.

Any suggestions?

Also I'd like to put a password on the root user. How do I do that?
0
mrmyth
Asked:
mrmyth
  • 6
  • 3
  • 3
  • +1
3 Solutions
 
blckholehorizonCommented:
to set root password:

mysqladmin -u root password newpassword
0
 
mrmythAuthor Commented:
thanks for the reply

i opened terminal and put in exactly what you typed and it said unknown "mysqladmin: command not found"
0
 
ray-solomonCommented:
Sounds like you are in a user account and you will need to switch to the root account instead.

type:

su

in the terminal and then the root password.
This should give you permission to use mysqladmin.

0
Technology Partners: 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!

 
ray-solomonCommented:
hmm, I just read that the root user is disabled by default on Mac OS X and you cannot use the su command to switch to root.

Instead use:

sudo

http://www.macdevcenter.com/pub/a/mac/2002/10/22/macforunix.html
0
 
rbudjCommented:
Did you start Apache (or other) service?  I use WAMP (search google) for my local testing and it works perfectly with Dreamweaver 8 and CS3.  However, you have navigate through the Start menu to find the link that says "Start Apache"
0
 
blckholehorizonCommented:
to make sure the services are running, run netstat -a | grep tcp

make sure mysql is running on port 3306 ( or whatever port you have it on), and apache on port 80

after installing apache, it will not start automatically at boot time, until you tell it to do so by adding it as a service.  mysql either (unless you used the gui installer to do so)

if they are running, then make sure there is no firewall prohibiting access to them.
0
 
mrmythAuthor Commented:
All the services seem to be running.

I put a password on the root, but it seems when I use Navicat to look at my mySQL database, and use the username root, it still has no password.

My local website still can't access the MySQL database for some strange reason, but Navicat has no problem accessing the database.

I try to connect to it in Dreamweaver and it says "unknown error"

I get this
"Warning: mysql_pconnect() [function.mysql-pconnect]: Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2) in /Libarry/WebServer/Documents/MYWEBSITEFOLDER/Connections/conn_WEBSITE.php on line 9."

I don't think the firewall would have anything to do with it since it's local right?

0
 
blckholehorizonCommented:
are you using an options file for connections?  that could explain why certain connections work, and some don't.  Try connecting over a TCP/IP socket instead of a socket file. also use 'localhost' instead of the IP address for a tcp/ip connection.

If still using a socket file, do the connecting programs have the rights to access the socket file if you are using?
0
 
mrmythAuthor Commented:
I got into a whole thing with the socket file and it seems to be getting closer.

Now it appears that the local website is trying to access the database, but it still can't.

I'm not getting the error that says it can't find the mysql.sock file

I followed these directions that I found:
"Bring the mysql.sock to PHP
One problem that has come about with MySQL and Leopard is the location of the mysql.sock file. Previously, the default location for this file was in the /tmp directory. That location has now moved to the /var/mysql directory. PHP will look for it there. Unfortunately, the default location from the MySQL will still place it in the old location. We can fix this by creating a my.cnf configuration file in the /etc directory. Save a file with the following contents to /etc/my.cnf:

[client]
socket = /var/mysql/mysql.sock

[mysqld]
socket = /var/mysql/mysql.sock

In the terminal window, type the following commands to create the directory for the sock file:

sudo mkdir /var/mysql
sudo chown _mysql /var/mysql"

Now I still can't connect to the database when I try to add it in Dreameaver.
I get "an unidentified error has occured"


0
 
mrmythAuthor Commented:
As far as Dreamweaver goes, I still can't get it to open that database, but when I put in all the pertinent data the connection does occur at the website level.

I was able to configure the php to work on the localhost by following the directions outlined here

http://www.procata.com/blog/archives/2007/10/28/working-with-php-5-in-mac-os-x-105/

especially the section that I recounted above

The Dreamweaver problem is still happening where it says "an unidentified error has occurred" when I try to connect to the database from within Dreamweaver.
0
 
ray-solomonCommented:
Read the mysql manual for mac os x installation and also read all the user comments for tips.
http://dev.mysql.com/doc/refman/5.0/en/mac-os-x-installation.html

There is a dreamweaver comment in the user comments as well.




I would recommend creating a new php file then access it in your browser if you have apache and php working and configured properly on the computer.  This connection code is for testing purposes only to see what specific error messages are returned. It is helpful in correcting basic connection mistakes.

<?php

define('DB_HOST', 'localhost'); // stays as localhost
define('DB_USERNAME', 'your-database-username');
define('DB_PASSWORD', 'your-database-password');
define('DB_NAME', 'your-database-name');

@mysql_connect(DB_HOST,DB_USERNAME,DB_PASSWORD) or die(mysql_error());
@mysql_select_db(DB_NAME) or die(mysql_error());

?>
0
 
mrmythAuthor Commented:
Thanks for the advice. The final step of getting it to work was just to make sure that I set a testing site. I made it the same as the testing folder on my computer that I'm using and Dreamweaver can now connect.
If I would have just read the steps in the database connection box I wouldn't have had this final problem.


0
 
mrmythAuthor Commented:
In retrospect I think I should have just downloaded MAMP to properly setup the LAMP server on my mac. I assume it would resolve some of these problems.
0

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

  • 6
  • 3
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now