TablePlus / DBngin

DB Engine
https://dbngin.com
1.08k stars 19 forks source link

[Feature Request] Make DBngin work with `localhost` #160

Closed hirasso closed 2 weeks ago

hirasso commented 2 weeks ago

Hi there!

Amazing work on DBngin. Thank you!!

Current behavior

As discussed in #127 , DBngin currently only supports connections via 127.0.0.1.

Desired behavior

I'd love if DBngin would also support connections via localhost.

I asked ChatGPT about the differences between localhost and 127.0.0.1

In MySQL, there’s a subtle difference between using 127.0.0.1 and localhost as the host when connecting to the database, which comes down to how MySQL handles the connection:

  1. localhost: When you use localhost as the hostname, MySQL tries to connect via the Unix socket file (e.g., /var/run/mysqld/mysqld.sock on Linux systems), instead of making a TCP/IP connection. This socket-based connection is typically faster for local connections because it bypasses the network stack.

  2. 127.0.0.1: When you specify 127.0.0.1, MySQL will connect via TCP/IP, even though it’s a local address. This is necessary if the MySQL server is configured to allow only TCP connections or if the client application is explicitly set to connect over TCP.

Summary of Differences:

  • localhost → Connects via Unix socket.
  • 127.0.0.1 → Connects via TCP/IP.

Using one over the other can sometimes cause connection issues if MySQL is configured to allow only one type of connection or if permissions are set differently for each connection method.

System Infos

  1. Driver: MySQL 5.7
  2. DBngin build number and platform: 7.3 on MacOS
  3. MacOS: Sonoma
  4. I'm using DBngin in combination with Laravel Herd.

Steps to repdroduce

huyphams commented 2 weeks ago

Do you have the rosetta 2 on your mac @hirasso also can you post the error log?

hirasso commented 2 weeks ago

@huyphams woaaaa that was fast ⚡️⚡️

It seems like I have rosetta 2 installed (no idea what that does):

❯ /usr/bin/pgrep oahd
510

I don't really have an error log. I'm mostly developing WordPress websites, and there I'm getting not very specific information, but rather only this screen in the browser when using localhost instead of 127.0.0.1:

CleanShot 2024-11-08 at 09 22 26@2x

huyphams commented 2 weeks ago

You could find the log here

Screenshot 2024-11-08 at 3 22 59 PM
huyphams commented 2 weeks ago

Show database files, that folder contains log file.

hirasso commented 2 weeks ago

What should the file be called?

huyphams commented 2 weeks ago

You can find the file that contains the err in the name (the only file)

Screenshot 2024-11-08 at 3 27 24 PM
hirasso commented 2 weeks ago

Got it. I cleared that file while the service was off and then started the service. This is the output in the error log:

2024-11-08T08:27:47.213664Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2024-11-08T08:27:47.213876Z 0 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled
2024-11-08T08:27:47.213905Z 0 [Note] /Users/Shared/DBngin/mysql/5.7.23/bin/mysqld (mysqld 5.7.23) starting as process 29072 ...
2024-11-08T08:27:47.216276Z 0 [Warning] Setting lower_case_table_names=2 because file system for /Users/rah/Library/Application Support/com.tinyapp.DBngin/Engines/mysql/80085D76-586B-4235-99D1-FBAA2E7D29A9/ is case insensitive
2024-11-08T08:27:47.216859Z 0 [Warning] One can only use the --user switch if running as root

2024-11-08T08:27:47.217958Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2024-11-08T08:27:47.217969Z 0 [Note] InnoDB: Uses event mutexes
2024-11-08T08:27:47.217974Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2024-11-08T08:27:47.217978Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.3
2024-11-08T08:27:47.219217Z 0 [Note] InnoDB: Number of pools: 1
2024-11-08T08:27:47.219307Z 0 [Note] InnoDB: Using CPU crc32 instructions
2024-11-08T08:27:47.220205Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2024-11-08T08:27:47.227563Z 0 [Note] InnoDB: Completed initialization of buffer pool
2024-11-08T08:27:47.242726Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2024-11-08T08:27:47.315051Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2024-11-08T08:27:47.315190Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2024-11-08T08:27:47.318387Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2024-11-08T08:27:47.318941Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2024-11-08T08:27:47.318952Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2024-11-08T08:27:47.319229Z 0 [Note] InnoDB: Waiting for purge to start
2024-11-08T08:27:47.374397Z 0 [Note] InnoDB: 5.7.23 started; log sequence number 2736360853
2024-11-08T08:27:47.374623Z 0 [Note] InnoDB: Loading buffer pool(s) from /Users/rah/Library/Application Support/com.tinyapp.DBngin/Engines/mysql/80085D76-586B-4235-99D1-FBAA2E7D29A9/ib_buffer_pool
2024-11-08T08:27:47.374755Z 0 [Note] Plugin 'FEDERATED' is disabled.
2024-11-08T08:27:47.377210Z 0 [Note] InnoDB: Buffer pool(s) load completed at 241108  9:27:47
2024-11-08T08:27:47.378394Z 0 [Warning] Failed to set up SSL because of the following SSL library error: SSL context is not usable without certificate and private key
2024-11-08T08:27:47.378409Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
2024-11-08T08:27:47.378516Z 0 [Note] IPv6 is available.
2024-11-08T08:27:47.378532Z 0 [Note]   - '::' resolves to '::';
2024-11-08T08:27:47.378562Z 0 [Note] Server socket created on IP: '::'.
2024-11-08T08:27:47.389132Z 0 [Note] Event Scheduler: Loaded 0 events
2024-11-08T08:27:47.389319Z 0 [Note] /Users/Shared/DBngin/mysql/5.7.23/bin/mysqld: ready for connections.
Version: '5.7.23'  socket: '/tmp/mysql_3306.sock'  port: 3306  MySQL Community Server (GPL)
huyphams commented 2 weeks ago

so I think it has nothing todo with DBngin.

You should point the connect to socker /tmp/mysql_3306.sock

Or the address 127.0.0.1 and port 3306 (not localhost)

hirasso commented 2 weeks ago

So basically the same as this article says:

Make sure your DB_HOST is 127.0.0.1 and NOT localhost or you’ll get a connection error and be sure the port matches the port designated for that specific service with the listed database in your DBngin.

MAMP, that I was using before Herd/DBngin, managed to get this to work with localhost... but don't get me wrong – I love my new shiny setup!! 😄

Should there ever be a solution to this, I'd happy to hear about it. I'll close this for now.

Again, thanks @huyphams for this amazing tool!