数据库
首页 > 数据库> > php-显示错误:mysqli :: real_connect():(28000/1045):用户’user’@’192.188.145.163’的访问被拒绝(使用密码:是)

php-显示错误:mysqli :: real_connect():(28000/1045):用户’user’@’192.188.145.163’的访问被拒绝(使用密码:是)

作者:互联网

这是一个代码点火器项目.我给定的数据库信息是正确的,它在localhost中可以完美运行.但是在将我的项目上传到托管站点后,它仍然显示“拒绝访问”错误.

这是我的数据库:

 $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
);

我该如何解决?

解决方法:

实际上在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;

简单来说

Host = localhost (literally put localhost)
Database name = (cpanelUsername_databaseName)
Database username = (cpanelUsername_databaseUsername)
Database password = (******)

注意:
连接到数据库时,需要确保:

>您已经创建了一个数据库
>您已经创建了数据库用户名
>您已为该用户分配了数据库特权

您的MySQL连接可能使用127.0.0.1或服务器的IP地址,如果未为使用的特定IP地址授予访问权限,则MySQL将拒绝该连接.

验证服务器上的权限表(如果需要,重新加载授权)以及您要连接的权限表

Regrant通过:

GRANT ALL PRIVILEGES on *.* to 'user'@'IP' IDENTIFIED BY '*UserPass*';

标签:access-denied,codeigniter,mysql,php,database
来源: https://codeday.me/bug/20191119/2037279.html