数据库不能初始化

安装报错 · biaobiaohehe · 于 4年前 发布 · 3515 次阅读

再通过install.php 安装的时候填写数据库信息后 在nginx错误日志里面报错了 9039#0: 50 FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'shop.extensions' doesn't exist in /Users/hebiao/Workspace/mine/fecmall/vendor/yiisoft/yii2/db/Command.php:1290 Stack trace: #0 /Users/hebiao/Workspace/mine/fecmall/vendor/yiisoft/yii2/db/Command.php(1290): PDOStatement->execute() #1 /Users/hebiao/Workspace/mine/fecmall/vendor/yiisoft/yii2/db/Command.php(1158): yii\db\Command->internalExecute('SELECT FROM ...') #2 /Users/hebiao/Workspace/mine/fecmall/vendor/yiisoft/yii2/db/Command.php(399): yii\db\Command->queryInternal('fetchAll', NULL) #3 /Users/hebiao/Workspace/mine/fecmall/common/config/bootstrap.php(34): yii\db\Command->queryAll() #4 /Users/hebiao/Workspace/mine/fecmall/appfront/web/index.php(24): require('/Users/hebiao/W...') #5 {main}

Next yii\db\Exception: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'shop.extensions' doesn't exist The SQL being executed was: SELECT * FROM extensions where status=1 AND installed_status" while reading response header from upstream, client: 127.0.0.1, server: appfront.shoptest.com, request: "GET /install.php/database/config/migrate HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "appfront.shoptest.com", referrer: "http://appfront.shoptest.com/install.php

因为数据还是空的,但是里面不可能有这个表啊 shop.extensions sho是我的是数据库名字,很奇怪卡在这个地方不能安装了

共收到 27 条回复
Fecmall#14年前 0 个赞

你是升级的fecmall-2.3.2? 还是直接安装?

如果直接安装, 请安装2.3.2以上版本

fecmall的数据库初始化migrate步骤,会安装数据库表的

就是直接安装的2.3.2 这个版本的,但是在输入数据库配置的界面,提交以后直接报错 500 ,然后在nginx里面看错误日志,发现上面的问题。是缺少什么扩展吗。

Fecmall#34年前 0 个赞

不是扩展的问题。

你是不是进行了代码改动?

common/config/bootstrap.php

if (!$is_install) {
    $dbConfig = isset($fecmall_common_main_local_config['components']['db']) ? $fecmall_common_main_local_config['components']['db'] : '';
    if (is_array($dbConfig) && !empty($dbConfig)) {
        $connection = Yii::createObject($dbConfig);
        $command = $connection->createCommand('SELECT * FROM  extensions where  status=:status AND installed_status=:installed_status ORDER BY priority ASC ');
        $command->bindValue(':status', 1);
        $command->bindValue(':installed_status', 1);
        $fecmall_db_extensions_data = $command->queryAll();
    }
}

如果install.php入口,$fecmall_common_main_local_config,这个变量的值为空的,不会执行下面的查询的, 你可以自己debug一下这个变量,输出一下看看值。

很奇怪,我就是第一次安装的,我这边没有修改任何代码的 加了debug确实是null 但是在以第一次出现填写数据库页面的时候我这边,在nginx 里面看到这个报错 error] 33978#0: *161 FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught PDOException: PDO::construct(): php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known in /Users/hebiao/Workspace/mine/myshop/vendor/yiisoft/yii2/db/Connection.php:695 Stack trace: #0 /Users/hebiao/Workspace/mine/myshop/vendor/yiisoft/yii2/db/Connection.php(695): PDO->construct('mysql:host={mys...', '{mysql_user}', '{mysql_password...', NULL) #1 /Users/hebiao/Workspace/mine/myshop/vendor/yiisoft/yii2/db/Connection.php(621): yii\db\Connection->createPdoInstance() #2 /Users/hebiao/Workspace/mine/myshop/vendor/yiisoft/yii2/db/Connection.php(1012): yii\db\Connection->open() #3 /Users/hebiao/Workspace/mine/myshop/vendor/yiisoft/yii2/db/Connection.php(999): yii\db\Connection->getMasterPdo() #4 /Users/hebiao/Workspace/mine/myshop/vendor/yiisoft/yii2/db/Command.php(253): yii\db\Connection->getSlavePdo() #5 /Users/hebiao/Workspace/mine/myshop/vendor/yiisoft/yii2/db/Command.php(1153): yii\db\Command->prepare(true) #6 /Users/hebiao/Works" while reading response header from upstream, client: 127.0.0.1, server: appfront.shoptest.com, request: "GET /debug/default/toolbar?tag=5d7f7dbc72a0d HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "appfront.shoptest.com", referrer: "http://appfront.shoptest.com/install.php"

然后我在填写数据库信息,点击提交按钮后,就会跳HTTP ERROR 500 然后页面nginx里面继续报上面的错误

[error] 33978#0: 161 FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'fecmall.extensions' doesn't exist in /Users/hebiao/Workspace/mine/myshop/vendor/yiisoft/yii2/db/Command.php:1290 Stack trace: #0 /Users/hebiao/Workspace/mine/myshop/vendor/yiisoft/yii2/db/Command.php(1290): PDOStatement->execute() #1 /Users/hebiao/Workspace/mine/myshop/vendor/yiisoft/yii2/db/Command.php(1158): yii\db\Command->internalExecute('SELECT FROM ...') #2 /Users/hebiao/Workspace/mine/myshop/vendor/yiisoft/yii2/db/Command.php(399): yii\db\Command->queryInternal('fetchAll', NULL) #3 /Users/hebiao/Workspace/mine/myshop/common/config/bootstrap.php(37): yii\db\Command->queryAll() #4 /Users/hebiao/Workspace/mine/myshop/appfront/web/index.php(24): require('/Users/hebiao/W...') #5 {main}

Next yii\db\Exception: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'fecmall.extensions' doesn't exist The SQL being executed was: SELECT * FROM extensions where status=1 AND installed_status" while reading response header from upstream, client: 127.0.0.1, server: appfront.shoptest.com, request: "GET /install.php/database/config/migrate HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "appfront.shoptest.com", referrer: "http://appfront.shoptest.com/install.php"

域名的配置这些都是按照文档来的,难道因为我是mac吗。。。

Fecmall#54年前 0 个赞

实在不清楚你是怎么操作的,看不懂你的报错

1.先看一下发帖说明,学会使用markdown语法写:http://www.fecmall.com/markdown ,你的内容乱糟糟的很影响阅读。

2.建议删除数据库,从头重新严格按照文档安装

3. construct('mysql:host={mys...', '{mysql_user}', '{mysql_password...', NULL) #1 前台提交的数据库配置,会改写@common/config/main-local.php, 在init步骤,会操作改变这个文件为可写状态,如果你的账户不是root,请检查这些更改的文件状态是否成功

如果该文件不可写,那么前台提交的配置文件根本写不进去,

<?php
return [
    'components' => [
        // Mysql部分的配置
        'db' => [ 
            'class' => 'yii\db\Connection',
            'dsn' => 'mysql:host={mysql_host};dbname={mysql_database}',
            'username' => '{mysql_user}',
            'password' => '{mysql_password}',
            'charset' => 'utf8',
        ],

那么连接mysql肯定失败连接不上

4.对于报错中的SELECT * FROM extensions where status=1 AND installed_status这个操作是在common/config/bootstrap.php中执行的,请自行debug一下原因

5.我没有mac机器,无法测试,目前linux和win是没有问题的。

Adia#64年前 0 个赞

今天本地全新安装也是这样的情况,网上查了方法试了都不行。

可能跟环境配置问题吧,暂时只能用回以前的导入。
我本地是linux

Fecmall#74年前 0 个赞

@Adia [#6楼](#comment6) 我测试了,除了 init步骤 Error. Directory common/config/main-local.php does not exist. 这个文件common/config/main-local.php 更改文件权限存在问题,其他的都没有问题

这个文件可以暂且自己手动改一下权限:common/config/main-local.php

http://www.fecmall.com/topic/2136

Fecmall#84年前 0 个赞

@Adia #6楼

我也很神奇这个问题

1.安装部分

对于安装文件:install.php, https://github.com/fecshop/yii2_fecshop_app_advanced/blob/master/appfront/web/install.php ,并没有设置变量 $fecmall_common_main_local_config,因此在bootstrap https://github.com/fecshop/yii2_fecshop_app_advanced/blob/master/common/config/bootstrap.php#L28

if (!$is_install) {
    $dbConfig = isset($fecmall_common_main_local_config['components']['db']) ? $fecmall_common_main_local_config['components']['db'] : '';
    if (is_array($dbConfig) && !empty($dbConfig)) {
        $connection = Yii::createObject($dbConfig);
        $command = $connection->createCommand('SELECT * FROM  extensions where  status=:status AND installed_status=:installed_status ORDER BY priority ASC ');
        $command->bindValue(':status', 1);
        $command->bindValue(':installed_status', 1);
        $fecmall_db_extensions_data = $command->queryAll();
    }
}

对于变量$fecmall_common_main_local_config['components']['db'] ,肯定是不存在的,因此不会执行下面的sql查询方法,搞不明白你们的安装为什么会执行下面的sql

有能力的遇到这个问题可以debug一下,我本地无法重现,无法协助。

2.如果安装完成,访问index.php https://github.com/fecshop/yii2_fecshop_app_advanced/blob/master/environments/prod/appfront/web/index.php#L22

这个入口文件才会设置变量$fecmall_common_main_local_config,才会进行sql查询。

hd2019#94年前 0 个赞

@Fecmall #8楼 我看了一下,这个`$fecmall_common_main_local_config`是在`\fecmall\appfront\web\index.php`里面赋值的,注释掉相关代码以后不再报错,但是我不知道为什么install.php会引用到index.php,可能跟nginx的配置有关?我用的是你们文档里给的配置:

server {
        listen        80;
        server_name  fec.app;
        root   G:/WWW/fecmall/appfront/web/;

        location / {
            index  index.php index.html index.htm;
            try_files $uri $uri/ /index.php?$query_string;
        }
        
        location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

}
Fecmall#104年前 0 个赞

@hd2019 #9楼 如果感觉哪里有问题,自己调试一下试试,找找原因,本人本地无法重现,帮不上忙

我也碰到了这个问题: FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mydb.extensions' 目前不知道原因

Fecmall#124年前 0 个赞

目前我无法重现这个问题,因此无法查找原因

如果是服务器安装fecmall遇到这个问题,方便给与root账户,可以加我QQ:2358269014,我试一下,找找原因。

Fecmall#134年前 0 个赞

@hd2019 #9楼 @Adia #6楼 方便的留个服务器账户,加我Q:2358269014,我测试一下试试,找找原因,有能力的也可以自己找找,为什么install.php 加载了index.php 的变量。

if (!$is_install) {

$dbConfig = isset($fecmall_common_main_local_config['components']['db']) ? $fecmall_common_main_local_config['components']['db'] : '';
echo "<pre> aaaa dbConfig = $dbConfig";
if (is_array($dbConfig) && !empty($dbConfig)) {
    $connection = Yii::createObject($dbConfig);
    $command = $connection->createCommand('SELECT * FROM  extensions where  status=:status AND installed_status=:installed_status');
    $command->bindValue(':status', 1);
    $command->bindValue(':installed_status', 1);
    $fecmall_db_extensions_data = $command->queryAll();
}

} 浏览器上 打印了 aaaa dbConfig = Array 说明不为空 我看了下数据库没有任何表,install.php配置界面提交后common/config/main-local.php是有值的,按照给的流程 应该进入表创建界面,然后报错了。

另外 下载好后 执行 ./init 我这直接退出了,我把answer = 0 改为了 answer = "0" 才正常完成了init,不知道和这个有没有关系

Fecmall#154年前 0 个赞

@likefecmall [#14楼](#comment14) 请下载2.3.3,answer = 0这个问题已经修复

按照常理:$dbConfig = isset($fecmall_common_main_local_config['components']['db']) ? $fecmall_common_main_local_config['components']['db'] : '';

这个是不可能有值的,我不清楚你们的配置为什么会这样,$fecmall_common_main_local_config这个变量是在index.php里面赋值的,install.php,根本没有赋值

不明白你们的配置,访问install.php 会加载index.php的变量。

wull#164年前 0 个赞

我也遇到了这个问题: Fatal error: Uncaught PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'fecshop.extensions' doesn't exist in /data/htdocs/fecshop/fecmall/vendor/yiisoft/yii2/db/Command.php:1290 Stack trace: #0 /data/htdocs/fecshop/fecmall/vendor/yiisoft/yii2/db/Command.php(1290): PDOStatement->execute() #1 /data/htdocs/fecshop/fecmall/vendor/yiisoft/yii2/db/Command.php(1158): yii\db\Command->internalExecute('SELECT FROM ...') #2 /data/htdocs/fecshop/fecmall/vendor/yiisoft/yii2/db/Command.php(399): yii\db\Command->queryInternal('fetchAll', NULL) #3 /data/htdocs/fecshop/fecmall/common/config/bootstrap.php(34): yii\db\Command->queryAll() #4 /data/htdocs/fecshop/fecmall/appfront/web/index.php(24): require('/data/htdocs/fe...') #5 {main} Next yii\db\Exception: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'fecshop.extensions' doesn't exist The SQL being executed was: SELECT FROM extensions where status=1 AND installed_status=1 ORDER BY priority ASC in /data/htdocs/fecshop/fecmall/vendor/yiisoft/yii2 in /data/htdocs/fecshop/fecmall/vendor/yiisoft/yii2/db/Schema.php on line 674

Fecmall#174年前 0 个赞

@wull #16楼 本人表示,安装了很多环境都没有遇到这个问题,如果遇到这个问题,请联系QQ:2358269014.协助解决这个 Base table or view not found: 1146 Table 'fecshop.extensions' doesn't exist

zues_pub#184年前 0 个赞

我是用的 nginx 也碰到这个问题,访问 install.php 会加载 index.php 然后填好数据库信息后报 Base table or view not found: 1146 Table 'fecshop.extensions' doesn't exist 错误。

这个问题确实是和 Nginx 配置有关系 我的配置中有这么一段

    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }

这里给个解决方案,比较麻烦点

先把 Nginx 配置中的 index.php 修改成 install.php, 重启 nginx

    location / {
        try_files $uri $uri/ /install.php$is_args$args;
    }

再运行

./init

再访问

http://appfront.your.domain/install.php

安装好后再把 nginx 配置改回去,再重启 nginx

    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }

还有一个坑, 在 install 的 migrate 阶段 php 可能超时, 编辑 install.php 在最开始加一条语句 ini_set("max_execution_time", "1800"); 增加下PHP的超时时间。

Fecmall#194年前 0 个赞

1.大多数人安装都没有问题,少数人遇到这个问题的,是nginx配置的问题,我不清楚你们使用了什么一件安装包,还是什么控制面板,里面的nginx默认这样配置导致的。

既然是nginx配置的问题,解决方式肯定是更改nginx的配置,而不是更改fecmall的代码

这个配置有问题,应该是去掉这个配置,而不是更改fecmall代码

这里有一个nginx的实例配置,可以参考修改一下:http://www.fecmall.com/topic/2101

2.install migrate一般不会超过10秒,(vps4秒执行完成)既然真的存在30秒还没有执行的情况,那么,我添加一下这个执行时间。

Fecmall#204年前 0 个赞

关于 nginx try_files

Nginx配置指令try_files try_files指令是按顺序检测文件的存在性,并且返回第一个找到文件的内容,如果第一个找不到就会自动找第二个,依次查找.其实现的是内部跳转.

参考资料:

https://blog.csdn.net/u013474436/article/details/79724111

https://blog.csdn.net/tuoni123/article/details/79713397

出现这个问题的,查阅nginx的try_files,并去掉

对于nginx去掉index.php,请使用nginx的rewrite

location / {
        if (!-e $request_filename){
            rewrite ^/(.*)$ /index.php/$1 last;
        }
    }
    location /fr/ {
        index index.php;
        if (!-e $request_filename){
            rewrite . /fr/index.php last;
        }
    }
    location /cn/ {
        index index.php;
        if (!-e $request_filename){
            rewrite . /cn/index.php last;
        }
    }
muyuto#214年前 0 个赞

我也是遇到一样的问题,ubuntu系统,通过apt安装的nginx和php7.2-fpm及其需要的扩展

查服务器日志发现如下问题 2019/09/29 02:33:24 [error] 6#6: *8 rewrite or internal redirection cycle while processing "/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/install.php/database/config/migrate", client: 172.18.0.1, server: appfront.fecshoptest.com, request: "GET /install.php/database/config/migrate HTTP/1.1", host: "appfront.fecshoptest.com", referrer: "http://appfront.fecshoptest.com/install.php"

感觉像是nginx的配置里rewrite的问题,可是nginx的配置文件用的是官方提供的标准配置,即地址:http://www.fecmall.com/topic/2101里的

不过配置里的fcgi.conf没有用,用的系统自带的fastcgi.conf。估计是这个文件头上的那几句起了什么作用,不过用了页面里的代码nginx启动报错,显示第4行问题,即那两句

if ($request_filename ~* (.*)\.php) {
    set $php_url $1;
}
if (!-e $php_url.php) {
    #return 403;
}

用了也是同样的错误,汗

Fecmall#224年前 0 个赞

@muyuto #21楼

你的报错才是真的汗!!!

rewrite or internal redirection cycle while processing "/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/install.php

访问install.php,rewrite成这个鬼样子的url。

自己去找nginx原因,肯定是你nginx配置加载了一些自己的配置

这个帖子出现问题,多巴拉巴拉你的nginx配置文件问题,该说的都说了,fecmall代码没有问题

muyuto#234年前 0 个赞

我真的啥都没有改啊,nginx的站点配置用的就是你给的页面上写的那一段啊 http://www.fecmall.com/topic/2101

muyuto#244年前 0 个赞
 location / {
        if (!-e $request_filename){
            rewrite ^/(.*)$ /index.php/$1 last;
        }
    }

官方给的这个配置意思是找不到访问页面是就跳转到页面地址前加一个index.php,所以会出这个错误,url变成一长串的index.php/index.php/......这种样子的

我看了一下代码,在数据库配置这个页面对应的control里写的是

			// 进行跳转
            $homeUrl = Yii::$app->homeUrl;
            return $this->redirect($homeUrl.'/database/config/migrate');

所以,如果urlManager配置不对没有实现地址美化,模块配置不对找不到对应的controller的时候都会出我那个错误

Fecmall#254年前 0 个赞

@muyuto #24楼

1.这个配置是去掉index.php,一点问题也没有.

2.nginx配置参数语法,自行搜索。 资料很多,搜索一下就知道了,没有必要猜。

Fecmall#264年前 0 个赞

1.这个帖子基本就这样了!!

2.出现这个报错able 'shop.extensions' doesn't exist 就是nginx的配置问题,参看上面的留言,自行从nginx配置找原因。

Fecmall#274年前 0 个赞

某位fecmaller提供了报错的服务器,进行了排查,此问题的原因

参看帖子:http://www.fecmall.com/topic/2177

添加回复 (需要登录)
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册
Your Site Analytics