From ff0bce8900605ba97bd79280b159e3de3a314c02 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Sun, 14 Oct 2018 14:50:22 -0400 Subject: [PATCH 1/2] OH YOU JUST GOT PRANKED --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 852a6a430a..258a1d3128 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ Create an `appsettings.Production.json` file next to `appsettings.json`. This wi - `Database:MySqlServerVersion`: The version of MySql/MariaDB the database resides on, can be left as null for attempted auto detection. Used by the MySQL/MariaDB provider for selection of [certain features](https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql/blob/2.1.1/src/EFCore.MySql/Storage/Internal/ServerVersion.cs) ignore at your own risk. A string in the form `..` -- `Database:ConnectionString`: Connection string for your database. Click [here](https://www.developerfusion.com/tools/sql-connection-string/) for an SQL Server generator or see [here](https://www.connectionstrings.com/mysql/) for a MySQL guide. +- `Database:ConnectionString`: Connection string for your database. Click [here](https://www.developerfusion.com/tools/sql-connection-string/) for an SQL Server generator or see [here](https://www.connectionstrings.com/mysql/) for a MySQL guide ([You should probably use '127.0.0.1' instead of 'localhost'](https://stackoverflow.com/questions/19712307/mysql-localhost-127-0-0-1)). ### Database Configuration From 157d6dfedf550ba16c5188275a19a7531524732e Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Sun, 14 Oct 2018 15:02:19 -0400 Subject: [PATCH 2/2] @steamp0rt's warning idea --- src/Tgstation.Server.Host/Models/MySqlDatabaseContext.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Tgstation.Server.Host/Models/MySqlDatabaseContext.cs b/src/Tgstation.Server.Host/Models/MySqlDatabaseContext.cs index 99657144aa..8c03b31ee0 100644 --- a/src/Tgstation.Server.Host/Models/MySqlDatabaseContext.cs +++ b/src/Tgstation.Server.Host/Models/MySqlDatabaseContext.cs @@ -1,6 +1,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; +using MySql.Data.MySqlClient; using Pomelo.EntityFrameworkCore.MySql.Infrastructure; using System; using Tgstation.Server.Host.Configuration; @@ -26,6 +27,12 @@ namespace Tgstation.Server.Host.Models protected override void OnConfiguring(DbContextOptionsBuilder options) { base.OnConfiguring(options); + var stringDeconstructor = new MySqlConnectionStringBuilder + { + ConnectionString = DatabaseConfiguration.ConnectionString + }; + if (stringDeconstructor.Server == "localhost") + Logger.LogWarning("MariaDB/MySQL server address is set to 'localhost'! If there are connection issues, try setting it to '127.0.0.1'!"); if (!String.IsNullOrEmpty(DatabaseConfiguration.MySqlServerVersion)) options.UseMySql(DatabaseConfiguration.ConnectionString, mySqlOptions => mySqlOptions.ServerVersion(Version.Parse(DatabaseConfiguration.MySqlServerVersion), DatabaseConfiguration.DatabaseType == DatabaseType.MariaDB ? ServerType.MariaDb : ServerType.MySql)); else