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!

4

2 回答 2

1

当您指定localhost为主机名时,您的计算机将尝试使用/var/mysql/mysql.sock. 由于该文件不存在,因此这不起作用。但是,当您指定127.0.0.1为主机名时,MySQL 连接是通过 TCP/IP 建立的。

另请参阅此问题

所以答案是要么找到 where MYSQL_HOSTis defined 并将其更改为127.0.0.1,要么忘记MYSQL_HOST并直接输入127.0.0.1。如果您想将站点移动到其他位置(服务器),后者更难维护。

于 2013-01-08T20:33:09.723 回答
0

尝试重新启动 SQL 服务器。这可能会重新创建丢失的 .sock 文件。有关重新启动的信息,请参见此处:http: //theos.in/desktop-linux/tip-that-matters/how-do-i-restart-mysql-server/

于 2013-01-08T06:10:20.830 回答