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?
Who is Participating?
blckholehorizonConnect With a Mentor Commented:
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?
to set root password:

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

i opened terminal and put in exactly what you typed and it said unknown "mysqladmin: command not found"
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Sounds like you are in a user account and you will need to switch to the root account instead.



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

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:


rbudjConnect With a Mentor Commented:
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"
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.
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?

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:

socket = /var/mysql/mysql.sock

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"

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


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.
ray-solomonConnect With a Mentor Commented:
Read the mysql manual for mac os x installation and also read all the user comments for tips.

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.


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());

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.

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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.