我想使用本地IP地址连接到CodeIgniter中的数据库,但是失败,
配置/数据库:
$active_group = 'default';
$query_builder = TRUE;
$active_record = TRUE;
$db['default'] = array(
'dsn' => '',
'hostname' => '192.168.1.102',
'username' => 'root',
'password' => '',
'database' => 'webbmkg',
'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(
array(
'dsn' => '',
'hostname' => '192.168.1.103',
'username' => 'root',
'password' => '',
'database' => 'webbmkg',
'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,
'save_queries' => TRUE
)
),
'save_queries' => TRUE
);
错误说:“无法选择指定的数据库”
我的本地IP地址是192.168.1.102,但是当我将IP更改为“ localhost”时,它的工作。
实际上,我想使用另一台PC的IP地址进行故障转移,但是它无法正常工作,然后我使用其IP地址也无法正常工作来更改默认数据库。我认为有问题,但我不知道那是什么。
答案 0 :(得分:0)
方法1: 将所有特权授予该服务器。
mysql> GRANT ALL PRIVILEGES ON * . * TO 'root'@'192.168.1.103';
mysql> FLUSH PRIVILEGES;
# service mysql restart
方法2: ****创建新的用户和授予特权*********
mysql> select password('admin@123');
+-------------------------------------------+
| password('admin@123') |
+-------------------------------------------+
| *89FA6EAF8B6264AC8D6E84759027252505A3EAEE |
+-------------------------------------------+
1 row in set (0.00 sec)
mysql> CREATE USER chirag IDENTIFIED BY password '*89FA6EAF8B6264AC8D6E84759027252505A3EAEE';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'chirag'@'192.168.1.103' WITH GRANT OPTION;
重新启动MySql服务。
# service mysql restart
现在您可以连接
用于列出用户及其特权。
mysql> SELECT host,user,Grant_priv,Super_priv FROM mysql.user;
答案 1 :(得分:-1)
尝试一下:
_V