Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FluentMySQL connection using Unix Socket

Tags:

I'm following the Getting started section for the MySQL package on the Vapor Documentation, which I'm able to follow step by step and, as a result, I have successfully established a connection to the MySQL database, using custom database credentials like this:

/// Register providers first
try services.register(FluentMySQLProvider())

// MySQL database
let mySQLConfig = MySQLDatabaseConfig(hostname: "localhost",
                                      port: 3306,
                                      username: "root",
                                      password: "thisismyrootpassword",
                                      database: "lol_database",
                                      capabilities: .default,
                                      characterSet: MySQLCharacterSet.utf8_general_ci,
                                      transport: MySQLTransportConfig.cleartext)

services.register(mySQLConfig)

Based on the MySQLDatabaseConfig object's documentation I'm unable to find if it is possible to connect to a MySQL database based on a Unix Socket configuration.

What I'll be able to provide to the application under the production environment it's just the database name, the username, password and the Socket path, which will be in the form /cloudsql/project1:us-central1:instance1

For more reference, what I'm trying to do is connect from a Google Cloud App Engine flexible environment to a SQL database based on this tutorial: https://cloud.google.com/appengine/docs/flexible/nodejs/using-cloud-sql#setting_up_your_local_environment The environment of course will be Vapor still that's the only way for a database client to establish connection to the database server.

Thank you for your help.

like image 271
Orlando Avatar asked Aug 30 '18 02:08

Orlando


People also ask

How do I connect to a Unix socket?

Create a socket with the socket() system call. Connect the socket to the address of the server using the connect() system call. Send and receive data. There are a number of ways to do this, but the simplest way is to use the read() and write() system calls.

What is Unix socket in MySQL?

On Unix, MySQL Shell connections default to using Unix sockets when the following conditions are met: A TCP port is not specified. A host name is not specified or it is equal to localhost . The --socket or -S option is specified, with or without a path to a socket file.


1 Answers

Times have changed and there's now a unix​Domain​Socket​Path that can be used instead of hostname/port.

like image 112
danblack Avatar answered Sep 28 '22 09:09

danblack