【发布时间】:2016-04-12 22:49:00
【问题描述】:
我正在编写一个连接到 WAMP 上的数据库的 php 页面。
我有以下代码:
$servername = "127.0.0.1";
$username = "root";
$password = "";
// connect to database
$conn = new mysqli($servername, $username, $password); //error line (1)
$sql = "USE xdbl0zz14_biodiversity";
$conn->query($sql); //error line (2)
错误行 (1) 给出以下错误:
Warning: mysqli::mysqli(): (HY000/2003): Can't connect to MySQL server on '127.0.0.1' (111)
错误行 (2) 给出以下错误:
Warning: mysqli::query(): Couldn't fetch mysqli
但我认为这是之前错误的直接结果。
我查看了 services.msc 并且 wampmysqld64 服务已启动。
提前谢谢你。
编辑
mysql 日志显示:
2016-04-05T12:05:50.193100Z 0 [Warning] InnoDB: Resizing redo log from 2*3072 to 2*320 pages, LSN=2471251
2016-04-05T12:05:50.380111Z 0 [Warning] InnoDB: Starting to delete and rewrite log files.
2016-04-05T12:05:51.310164Z 0 [Warning] InnoDB: New log files created, LSN=2471251
2016-04-12T11:10:57.423304Z 0 [Warning] wampmysqld64: Forcing close of thread 2 user: 'root'
2016-04-12T22:34:23.288955Z 0 [Warning] wampmysqld64: Forcing close of thread 2 user: 'root'
【问题讨论】:
-
MySQL 日志中是否有任何内容表明它无法启动?
-
你没有选择数据库
-
@Fred-ii- 虽然这样做有点奇怪,但
USE xdbl0zz14_biodiversity不应该这样做吗? -
把
'127.0.0.1'改成'localhost'看看能不能用。 -
@miken32 现在显示“无法通过套接字'/var/lib/mysql/mysql.sock' (2) 连接到本地 MySQL 服务器”