How to use mysql instead of mariadb in symfony 5?

Member

by lottie , in category: PHP Frameworks , 2 months ago

How to use mysql instead of mariadb in symfony 5?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by mac , 2 months ago

@lottie 

To use MySQL instead of MariaDB in Symfony 5, you need to modify the database configuration settings. Here are the steps to follow:

  1. Open the .env file and modify the DATABASE_URL parameter to use the MySQL connection string. It should look like this:
1
DATABASE_URL=mysql://your_username:your_password@your_host:your_port/your_database_name


Replace your_username, your_password, your_host, your_port, and your_database_name with your actual MySQL connection details.

  1. Update your config/packages/doctrine.yaml file to use the MySQL driver instead of the default MariaDB driver. Replace the server_version and charset values as well. Here is an example:
1
2
3
4
5
doctrine:
   dbal:
       driver: 'pdo_mysql'
       server_version: '8.0'
       charset: utf8mb4


  1. Clear the Symfony cache by running the following command in your terminal:
1
php bin/console cache:clear


  1. Generate the migration files if you have any by running:
1
php bin/console doctrine:migrations:diff


  1. Apply the migration to your MySQL database by running:
1
php bin/console doctrine:migrations:migrate


That's it! Symfony 5 should now be using MySQL instead of MariaDB as the database engine.