我尝试从我的localhost访问所有远程服务器mysql数据。但我不知道如何连接远程数据库服务器我的本地数据库。 我的本地数据库连接代码是
$db['on_app']['hostname'] = 'host ip address';
$db['on_app']['username'] = 'host username';
$db['on_app']['password'] = 'host password';
$db['on_app']['database'] = 'host db name';
$db['on_app']['dbdriver'] = 'mysql'`enter code here`;
$db['on_app']['dbprefix'] = '';
$db['on_app']['pconnect'] = TRUE;
$db['on_app']['db_debug'] = FALSE;
$db['on_app']['cache_on'] = FALSE;
$db['on_app']['cachedir'] = '';
$db['on_app']['char_set'] = 'utf8';
$db['on_app']['dbcollat'] = 'utf8_general_ci';
$db['on_app']['swap_pre'] = '';
$db['on_app']['autoinit'] = TRUE;
$db['on_app']['stricton'] = FALSE;
答案 0 :(得分:0)
在application-> config文件夹下的database.php文件中,编辑与您的详细信息的默认连接
$db['default'] = array(
'dsn' => '',
'hostname' => 'your.server.ip.address',
'username' => 'yourserverusername',
'password' => 'your_db_password',
'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
);
您必须在服务器上创建用户并将数据库打开到所有ips或您希望的任何一个用户
答案 1 :(得分:0)
试试这个,它对我有用。
在远程数据库服务器中打开PHPMyAdmin
使用所有权限创建用户。请记住将主机设置为%。
编辑mysqld.cnf并设置" bind-address = 0.0.0.0" (也许 /etc/mysql/mysql.conf.d/mysqld.cnf)。
重启MySQL。