To connect Directus to a MySQL database, follow the steps given below:
If you haven’t installed Directus yet, you can install it via npm or Docker. Here’s the npm installation method:
Directus uses environment variables to connect to a database. To connect to MySQL, you'll need to configure the ‘.env’ file in your Directus project.
Edit the ‘.env’ file to add the MySQL connection details:
Before running Directus, ensure you have created the MySQL database. You can do this through MySQL command line or a tool like phpMyAdmin:
After configuring the .env file, run Directus to initialize the connection:
Directus will automatically connect to the specified MySQL database, run the necessary migrations, and set up the required schema.
When Directus starts successfully, you can access it via your web browser at
http://localhost:8055
. If the connection to MySQL is working, Directus will load without any database errors.