无法连接到数据库:用户''@ localhost'拒绝访问数据库'socialdb'

时间:2022-09-26 19:20:17

I've seen a few errors like this, but I found no answer.

我见过这样的一些错误,但我没有找到答案。

Unable to connect to database: Access denied for user ''@'localhost' to database 'socialdb'

socialdb is my database. The "Unable to connect to database:" part is located here.

socialdb是我的数据库。 “无法连接到数据库:”部分位于此处。

$db = mysql_select_db("socialdb",$con);

if(!$db) {

    die ('Unable to connect to database: ' . mysql_error());

    }

I don't know what's causing this. Here are my mysql_connect details

我不知道是什么造成了这种情况。这是我的mysql_connect详细信息

<?php
$con = mysql_connect("localhost");

if(!$con) {

    die ('Error: ' . mysql_error());

    }

I need to find the root. Thanks.

我需要找到根。谢谢。

I DON'T HAVE A USERNAME OR PASSWORD FOR MySQL

我没有MySQL的用户名或密码

Should it be this?

应该是这个吗?

mysql_connect("localhost","","");

6 个解决方案

#1


6  

The error is pretty self-explanatory, you're not allowed to connect without specifying some credentials.

该错误非常明显,如果不指定某些凭据,则不允许连接。

Change your call to mysql_connect() to something like this:

将对mysql_connect()的调用更改为以下内容:

mysql_connect("localhost", "user", "password");

#2


1  

Your default credentials are most likely:

您的默认凭据最有可能:

$con = mysql_connect("localhost","root","");

#3


0  

You're missing username and password parameter, should be:

你缺少用户名和密码参数,应该是:

$con = mysql_connect("localhost","username","password");

#4


0  

You did not specify a user in neither mysql_connect or your PHP configuration.

您没有在mysql_connect或PHP配置中指定用户。

Either set mysql.default_user and mysql.default_password in your PHP configuration or use the appropriate arguments for mysql_connect.

在PHP配置中设置mysql.default_user和mysql.default_password,或者为mysql_connect使用适当的参数。

#5


0  

mysql_connect takes 3 parameters

mysql_connect有3个参数

$con = mysql_connect("localhost", "dbuser", "password");

#6


0  

even if you are not having a user. there exist 'root' user so use it

即使你没有用户。存在'root'用户所以使用它

$con = mysql_connect('localhost','root','');

#1


6  

The error is pretty self-explanatory, you're not allowed to connect without specifying some credentials.

该错误非常明显,如果不指定某些凭据,则不允许连接。

Change your call to mysql_connect() to something like this:

将对mysql_connect()的调用更改为以下内容:

mysql_connect("localhost", "user", "password");

#2


1  

Your default credentials are most likely:

您的默认凭据最有可能:

$con = mysql_connect("localhost","root","");

#3


0  

You're missing username and password parameter, should be:

你缺少用户名和密码参数,应该是:

$con = mysql_connect("localhost","username","password");

#4


0  

You did not specify a user in neither mysql_connect or your PHP configuration.

您没有在mysql_connect或PHP配置中指定用户。

Either set mysql.default_user and mysql.default_password in your PHP configuration or use the appropriate arguments for mysql_connect.

在PHP配置中设置mysql.default_user和mysql.default_password,或者为mysql_connect使用适当的参数。

#5


0  

mysql_connect takes 3 parameters

mysql_connect有3个参数

$con = mysql_connect("localhost", "dbuser", "password");

#6


0  

even if you are not having a user. there exist 'root' user so use it

即使你没有用户。存在'root'用户所以使用它

$con = mysql_connect('localhost','root','');