找不到数据库Unknown database 'test_park'

BoringBlue

问题描述

带下划线“_”数据库名“test_park”的数据库识别不了,无其他符号的数据库“test”识别成功,两个数据库配置一样

程序代码

数据库设置

return [
    // 默认数据库
    'default' => 'mysql',
    'connections' => [
        'mysql' => [
            'driver'      => 'mysql',
            'host'        => '127.0.0.1',
            'port'        => 3306,
            'database'    => 'test_park',
            'username'    => 'root',
            'password'    => '123456',
            'unix_socket' => '',
            'charset'     => 'utf8mb4',
            'collation'   => 'utf8mb4_general_ci',
            'prefix'      => '',
            'strict'      => true,
            'engine'      => null,
        ],
    ]
];

报错信息

PDOException: SQLSTATE[HY000] [1049] Unknown database 'test_park' in E:\MXJK_GitLab\webman\vendor\illuminate\database\Connectors\Connector.php:70
Stack trace:
#0 E:\MXJK_GitLab\webman\vendor\illuminate\database\Connectors\Connector.php(70): PDO->__construct('mysql:host=127....', 'root', '123456', Array)
#1 E:\MXJK_GitLab\webman\vendor\illuminate\database\Connectors\Connector.php(46): Illuminate\Database\Connectors\Connector->createPdoConnection('mysql:host=127....', 'root', '123456', Array)
#2 E:\MXJK_GitLab\webman\vendor\illuminate\database\Connectors\MySqlConnector.php(24): Illuminate\Database\Connectors\Connector->createConnection('mysql:host=127....', Array, Array)
#3 E:\MXJK_GitLab\webman\vendor\illuminate\database\Connectors\ConnectionFactory.php(184): Illuminate\Database\Connectors\MySqlConnector->connect(Array)
#4 [internal function]: Illuminate\Database\Connectors\ConnectionFactory->Illuminate\Database\Connectors\{closure}()
#5 E:\MXJK_GitLab\webman\vendor\illuminate\database\Connection.php(1064): call_user_func(Object(Closure))
#6 E:\MXJK_GitLab\webman\vendor\illuminate\database\Connection.php(1100): Illuminate\Database\Connection->getPdo()
#7 E:\MXJK_GitLab\webman\vendor\illuminate\database\Connection.php(442): Illuminate\Database\Connection->getReadPdo()
#8 E:\MXJK_GitLab\webman\vendor\illuminate\database\Connection.php(368): Illuminate\Database\Connection->getPdoForSelect(true)
#9 E:\MXJK_GitLab\webman\vendor\illuminate\database\Connection.php(705): Illuminate\Database\Connection->Illuminate\Database\{closure}('select `name` f...', Array)
#10 E:\MXJK_GitLab\webman\vendor\illuminate\database\Connection.php(672): Illuminate\Database\Connection->runQueryCallback('select `name` f...', Array, Object(Closure))
#11 E:\MXJK_GitLab\webman\vendor\illuminate\database\Connection.php(376): Illuminate\Database\Connection->run('select `name` f...', Array, Object(Closure))
#12 E:\MXJK_GitLab\webman\vendor\illuminate\database\Query\Builder.php(2414): Illuminate\Database\Connection->select('select `name` f...', Array, true)
#13 E:\MXJK_GitLab\webman\vendor\illuminate\database\Query\Builder.php(2402): Illuminate\Database\Query\Builder->runSelect()
#14 E:\MXJK_GitLab\webman\vendor\illuminate\database\Query\Builder.php(2936): Illuminate\Database\Query\Builder->Illuminate\Database\Query\{closure}()
#15 E:\MXJK_GitLab\webman\vendor\illuminate\database\Query\Builder.php(2403): Illuminate\Database\Query\Builder->onceWithColumns(Array, Object(Closure))
#16 E:\MXJK_GitLab\webman\vendor\illuminate\database\Concerns\BuildsQueries.php(294): Illuminate\Database\Query\Builder->get(Array)
#17 E:\MXJK_GitLab\webman\vendor\illuminate\database\Query\Builder.php(2388): Illuminate\Database\Query\Builder->first(Array)
#18 E:\MXJK_GitLab\webman\app\api\controller\IndexController.php(19): Illuminate\Database\Query\Builder->value('name')
#19 E:\MXJK_GitLab\webman\vendor\workerman\webman-framework\src\App.php(293): app\api\controller\IndexController->index(Object(support\Request))
#20 E:\MXJK_GitLab\webman\vendor\workerman\webman-framework\src\App.php(147): Webman\App::Webman\{closure}(Object(support\Request))
#21 E:\MXJK_GitLab\webman\vendor\workerman\workerman\Connection\TcpConnection.php(638): Webman\App->onMessage(Object(Workerman\Connection\TcpConnection), Object(support\Request))
#22 E:\MXJK_GitLab\webman\vendor\workerman\workerman\Events\Select.php(311): Workerman\Connection\TcpConnection->baseRead(Resource id #153)
#23 E:\MXJK_GitLab\webman\vendor\workerman\workerman\Worker.php(2467): Workerman\Events\Select->loop()
#24 E:\MXJK_GitLab\webman\vendor\workerman\workerman\Worker.php(1453): Workerman\Worker->run()
#25 E:\MXJK_GitLab\webman\vendor\workerman\workerman\Worker.php(1396): Workerman\Worker::forkWorkersForWindows()
#26 E:\MXJK_GitLab\webman\vendor\workerman\workerman\Worker.php(560): Workerman\Worker::forkWorkers()
#27 E:\MXJK_GitLab\webman\vendor\workerman\webman-framework\src\support\App.php(124): Workerman\Worker::runAll()
#28 E:\MXJK_GitLab\webman\start.php(4): support\App::run()
#29 {main}

截图报错信息里报错文件相关代码

这里粘贴截图
截图

操作系统及workerman/webman等框架组件版本

这里写系统环境相关信息
win10 mysql5.7 php7.3

    "workerman/webman-framework": "^1.4.3",
    "monolog/monolog": "^2.0",
    "psr/container": "1.1.1",
    "illuminate/redis": "^8.83",
    "illuminate/events": "^8.83",
    "phpoffice/phpspreadsheet": "^1.25",
    "illuminate/database": "^8.83",
    "illuminate/pagination": "^8.83",
    "symfony/var-dumper": "^5.4"
969 2 0
2个回答

BoringBlue

好像不是字符的原因,我把原有的test数据库删了,新建的test数据库也连不上了

  • BoringBlue 2022-10-26

    database.php配置文件host之前写的127.0.0.1,改成localhost就好了

six

执行 mysql -h127.0.0.1 -uroot -p 输入密码,进入mysql命令行,执行 show databases; 或者 use test_park;,看下数据库是否存在。这种基本都是自己的低级错误,自己简单定位下就出来了。数据库不存在就是不存在,代码不会骗人,只有自己骗了自己。

年代过于久远,无法发表回答
×
🔝