Can't connect to Mysql Database

I'm running Mysql 5.6.26 on a Mac OS 10.10.  When I load my index page, I can see my website, but when my php code tries to access the Mysql server, I get an error "Warning: mysql_connect(): Connection refused in '... url ...' on line 25 couldn't connect to server."

I can see the database I'm trying to reach in Finder, but I think there is perhaps something wrong in my Mysql setup.

Any help would be appreciated!!!
Bill SullivanCEOAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
Please show us the PHP code you are trying to use.  What version of PHP are you using?  Also, the 'mysql' extension is deprecated.  The current extension is 'mysqli'.  Note the extra 'i' at the end.
Bill SullivanCEOAuthor Commented:
Here is the php code calling for the database:

                        or die ("couldn't connect to server");
                  $db = mysql_select_db($database,$connection)
                        or die ("couldn't select database"); looks like this:

I am using PHP 5.5.27, and I noticed that "Loaded Configuration File" = (none) - I cannot find PHP.ini anywhere.  I'm wondering if this is the problem?
Bill SullivanCEOAuthor Commented:
I found php.ini.default and renamed it to php.ini

Now my error reads only "couldn't connect to server" which is the text my php code says to display when mysql_connect dies.
The 7 Worst Nightmares of a Sysadmin

Fear not! To defend your business’ IT systems we’re going to shine a light on the seven most sinister terrors that haunt sysadmins. That way you can be sure there’s nothing in your stack waiting to go bump in the night.

Dave BaldwinFixer of ProblemsCommented:
The 'mysql' extension has been deprecated as of PHP 5.5 and removed from PHP 7.0.

All of the extensions are enabled in 'php.ini' so if it does not exist, that indeed could be your problem.  Though I would expect an error saying it wasn't available instead.  You may need to edit '' and you definitely need to move to 'mysqli' instead of 'mysql'.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bill SullivanCEOAuthor Commented:
phpinfo now finds php.ini, but I still cannot connect to the database.  Do you know what the php.ini file should say?
Look at /etc/mysql.cnf

Make sure MySQL starts and U.S. Listening on port 3306

Are you able to connect mysql -u bsullivan -pcsrSully -h SECURE
See if you get an informative error.
Or add to your php code a $! In the die command so you can see the true error for the connection failure.

See whether you should use mysql_connect versus mysqli_connect
Dave BaldwinFixer of ProblemsCommented:
In the extensions area of 'php.ini', these extensions should be uncommented (';' removed) for MySQL to work and the server restarted so they will be used.

Open in new window

Bill SullivanCEOAuthor Commented:
did that - still didn't work.  Any other ideas?
Dave BaldwinFixer of ProblemsCommented:
Are they showing in phpinfo() now?
Bill SullivanCEOAuthor Commented:
yes. now the error I'm receiving says Access denied for user 'bsullivan'@'localhost' (using password: YES)

Is it possible I have not set permissions correctly for my username?  If so, how do I do that?
Dave BaldwinFixer of ProblemsCommented:
MySQL Privileges are set with username, password, and host.  '%' (or 'anyhost') and 'localhost' are not the same although we frequently use the same username and password with them.
Yes, after you created/granted rights to user, make sure to run flush privileges;

The php.ini changes for dll are unneeded for Mac/osX based systems.  The .dll is for windows.

Rerun the MySQL command I posted to test once you successfully login, your php will start working as well.
MySQL -u root
Or include -p if you set root password.
flush privileges;
Then try your user login again.
Bill SullivanCEOAuthor Commented:
when I do arnold's suggestion above, terminal returns "Access denied for user 'bsullivan'@'localhost' (using password: YES)"
Dave BaldwinFixer of ProblemsCommented:
The php.ini changes for dll are unneeded for Mac/osX based systems.  The .dll is for windows.
'dll' should probably be 'so' instead.

If you can get in as 'root', change the user password for 'bsullivan' to something else.  ??
Did you execute flush privileges after you created/granted rights to the user?
Whenever security changes are made, the flush command has to be run to have MySQL server made aware of the security changes.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Web Server

From novice to tech pro — start learning today.