Skip to content

Instantly share code, notes, and snippets.

@fabianoone
Created February 11, 2026 12:50
Show Gist options
  • Select an option

  • Save fabianoone/a1e9368005304dda6cee354a64adb7b2 to your computer and use it in GitHub Desktop.

Select an option

Save fabianoone/a1e9368005304dda6cee354a64adb7b2 to your computer and use it in GitHub Desktop.

[WP Local & PHPStorm] - Connecting to MySQL using TCP/IP rather than a socket on macOS/Linux?

source: https://community.localwp.com/t/how-can-i-connect-to-mysql-using-tcp-ip-rather-than-a-socket-on-macos-linux/21220

Steps Right-click on the site you wish to connect to via TCP/IP in Local’s sidebar and go to “Open Site Shell.”

Once your terminal opens, run the following commands:

Allow root to connect via 127.0.0.1.

mysql -e "CREATE USER 'root'@'127.0.0.1' IDENTIFIED BY 'root'; GRANT ALL ON . TO 'root'@'127.0.0.1';" Get the TCP/IP port that MySQL is currently running on. Note, this is not shown in Local’s UI as of writing if on macOS or Linux

mysql -e "SHOW VARIABLES WHERE Variable_name = 'port';" Here’s an example of what you should see after running these two commands:

Screen Shot 2020-07-31 at 10.02.05 AM Screen Shot 2020-07-31 at 10.02.05 AM 2036×240 62.8 KB Example: Connecting via PhpStorm Now that the user is created and you have the port, you can connect to it! Here’s what that looks like in PhpStorm.

Be sure that you use 127.0.0.1 as the “Host”, update “Port” to the port output in step #2 above, and set “Database” to local.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment