简体   繁体   English

mysql_connect():用户'root'@'localhost'的访问被拒绝

[英]mysql_connect(): Access denied for user 'root'@'localhost'

For school I have to build and basic website using PHP and MySQL. 对于学校,我必须使用PHP和MySQL构建和基本的网站。 The websites function is to allow a user to register and then sign in and out. 网站功能是允许用户注册然后登录和注销。 To do this, since I have no prior knowledge of PHP I was trying to follow this tutorial . 为此,由于我没有PHP的先验知识,因此我尝试遵循本教程 I got sever space with godaddy and using MySQL I created the database called details_db. 我通过godaddy获得了足够的空间,并使用MySQL创建了一个名为details_db的数据库。 I created the files the tutorial told me and uploaded to the server. 我创建了教程告诉我的文件,并上传到服务器。 Now when I go onto the website I get these errors. 现在,当我进入网站时,我得到了这些错误。

Warning: mysql_connect(): Access denied for user 'root'@'localhost' (using password: NO) in /home/pendrive34/public_html/dbconnect.php on line 12 警告:mysql_connect():在第12行的/home/pendrive34/public_html/dbconnect.php中,对用户'root'@'localhost'的访问被拒绝(使用密码:NO)

Warning: mysql_select_db(): Access denied for user ''@'localhost' (using password: NO) in /home/pendrive34/public_html/dbconnect.php on line 13 警告:mysql_select_db():在第13行的/home/pendrive34/public_html/dbconnect.php中,对用户“ @'localhost”的访问被拒绝(使用密码:NO)

Warning: mysql_select_db(): A link to the server could not be established in /home/pendrive34/public_html/dbconnect.php on line 13 Connection failed : Access denied for user ''@'localhost' (using password: NO) 警告:mysql_select_db():在第13行的/home/pendrive34/public_html/dbconnect.php中无法建立到服务器的链接连接失败:对用户``@'localhost'的访问被拒绝(使用密码:NO)

This is the code in the file deconnect.php 这是文件deconnect.php中的代码

<?php

// this will avoid mysql_connect() deprecation error.
error_reporting( ~E_DEPRECATED & ~E_NOTICE );
// but I strongly suggest you to use PDO or MySQLi.

define('DBHOST', 'localhost');
define('DBUSER', 'root');
define('DBPASS', '');
define('DBNAME', 'details_db');

$conn = mysql_connect(DBHOST,DBUSER,DBPASS);
$dbcon = mysql_select_db(DBNAME);

if ( !$conn ) {
    die("Connection failed : " . mysql_error());
}

if ( !$dbcon ) {
    die("Database Connection failed : " . mysql_error());
}

I've been trying to find the answer to the problem for a while but my limited knowledge is holding me back. 我一直在尝试寻找问题的答案,但是我有限的知识使我退缩。

You have to write mysql root users password to 您必须编写mysql root用户密码才能

define('DBPASS', '');

this line like.. 这条线像..

define('DBPASS', 'password_of_root_user');

If you are trying to connect a database on remote machine (like a shared hosting), you have to change DBHOST, DBUSER and DBPASS to values that given you by hosting company. 如果您尝试连接远程计算机上的数据库(例如共享托管),则必须将DBHOST,DBUSER和DBPASS更改为托管公司提供的值。

you need to provide the password in define('DBPASS', 'PASSWORD'); 您需要在define('DBPASS', 'PASSWORD');提供密码define('DBPASS', 'PASSWORD');

if you are working on local machine the default password might be " root " 如果您在本地计算机上工作,则默认密码可能是“ root

define('DBPASS', 'root');

暂无
暂无

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

相关问题 mysql_connect():用户“ root”的访问被拒绝 - mysql_connect(): Access denied for user 'root' 警告:mysql_connect():用户&#39;root&#39;@&#39;localhost&#39;拒绝访问(使用密码:YES) - Warning: mysql_connect(): Access denied for user 'root'@'localhost' (using password: YES) mysql_connect():用户&#39;user&#39;@&#39;localhost&#39;的访问被拒绝 - mysql_connect() : Access denied for user 'user'@'localhost' mysql_connect():用户&#39;mss&#39;@&#39;localhost&#39;拒绝访问 - mysql_connect(): Access denied for user 'mss'@'localhost' PHP警告mySql_connect()第4行对用户&#39;a34525_user&#39;@&#39;localhost&#39;的访问被拒绝(使用密码:是) - PHP Warning mySql_connect() Access denied for user 'a34525_user'@'localhost' (using password: YES) on line 4 mysql_connect(): 用户 &#39;adminryan&#39;@&#39;localhost&#39; 访问被拒绝(使用密码:YES) - mysql_connect(): Access denied for user 'adminryan'@'localhost' (using password: YES) mysql_connect()访问被拒绝 - mysql_connect() access denied mysql_connect:访问被拒绝 - mysql_connect: Access denied mysql_connect():拒绝用户“ user” @“ host”的访问(使用密码:NO) - mysql_connect(): Access denied for user 'user'@'host' (using password: NO) WebsitePanel-mysql_connect():第38行对用户&#39;user&#39;@&#39;localhost&#39;的访问被拒绝(使用密码:是)。连接到mysql时出错 - WebsitePanel - mysql_connect(): Access denied for user 'user'@'localhost' (using password: YES) on line 38. Error connecting to mysql
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM