1、在 CakePHP v2.6.4 中,报错:SQLSTATE[HY000] [2002] Connection timed out。如图1
2020-08-19 13:28:45 Error: [MissingConnectionException] Database connection "Mysql" is missing, or could not be created. Exception Attributes: array ( 'class' => 'Mysql', 'message' => 'SQLSTATE[HY000] [2002] Connection timed out', 'enabled' => true, ) Request URL: /?src=fly&username=test0819a&tenantid=2de4ad2e76a6d76ee2368b1c93cec41a&token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0ZW5hbnRJRCI6IjJkZTRhZDJlNzZhNmQ3NmVlMjM2OGIxYzkzY2VjNDFhIiwidXNlcklEIjoiMiIsInVzZXJOYW1lIjoidGVzdDA4MTlhIiwiZ3JvdXBJRCI6bnVsbCwiZ3JvdXBDb2RlIjpudWxsLCJ0b2tlblR5cGUiOiJzc28iLCJyZWZyZXNoVG9rZW4iOiI1RjNDQjg2RTc5RjQ0RDFFOTk2MjAxOTkwQTJBMTFDNSJ9.m37jbpZ8uXc0uO5r7k8dAxA8DrEIL3lKTmyy_fv-FJA&uid=2&status=1 Stack Trace: #0 /mcloud/creditshop/lib/Cake/Model/Datasource/DboSource.php(260): Mysql->connect() #1 /mcloud/creditshop/lib/Cake/Model/ConnectionManager.php(105): DboSource->__construct(Array) #2 /mcloud/creditshop/app/Model/AppModel.php(125): ConnectionManager::getDataSource('tmp') #3 /mcloud/creditshop/lib/Cake/Model/Model.php(1155): AppModel->setDataSource('default') #4 /mcloud/creditshop/lib/Cake/Model/Model.php(3644): Model->setSource('products') #5 /mcloud/creditshop/lib/Cake/Model/Model.php(3022): Model->getDataSource() #6 /mcloud/creditshop/lib/Cake/Model/Model.php(2994): Model->_readDataSource('all', Array) #7 /mcloud/creditshop/lib/Cake/Controller/Component/PaginatorComponent.php(195): Model->find('all', Array) #8 /mcloud/creditshop/lib/Cake/Controller/Controller.php(1086): PaginatorComponent->paginate(NULL, Array, Array) #9 /mcloud/creditshop/app/Controller/ProductsController.php(115): Controller->paginate() #10 [internal function]: ProductsController->index() #11 /mcloud/creditshop/lib/Cake/Controller/Controller.php(490): ReflectionMethod->invokeArgs(Object(ProductsController), Array) #12 /mcloud/creditshop/lib/Cake/Routing/Dispatcher.php(193): Controller->invokeAction(Object(CakeRequest)) #13 /mcloud/creditshop/lib/Cake/Routing/Dispatcher.php(167): Dispatcher->_invoke(Object(ProductsController), Object(CakeRequest)) #14 /mcloud/creditshop/app/webroot/index.php(117): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse)) #15 {main}
2、打印数据库连接信息,发现主机地址为内网IP,容器无法访问
stdClass Object ( [tmp] => Array ( [datasource] => Database/Mysql [persistent] => [host] => 192.168.150.23 [login] => contenttest [password] => xxxxxxxx [database] => creditnew_2de4ad2e76a6d76ee2368b1c93cec41a [port] => 3306 [prefix] => operation_ [encoding] => utf8 ) )
3、调整为外网IP,打印数据库连接信息,容器可以正常访问。如图2
stdClass Object ( [tmp] => Array ( [datasource] => Database/Mysql [persistent] => [host] => xxxxxxxxxxx.bj.tencentcdb.com [login] => contenttest [password] => xxxxxxxx [database] => creditnew_2de4ad2e76a6d76ee2368b1c93cec41a [port] => 10132 [prefix] => operation_ [encoding] => utf8 ) )
原创文章,作者:carmelaweatherly,如若转载,请注明出处:https://blog.ytso.com/181564.html