Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Using external mysql database #156

Closed
matusnovak opened this issue Sep 21, 2019 · 4 comments
Closed

Feature request: Using external mysql database #156

matusnovak opened this issue Sep 21, 2019 · 4 comments

Comments

@matusnovak
Copy link

Would it be possible to use an external MySQL database? I have noticed that connecting to the MySQL is done via:

connString := fmt.Sprintf("%s:%s@/%s", username, password, dbName)

From my understanding, that uses localhost automatically and there is currently no way how to specify hostname. Only username, password, and dbname can be changed via environment variables.

I would like to use an external database. Would that be possible? The reason is that I am planning to run this in a docker swarm, having persistent volume across nodes is tricky, so having centralised MySQL database would be easy in this case.

@RadhiFadlillah
Copy link
Collaborator

Hi @matusnovak,

Yeah, the database adress should be changeable via environment variable as well. Will add it ASAP.

@RadhiFadlillah
Copy link
Collaborator

@matusnovak per df98c28 I've made the database address changeable via environment variable SHIORI_MYSQL_ADDRESS

shiori/internal/cmd/root.go

Lines 105 to 113 in df98c28

if dbms, _ := os.LookupEnv("SHIORI_DBMS"); dbms == "mysql" {
user, _ := os.LookupEnv("SHIORI_MYSQL_USER")
password, _ := os.LookupEnv("SHIORI_MYSQL_PASS")
dbName, _ := os.LookupEnv("SHIORI_MYSQL_NAME")
dbAddress, _ := os.LookupEnv("SHIORI_MYSQL_ADDRESS")
connString := fmt.Sprintf("%s:%s@%s/%s", user, password, dbAddress, dbName)
return database.OpenMySQLDatabase(connString)
}

@matusnovak
Copy link
Author

Awesome! Thank you very much.

@matusnovak
Copy link
Author

For future visitors:

If anyone is trying to do the same, you have to wrap the MySQL address in tcp(...) as the following:

docker run ... -e "SHIORI_MYSQL_ADDRESS=tcp(mysql_address_or_ip_here:3306)"

Reference: go-sql-driver/mysql#427

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants