php 显示错误:mysqli::real_connect(): (28000/1045): 用户 'user'@'192.188.145.163' 访问被拒绝(使用密码:是)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33142187/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Showing Error: mysqli::real_connect(): (28000/1045): Access denied for user 'user'@'192.188.145.163' (using password: YES)
提问by Mamun Sabuj
This is a codeigniter project. my given database information is right.It works perfectly in localhost. But after uploading my project in hosting site, it still shows an 'access denied' error.
这是一个代码点火器项目。我给定的数据库信息是正确的。它在本地主机中完美运行。但是在托管站点上传我的项目后,它仍然显示“拒绝访问”错误。
This is my database:
这是我的数据库:
$db['default'] = array(
'dsn' => '',
'hostname' => 'telihatyhighschool.edu.bd',
'username' => 'db_username',
'password' => 'db_password',
'database' => 'db_name',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array() ,
'save_queries' => TRUE
);
How can I solve this ?
我该如何解决这个问题?
回答by Linus
In cpannel actually username and database name has cpanel username prefix eg
在 cpannel 实际上用户名和数据库名称具有 cpanel 用户名前缀,例如
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'localhost'; //literaly put localhost
$db['default']['username'] = 'cpanelusername_root';
$db['default']['password'] = 'password';
$db['default']['database'] = 'cpanelusername_db name';
$db['default']['dbdriver'] = 'mysqli'; ///use this extension
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
in more simple words
用更简单的话来说
Host = localhost (literally put localhost)
Database name = (cpanelUsername_databaseName)
Database username = (cpanelUsername_databaseUsername)
Database password = (******)
NOTE:When connecting to a database, you need to ensure that:
注意:连接到数据库时,您需要确保:
- You've created a database
- You've created a database username
- You've assigned that user with privileges to your database
- 你已经创建了一个数据库
- 您已经创建了一个数据库用户名
- 您已为该用户分配了对您的数据库的权限
Your MySQL connections may use 127.0.0.1 or the IP address of your server, and MySQL will reject the connection if access isn't granted for the specific IP address used.
您的 MySQL 连接可能使用 127.0.0.1 或您服务器的 IP 地址,如果使用的特定 IP 地址未授予访问权限,MySQL 将拒绝连接。
Verify the permission tables (reloading grants if required) on the server and that you're connecting to
验证服务器上的权限表(如果需要,重新加载授权)以及您要连接到
Regrant Preveliges by :
Regrant Preveliges 由 :
GRANT ALL PRIVILEGES on *.* to 'user'@'IP' IDENTIFIED BY '*UserPass*';
回答by Abdulla Nilam
If your hosting server is Linux,
如果您的托管服务器是 Linux,
Change hostname
value to localhost
将hostname
值更改为localhost
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'user',
'password' => 'XXXXXXXX',
'database' => 'mydbname',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array() ,
'save_queries' => TRUE
);
回答by Mamun Sabuj
Yeah, I have solved this problem changing:
是的,我已经解决了这个问题改变:
$db['default'] = array('dsn' => '','hostname' => 'telihatyhighschool.edu.bd',
to:
到:
$db['default'] = array('dsn' => '','hostname' => 'localhost',
回答by noushad mohammed
I had the same error but all the error are resolved by adding privileges to that user
我遇到了同样的错误,但通过向该用户添加权限来解决所有错误
回答by Shento
Try to use the plain password with no special characters, below is the example:
尝试使用没有特殊字符的普通密码,示例如下:
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'password',
'password' => 'Mynewpass@756',
'database' => 'database_name',
);
回答by Kanak Sony
I resolved this issue by adding a User under Privileges for the database. This User should have the same values as database.php:
我通过在数据库的权限下添加用户解决了这个问题。此用户应具有与 database.php 相同的值:
'hostname' => 'localhost',
'username' => 'username',
'password' => 'password',
回答by Robert
SOLVED
解决了
- create a new database from cpanel
- create a new username
- assigned that user with privileges to your database
- modify file database.php with new information database
- 从 cpanel 创建一个新数据库
- 创建一个新用户名
- 为该用户分配了对您的数据库的权限
- 用新的信息数据库修改文件database.php
public_html/application/config/database.php
public_html/application/config/database.php
- export database from your old hosting cpanel - option phpmyadmin
- import database to you new hosting cpanel- option phpmyadmin
- DONE
- 从旧的托管 cpanel 导出数据库 - 选项 phpmyadmin
- 将数据库导入您的新主机 cpanel-选项 phpmyadmin
- 完毕
回答by Makarand
I had same problem. I had codeigniter project live on my server.
我有同样的问题。我的服务器上有 codeigniter 项目。
Solution:
解决方案:
In File Managerin codeigniter project public_html/your_project_name/application/config/database.php
在codeigniter 项目的文件管理器中 public_html/your_project_name/application/config/database.php
I added the password which was missing. [ Password of user when you created it in Cpanel -> MySQL Databases]
我添加了丢失的密码。[在Cpanel 中创建时的用户密码-> MySQL 数据库]
**Make sure you have assigned the database access to this user with all privileges and your configurations in database.php
are correct.
**确保您已将数据库访问权限分配给具有所有权限的用户,并且您的配置database.php
正确。
Mine are:
我的是:
$active_group = 'default';
$query_builder = TRUE;
$db['default'] = array(
'dsn' => '',
'hostname' => 'YOUR_DOMAIN_NAME', //Ex- abcd.com
'username' => 'USER_NAME_HERE',// CREATED IN CPANEL->MySQL Database
'password' => 'PASSWORD_HERE', // PASSWORD OF ABOVE USER
'database' => 'YOUR_DB_NAME',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);