[英]Doctrine2 (Symfony4) database connection url over socket
I'm having a hard time getting a database connection to work with the mysql url format used in Symfony4 w/ doctrine2. 我很难获得数据库连接以使用Symfony4 w / doctrine2中使用的mysql url格式。
Here is what I'm trying to do: 这是我正在尝试做的事情:
mysql://dbusername:dbpassword@unix_socket(/path/to/socket)/dbname
What am I doing wrong? 我究竟做错了什么? Please advise.
请指教。 The Doctrine2 documentation isn't clear on the format for connection over a socket.
Doctrine2文档不清楚套接字连接的格式。
I also faced this problem when trying to use google cloud platform SQL for mysql that requires to use a local unix socket. 当我尝试使用需要使用本地unix套接字的mysql的google云平台SQL时,我也遇到了这个问题。
Every part of the URL is not mandary, it's in the form : URL的每个部分都不是强制性的,它的形式如下:
<type>://[user[:password]@][host][:port][/db][?param_1=value_1¶m_2=value_2...]
So for a mysql unix socket if you need to specify user and password, you can do : 因此,对于mysql unix套接字,如果需要指定用户和密码,可以执行以下操作:
mysql://user:password@127.0.0.1/db_name/?unix_socket=/path/to/socket
The 127.0.0.1 part will be ignored. 127.0.0.1部分将被忽略。
You can test that this is working through the parse_url
function (that is used by doctrine internally): 您可以通过
parse_url
函数(内部使用doctrine)测试这是否正常工作:
php > var_dump(parse_url("mysql://user:password@127.0.0.1/db_name/?unix_socket=/path/to/socket"));
php shell code:1:
array(6) {
'scheme' =>
string(5) "mysql"
'host' =>
string(9) "127.0.0.1"
'user' =>
string(4) "user"
'pass' =>
string(8) "password"
'path' =>
string(9) "/db_name/"
'query' =>
string(27) "unix_socket=/path/to/socket"
}
.env
: .env
: DATABASE_URL=mysql://root:root@127.0.0.1:3306/database_name
php bin/console doctrine:database:create
php bin/console doctrine:schema:create
php bin/console doctrine:schema:update --force
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.