Skip to content

Commit 038f23e

Browse files
committed
Fix MySQL connection by using 127.0.0.1 instead of localhost
MySQL in Docker requires TCP connection, not Unix socket. Using localhost attempts to connect via socket, while 127.0.0.1 forces TCP connection.
1 parent 76c6303 commit 038f23e

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

.github/workflows/example.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ jobs:
8282
docker exec $(docker compose ps -q mysql) mysql -uroot -e "CREATE DATABASE testdb;"
8383
# Test connection from host
8484
echo "Testing connection from host..."
85-
mysql -h localhost -P 3306 -u root -e "SHOW DATABASES;" || echo "Direct connection failed, but that's OK if mysqldef can connect"
85+
mysql -h 127.0.0.1 -P 3306 -u root -e "SHOW DATABASES;" || echo "Direct connection failed, but that's OK if mysqldef can connect"
8686
8787
- name: Preview MySQL schema changes
8888
uses: ./
@@ -93,7 +93,7 @@ jobs:
9393
schema-file: examples/mysqldef-desired.sql
9494
mysql-user: root
9595
mysql-password: ''
96-
mysql-host: localhost
96+
mysql-host: 127.0.0.1
9797
mysql-port: 3306
9898
mysql-database: testdb
9999

dist/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ function getCommandConfig(command) {
120120
case "mysqldef": {
121121
const user = core.getInput("mysql-user");
122122
const password = core.getInput("mysql-password");
123-
const host = core.getInput("mysql-host") || "localhost";
123+
const host = core.getInput("mysql-host") || "127.0.0.1";
124124
const port = core.getInput("mysql-port") || "3306";
125125
const database = core.getInput("mysql-database");
126126
config.args.push("-h", host, "-P", port);
@@ -341,11 +341,11 @@ async function run() {
341341
if (baselineConfig.env) {
342342
const sanitizedEnv = { ...baselineConfig.env };
343343
// Mask any password values for security
344-
if ('MYSQL_PWD' in sanitizedEnv) {
345-
sanitizedEnv.MYSQL_PWD = sanitizedEnv.MYSQL_PWD ? '***' : '(empty)';
344+
if ("MYSQL_PWD" in sanitizedEnv) {
345+
sanitizedEnv.MYSQL_PWD = sanitizedEnv.MYSQL_PWD ? "***" : "(empty)";
346346
}
347-
if ('PGPASSWORD' in sanitizedEnv) {
348-
sanitizedEnv.PGPASSWORD = sanitizedEnv.PGPASSWORD ? '***' : '(empty)';
347+
if ("PGPASSWORD" in sanitizedEnv) {
348+
sanitizedEnv.PGPASSWORD = sanitizedEnv.PGPASSWORD ? "***" : "(empty)";
349349
}
350350
core.debug(`Environment variables: ${JSON.stringify(sanitizedEnv)}`);
351351
}

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ function getCommandConfig(command: string): CommandConfig {
9494
case "mysqldef": {
9595
const user = core.getInput("mysql-user");
9696
const password = core.getInput("mysql-password");
97-
const host = core.getInput("mysql-host") || "localhost";
97+
const host = core.getInput("mysql-host") || "127.0.0.1";
9898
const port = core.getInput("mysql-port") || "3306";
9999
const database = core.getInput("mysql-database");
100100

0 commit comments

Comments
 (0)