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?
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.  http://php.net/manual/en/book.mysqli.php
0
Bill SullivanCEOAuthor Commented:
Here is the php code calling for the database:

include("millie.inc");
                  $connection=mysql_connect($host,$user,$password)
                        or die ("couldn't connect to server");
                  $db = mysql_select_db($database,$connection)
                        or die ("couldn't select database");

millie.inc looks like this:
<?php
      $user="bsullivan";
      $host="127.0.0.1";
      $password="csrSully";
      $database="SECURE";
?>

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?
0
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.
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

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 'php.in' and you definitely need to move to 'mysqli' instead of 'mysql'.
0

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?
0
arnoldCommented:
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 127.0.0.1 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
0
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.
extension=php_mysql.dll
extension=php_mysqli.dll
extension=php_pdo_mysql.dll
extension=php_pdo_odbc.dll

Open in new window

0
Bill SullivanCEOAuthor Commented:
did that - still didn't work.  Any other ideas?
0
Dave BaldwinFixer of ProblemsCommented:
Are they showing in phpinfo() now?
0
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?
0
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.   https://dev.mysql.com/doc/refman/5.1/en/user-account-management.html
0
arnoldCommented:
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.
.......
0
Bill SullivanCEOAuthor Commented:
when I do arnold's suggestion above, terminal returns "Access denied for user 'bsullivan'@'localhost' (using password: YES)"
0
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.  ??
0
arnoldCommented:
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.
0
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.

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.