简体   繁体   English

如何连接到WAMP服务器上的MySQL?

[英]How can I connect to MySQL on a WAMP server?

This might be ridiculously easy for you but I've been struggling with this for an hour... :( 这对您来说可能很容易,但是我已经为此苦苦挣扎一个小时了... :(

<?php
$connect = mysql_connect("localhost:8080", "root", "mypassword");
echo($connect);?>

This is the code that I'm trying to run - you can see that I'm using 8080 as my port number and, of course, I have HTML codes as well. 这是我要运行的代码-您可以看到我使用8080作为端口号,当然,我也有HTML代码。

However, it gives me the following error messages whenever I try to open the PHP file: 但是,每当我尝试打开PHP文件时,它都会给我以下错误消息:

Warning: mysql_connect() [function.mysql-connect]: MySQL server has gone away in C:\wamp\www\php_sandbox\index.php on line 2

Warning: mysql_connect() [function.mysql-connect]: Error while reading greeting packet. PID=4932 in C:\wamp\www\php_sandbox\index.php on line 2

Warning: mysql_connect() [function.mysql-connect]: MySQL server has gone away in C:\wamp\www\php_sandbox\index.php on line 2

I don't know... what's wrong with this? 我不知道...这是怎么了? Is it because of the port number? 是因为端口号吗?

将localhost:8080更改为localhost:3306。

尝试打开端口3306,并在连接字符串(而不是8080)中使用该端口。

只需将“连接” mysql字符串更改为127.0.0.1,它将起作用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM