How to Use WordPress Studio with a MySQL Database Instead of SQLite
If you’re using WordPress Studio and want to work with a locally developed MySQL database instead of SQLite, you’re in the right place. WordPress Studio provides built-in support for SQLite but also allows you to configure a MySQL database of your choice. Here’s a step-by-step guide to set up MySQL with WordPress Studio and solve the common issue of “Address family not supported by protocol”.
Setting Up WordPress Studio with MySQL
WordPress Studio supports connecting to a custom MySQL server. If you’ve already created a WordPress site in Studio and want to switch from SQLite to MySQL, follow these steps:
- Stop the WordPress Studio Site
Use the Studio interface or terminal to stop the site. -
Remove SQLite Integration
- Navigate to your Studio’s site directory.
- Go to the
wp-content
directory and:- Delete the
db.php
file. - Delete the
database
directory.
- Delete the
- Navigate to the
mu-plugins
directory and:- Delete the
sqlite-database-integration-main
directory.
- Delete the
- Update
wp-config.php
with MySQL Credentials
Open thewp-config.php
file in the site directory and add the following details:“`php
define(‘DB_NAME’, ‘your_database_name’);
define(‘DB_USER’, ‘your_database_user’);
define(‘DB_PASSWORD’, ‘your_database_password’);
define(‘DB_HOST’, ‘127.0.0.1’); // Use 127.0.0.1 instead of localhost
define(‘DB_CHARSET’, ‘utf8’);
define(‘DB_COLLATE’, ”);
Note: The key fix here is to use 127.0.0.1 instead of localhost. This forces WordPress to connect via TCP instead of trying to use a socket.
Start the MySQL Server
Ensure your MySQL server is running. You can use tools like Docker, Homebrew, or any other local MySQL setup.
Restart the WordPress Studio Site
Start the site in WordPress Studio.
Open the Site
Navigate to the site URL, and WordPress will now connect to your MySQL database.
Common Issue: “Address family not supported by protocol”
If you encounter this error during the setup process, it’s likely because WordPress is attempting to connect to MySQL using a socket instead of TCP. By default, localhost in WordPress triggers a socket connection.
Solution: Use 127.0.0.1 Instead of localhost
In the wp-config.php file, replace:
define(‘DB_HOST’, ‘localhost’);
with:
define(‘DB_HOST’, ‘127.0.0.1’);
This ensures that WordPress uses a TCP connection to communicate with MySQL, avoiding the socket-related error.
Verifying the Setup
Open your site in the browser.
If the connection is successful, WordPress should display your site without database errors.
If you still encounter issues, double-check your MySQL credentials, ensure the MySQL server is running, and verify the wp-config.php file configuration.
Need Help with WordPress Automation?
If you’re interested in learning more about automating WordPress site creation, database management, or publishing workflows, feel free to contact me through my blog at matteolavaggi.it. I’d be happy to guide you through advanced WordPress setups and automation techniques tailored to your needs!