无法连接到MySQL localhost [英] Cannot Connect to MySQL localhost
问题描述
大家好,
i下载了PHP 5和APACHE 2.我能够配置PHP5和APACHE2一起工作并运行.PHP文件。
i还在我的本地机器上安装了MySQL 5.6,在安装过程中它问我应该选择什么类型的安装。
这里是选项:
1.开发
2.服务器
3.专用
i选择服务器,因为我希望机器作为本地网络上的服务器。一切进展顺利,安装随MySql Workbench一起提供,我可以使用workbench连接到MySql DB。我创建了一个用于测试的数据库'dbsample',添加了一些表格和虚拟数据,一切正常。
现在,我的困境是我似乎无法连接PHP5到MySql。
我创建了一个带有这样代码的示例.php文件。
i赋予'用户'访问数据库的所有权限。
<?php
error_reporting(E_ALL);
ini_set(' display_errors',1);
// mysqli
$ host = localhost;
$ port = 3306;
$ user = user;
$ password = password;
$ dbname = dbtimereport;
$ mysqli = new mysqli_connect($ host,$ user,$ password) ,$ dbname,$ port)
if (mysqli_connect_error()){
die(' 连接错误(' .mysqli_connect_errno()。' )'
.mysqli_connect_error());
}
echo ' 成功......。 $ mysqli-> host_info。 \ n;
// 关闭连接
$ mysqli->关闭();
?>
i去了我的PHP directoty和修改后的php.ini并启用了以下行来支持mysql。
但仍然没有运气。我不知道这个错误会来自哪里或哪里?因为该页面没有显示任何错误消息。
extension = php_mysql.dll
extension = php_mysqli.dll
extension = php_pdo_mysql.dll
以下是来自MySql WorkBench的一些信息
名称:本地MySql实例
主机:localhost
端口:3306
版本:5.6.19-log
登录用户:user
当前用户:user @ localhost
提前感谢所有帮助。
host = localhost;
port = < span class =code-string> 3306;
user = 用户跨度>;
Hi Everyone,
i downloaded the PHP 5 and APACHE 2. i was able to configure PHP5 and APACHE2 to work together and run .PHP files.
i just also installed MySQL 5.6 on my local machine, during installation it asked me what type of installation should i choose.
here are the option:
1. Development
2. Server
3. Dedicated
i selected server as i would like the machine to serve as a server on my local network. everything was going well, the installation came with MySql Workbench and i am able to connect to MySql DB with workbench. i created a database 'dbsample' for testing, added some tables and dummy data and everything works.
Now, my dilema is that i can't seem to connect PHP5 to MySql.
i created a sample .php file with code like this.
i have given 'user' all privilege to access the database.
<?php
error_reporting (E_ALL);
ini_set('display_errors', 1);
// mysqli
$host="localhost";
$port="3306";
$user="user";
$password="password";
$dbname="dbtimereport";
$mysqli = new mysqli_connect($host, $user, $password, $dbname, $port)
if (mysqli_connect_error()) {
die('Connect Error (' . mysqli_connect_errno() . ') '
. mysqli_connect_error());
}
echo 'Success... ' . $mysqli->host_info . "\n";
//Close Connection
$mysqli->close();
?>
i went to my PHP directoty and modified php.ini and enabled below lines to support mysql.
but still no Luck. i dont' know what or where could the error be coming from? as the page does not show any error message.
extension=php_mysql.dll
extension=php_mysqli.dll
extension=php_pdo_mysql.dll
below are some info from the MySql WorkBench
Name: Local MySql Instance
Host: localhost
Port: 3306
Server: MySQL Community Server (GPL)
Version: 5.6.19-log
Login User: user
Current User: user@localhost
Thanks in advance for all the help.
host="localhost";
port="3306";
user="user";
这篇关于无法连接到MySQL localhost的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!