Score:0

How do I switch from PostgreSQL to MySQL

mv flag

I set up a website using Drupal 10 and PostgreSQL but due to a communication delay, I just found out from the server team that the database on the staging/live servers is MySQL and not PostgreSQL. I now face the issue of switching my site to use MySQL instead.

My goal is to switch the database from my local PostgreSQL database to my newly created local MySQL database so that I can easily migrate the site to the staging and live servers in the future. Alternatively, I would like to know if this is futile and if I am forced to start development from scratch.

Attempted Solutions

I did a lot of research to try to find information on how to make the change. I couldn't find any Drupal documentation on how to do this. I only found information on how to migrate the database, but it seemed to be specific to migrating to the same environment and not switching databases completely.

I found this 11 year old article which made it seem like I simply had to edit my settings.php file and change the $databases array.

My $databases array in my settings.php file looks like this:

$databases['default']['default'] = array (
  'database' => (database_name),
  'username' => (user),
  'password' => (password),
  'prefix' => '',
  'host' => 'localhost',
  'port' => '5432',
  'namespace' => 'Drupal\\pgsql\\Driver\\Database\\pgsql',
  'driver' => 'pgsql',
  'autoload' => 'core/modules/pgsql/src/Driver/Database/pgsql/',
);

Changing the database name, user, pass and port were easy enough, but I don't know what to change the namespace, driver, or autoload to, so I wasn't able to complete this attempt. I am frankly not sure if I am even on the right track or not.

Question

How do I switch my Drupal 10 site from PostgreSQL to MySQL in a way that preserves as much data as possible?

Is this even possible, or do I have to start my website over with MySQL?

Additional Information

  • All of the data on the site including the users is dummy data and not a big deal if it can't be preserved
  • The main information I would like to preserve is the data structures, views, and roles as these have configured permissions for various content types and fields that would be tedious to replicate
Kevin avatar
in flag
Views, roles, permissions and content types are all tracked in configuration and that should be exported out and imported into a new database. Beyond that, the driver settings in settings.php should match default.settings.php as far as driver and namespace value is concerned.
id flag
Did you install a MySQL site to see those defaults?
MrD avatar
cn flag
MrD
Did you try https://www.drupal.org/docs/develop/local-server-setup/linux-development-environments/set-up-a-local-development-drupal-1
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.