No port after the hostname: this is an UNIX socket. > engine = dict(unix_socket="/path/to/mysql.sock")) > engine = dict(host='localhost', port=3306))Īs you noticed, both will use a TCP connection (I know that because of the port number after the hostname). When a container is started for the first time, a new database with the specified name will be created and initialized with the provided configuration variables. # Same result by using 127.0.0.1 instead of localhost: Currently, this is only supported for MYSQLROOTPASSWORD, MYSQLROOTHOST, MYSQLDATABASE, MYSQLUSER, and MYSQLPASSWORD. > conn.execute("SELECT host FROM INFORMATION_SCHEMA.PROCESSLIST WHERE ID = CONNECTION_ID()").fetchall() # Normally URL options should use `?` and `&` As you explained it yourself, when invoking mysql on the command line, you use the -protocol tcp option.Īs explained here, from SQLAlchemy, you can pass the relevant options (if any) to your driver either as URL options or using the connect_args keyword argument.įor example using PyMySQL, on a test system I've setup for that purpose (MariaDB 10.0.12, SQLAlchemy 0.9.8 and PyMySQL 0.6.2) I got the following results: > engine = ^^^^^^^^^^^^^^^^^^^^^^^^^^ However, this simple trick doesn't appear to work in your case, so you have to somehow force the use of a TCP socket. To ensure that the client makes a TCP/IP connection to the local server, use -host or -h to specify a host name value of 127.0.0.1, or the IP address or name of the local server. This occurs even if a -port or -P option is given to specify a port number. For connections to localhost, MySQL programs attempt to connect to the local server by using a Unix socket file. On Unix, MySQL programs treat the host name localhost specially, in a way that is likely different from what you expect compared to other network-based programs. connections on Unix to localhost are made using a Unix socket file by default The classic answer to this issue is to use 127.0.0.1 or the IP of the host or the host name instead of the "special name" localhost. PDO::ATTR_PERSISTENT => env('DB_PERSISTENT', false), 'username' => env('DB_USERNAME', 'forge'), 'database' => env('DB_DATABASE', 'forge'), also, don't mind the alternate/different config settings that my database.php has as opposed to yours, these were for advanced configurations.)Īdd a 'port' section to your config/database.php, that looks like follows: 'pgsql' => [ (This is assuming Laravel 5.1 using a Postgres DB, but should work with alternate versions of Laravel, and different DBs. For those looking in the future, here is what you need: I know you figured it out, but of all the attempts you provided, the answer you gave wasn't clear. How can I tell laravel to connect to mysql on port 3308? I am not sure where is the user homestead is coming from. This gives me a different error Access denied for user (using password: YES) 'password' => env('DB_PASSWORD', 'pass'), 'username' => env('DB_USERNAME', 'user'), 'database' => env('DB_DATABASE', 'mydb_dev'), I have tried the following and none worked. I have to let laravel to connect to a different port somehow. SQLSTATE No connection could be made because the target machi I opned the database.php file located in the config directory and then update the mysql config. I am trying to use laravel for the first time.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |