swoft-cloud / swoft

🚀 PHP Microservice Full Coroutine Framework
https://swoft.org
Apache License 2.0
5.58k stars 788 forks source link

使用Docker Compose在window10下搭建swoft开发环境,mysql连接错误 #1082

Open akrick opened 4 years ago

akrick commented 4 years ago
{
"code": 0,
"error": "(Swoft\Db\Exception\DbException) Pool error is Create connection error(Dsn(mysql:dbname=test;host=127.0.0.1:13306) can not to connected!) file(/var/www/swoft/vendor/swoft/db/src/Connector/MySqlConnector.php) line (43) file=/var/www/swoft/vendor/swoft/connection-pool/src/AbstractPool.php line=250",
"file": "At /var/www/swoft/vendor/swoft/db/src/DB.php line 81",
"trace": "#0 /var/www/swoft/vendor/swoft/db/src/Query/Builder.php(3324): Swoft\Db\DB::connection('db.pool')
#1 /var/www/swoft/vendor/swoft/db/src/Query/Builder.php(2437): Swoft\Db\Query\Builder->getConnection()
#2 /var/www/swoft/app/Http/Controller/OrderController.php(35): Swoft\Db\Query\Builder->cursor()
#3 /var/www/swoft/vendor/swoft/stdlib/src/Helper/PhpHelper.php(54): App\Http\Controller\OrderController->buy()
#4 /var/www/swoft/vendor/swoft/http-server/src/Middleware/DefaultMiddleware.php(75): Swoft\Stdlib\Helper\PhpHelper::call(Array)
#5 /var/www/swoft/vendor/swoft/http-server/src/RequestHandler.php(73): Swoft\Http\Server\Middleware\DefaultMiddleware->process(Object(Swoft\Http\Message\Request), Object(Swoft\Http\Server\RequestHandler))
#6 /var/www/swoft/vendor/swoft/http-server/src/Middleware/ValidatorMiddleware.php(50): Swoft\Http\Server\RequestHandler->handle(Object(Swoft\Http\Message\Request))
#7 /var/www/swoft/vendor/swoft/http-server/src/RequestHandler.php(73): Swoft\Http\Server\Middleware\ValidatorMiddleware->process(Object(Swoft\Http\Message\Request), Object(Swoft\Http\Server\RequestHandler))
#8 /var/www/swoft/vendor/swoft/http-server/src/Middleware/UserMiddleware.php(54): Swoft\Http\Server\RequestHandler->handle(Object(Swoft\Http\Message\Request))
#9 /var/www/swoft/vendor/swoft/http-server/src/RequestHandler.php(73): Swoft\Http\Server\Middleware\UserMiddleware->process(Object(Swoft\Http\Message\Request), Object(Swoft\Http\Server\RequestHandler))
#10 /var/www/swoft/vendor/swoft/view/src/Middleware/ViewMiddleware.php(41): Swoft\Http\Server\RequestHandler->handle(Object(Swoft\Http\Message\Request))
#11 /var/www/swoft/vendor/swoft/http-server/src/RequestHandler.php(73): Swoft\View\Middleware\ViewMiddleware->process(Object(Swoft\Http\Message\Request), Object(Swoft\Http\Server\RequestHandler))
#12 /var/www/swoft/app/Http/Middleware/FavIconMiddleware.php(45): Swoft\Http\Server\RequestHandler->handle(Object(Swoft\Http\Message\Request))
#13 /var/www/swoft/vendor/swoft/http-server/src/RequestHandler.php(73): App\Http\Middleware\FavIconMiddleware->process(Object(Swoft\Http\Message\Request), Object(Swoft\Http\Server\RequestHandler))
#14 /var/www/swoft/vendor/swoft/http-server/src/HttpDispatcher.php(80): Swoft\Http\Server\RequestHandler->handle(Object(Swoft\Http\Message\Request))
#15 /var/www/swoft/vendor/swoft/http-server/src/Swoole/RequestListener.php(42): Swoft\Http\Server\HttpDispatcher->dispatch(Object(Swoft\Http\Message\Request), Object(Swoft\Http\Message\Response))
#16 {main}"
}

其中DB的配置如下:

'db'=> [
'class' => Database::class,
'dsn' => 'mysql:dbname=test;host=127.0.0.1:13306',
'username' => 'root',
'password' => '123456',
'prefix' => 'vc_',
'charset' => 'utf8',
],
inhere commented 4 years ago

使用 docker compose, mysql 并不在同一个容器里。

host=127.0.0.1:13306 需改为 host=mysql:13306

akrick commented 4 years ago

使用 docker compose, mysql 并不在同一个容器里。

host=127.0.0.1:13306 需改为 host=mysql:13306

修改了之后好像还是没能连上

Pool error is Create connection error(Dsn(mysql:dbname=test;host=mysql:13306) can not to connected!) file(/var/www/swoft/vendor/swoft/db/src/Connector/MySqlConnector.php) line (43) file=/var/www/swoft/vendor/swoft/connection-pool/src/AbstractPool.php line=250 At /var/www/swoft/vendor/swoft/db/src/DB.php line 81

mysql启动报错: mysql-srv exited with code 2

inhere commented 4 years ago

:( db启动失败了 肯定连不上啊

nanyounanyounan commented 4 years ago

看看这篇文章
https://blog.csdn.net/qq_33028267/article/details/105156454