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と、コンピューターは のソケットを使用して MySQL サーバーにアクセスしようとします/var/mysql/mysql.sock。そのファイルが存在しないため、これは機能しません。ただし、127.0.0.1ホスト名として指定すると、MySQL 接続は TCP/IP 経由でセットアップされます。

この質問も参照してください。

したがって、答えは、MYSQL_HOSTが定義されている場所を見つけて に変更する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 に答える