我正在使用 Vagrant 在 Windows 中启动 VirtualBox 虚拟机。我这样做:
$ Vagrant ssh
连接到虚拟机。然后我执行 $ mysql
连接到我的数据库。然后我可以看到我创建的要使用的数据库。但是,当我访问我的服务器时,我看到了这个错误:
The table "doe_user" for active record class "User" cannot be found in the database.
我知道那是因为数据库是空的并且用户表不存在。这就是为什么我尝试使用此将表添加到数据库的原因:
load all tables in the doe_db: http://***.***.**.**/install.php;
当我运行它时,我得到:
mysql> load all tables in the doe_db: http://***.***.**.**/install.php;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'all t
ables in the doe_db: http://***.***.**.**/install.php' at line 1,
当我使用 show databases
时,我选择了正确的数据库,然后要求显示表,它返回空集。
当我转到我的 http://***.***.**.**/install.php
时,我得到:
Internal Server Error Undefined index: log An internal error occurred while the Web server was processing your request. Please contact the webmaster to report this problem. Thank you.
这是我的数据库代码:
$config_database = array(
'components' => array(
'db' => array(
'connectionString' => 'mysql:host=localhost;dbname=doe_db',
'emulatePrepare' => true,
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
'enableProfiling' => true, //http://www.yiiframework.com/doc/guide/1.1/en/topics.logging
'enableParamLogging' => true,
),
),
);
现在当我访问:http://***.***.**.**/index.php
我得到错误:
The table "doe_user" for active record class "User" cannot be found in
the database.
但是,当我将数据库代码更改为:
$config_database = array(
'components' => array(
'db' => array(
'connectionString' => 'mysql:host=localhost;dbname=doe_db',
'emulatePrepare' => true,
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'enableProfiling' => true, //http://www.yiiframework.com/doc/guide/1.1/en/topics.logging
'enableParamLogging' => true,
),
),
);
当我访问:http://***.***.**.**/index.php
我得到:
CDbConnection failed to open the DB connection: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO)
对于我的本地主机,当我想访问 phpMyAdmin 时,我的 root 用户没有任何密码。
最佳答案
可以引用MySQL - LOAD DATA INFILE从文件加载数据。
LOAD DATA INFILE 'http://***.***.**.**/install.php' INTO TABLE doe_db;
关于php - 尝试使用 vagrant 将表加载到我的数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30886969/