1

Probably just because I'm not experienced with this sort of thing, but I downloaded MySQL with Apache running, and I'm working with the following code in a PHP file:

public static $connection = NULL;

private static $host = MYSQL_HOST;
private static $username = MYSQL_USER;
private static $passwd = MYSQL_PASS;
private static $db = MYSQL_DBNAME;

public static function init() {
  if(!self::$connection) {
    self::$connection = new mysqli(self::$host, self::$username, self::$passwd, self::$db);
}

}

It comes up with this when I open it in Firefox:

trying to connect via unix:///var/mysql/mysql.sock (says this doesn't exist—which, it doesn't)

I replaced MYSQL_HOST with 'localhost', MYSQL_USER with both 'mysql' and 'root' (stupid, yes), MYSQL_PASS with both my system password and NULL, and MYSQL_DBNAME with a few more things (I am having trouble finding out what my database name is called, even with MySQLWorkbench...I started learning this entire field of computing two days ago). It does say that a MySQL server is running on my machine, just not sure how to put the legos together here. Most of the settings are default (port 3306 and such). A test database migration over MySQLWorkBench failed (something to do with not reading the number of rows correctly), but otherwise it was fine and dandy, from what I saw.

Any help would be very welcome!

3
  • 3
    Don't kill your testability with statics! Commented Jan 8, 2013 at 6:05
  • What operating system are you using? Commented Jan 8, 2013 at 7:00
  • Sorry, failed to mention that—MAC OS X Mountain Lion Commented Jan 8, 2013 at 13:54

2 Answers 2

1

When you specify localhost as the host name, your computer will try to access the MySQL server using sockets in /var/mysql/mysql.sock. Since that file does not exist, this won't work. However, when you specify 127.0.0.1 as host name, the MySQL connection is set up over TCP/IP.

See also this question.

So the answer is to either find where MYSQL_HOST is defined and change it to be 127.0.0.1, or forget about MYSQL_HOST and just enter 127.0.0.1 instead. The latter is harder to maintain in case you would want to move your site to some other location (server).

Sign up to request clarification or add additional context in comments.

Comments

0

Try restarting SQL server. This may recreate the missing .sock file. See here for info on restarting: http://theos.in/desktop-linux/tip-that-matters/how-do-i-restart-mysql-server/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.