I'm having a hard time getting a database connection to work with the mysql url format used in Symfony4 w/ doctrine2.
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.
I also faced this problem when trying to use google cloud platform SQL for mysql that requires to use a local unix socket.
Every part of the URL is not mandary, it's in the form :
<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://user:[email protected]/db_name/?unix_socket=/path/to/socket
The 127.0.0.1 part will be ignored.
You can test that this is working through the parse_url
function (that is used by doctrine internally):
php > var_dump(parse_url("mysql://user:[email protected]/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"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With