Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace mysql with mysql2 #19361

Open
u12206050 opened this issue Aug 6, 2023 · 12 comments · May be fixed by #22534
Open

Replace mysql with mysql2 #19361

u12206050 opened this issue Aug 6, 2023 · 12 comments · May be fixed by #22534

Comments

@u12206050
Copy link
Contributor

Describe the Bug

Changing DB_CLIENT from mysql to mysql2 and installing the mysql2 package leads to an error about unsupported database client.
Though I understand this is not a bug, I did find in the code that both Knex and the Directus schema code support mysql2 so wonder if this was just missed?

To Reproduce

Ad in in description switch to mysql2

Directus Version

10.5.2

Hosting Strategy

Self-Hosted (Docker Image)

@rijkvanzanten rijkvanzanten changed the title Unable to use mysql2 even though knex and schema supports it Replace mysql with mysql2 Aug 7, 2023
@rijkvanzanten
Copy link
Member

I'd rather not try to support both if the end result is the same, so I'm hijacking this issue as a reminder to replace mysql with mysql2 completely 🙂

@clayboc
Copy link

clayboc commented Feb 1, 2024

Please don't forget about this, the mysql error logs are getting ridiculous. Thanks for all your hard work.

@fire015
Copy link

fire015 commented Feb 23, 2024

+1 for this feature

@u12206050
Copy link
Contributor Author

I can reveal that I have been using Directus with mysql2 for the past year now in three production environments and have had zero issues so far, if anyone was wondering about possible issues.

I apply it via a hotfix overwrite of some directus files

@fire015
Copy link

fire015 commented Feb 24, 2024

How are you applying the hotfix? Are you manually editing files in node_modules?

@u12206050
Copy link
Contributor Author

Yeh, from the start I have been using Directus via npm install, since there are so many hot-fixes I need just for different reasons. Here is my full set of hot fixes, most are done for performance optimisations that I have made PRs for, but they are not in Directus yet. So if you only use mysql, then you should be able to use this: Unzip into your root Directus folder (same as where extensions folder is) then run node hot-fix.js

hot-fixes.zip

@u12206050 u12206050 reopened this Feb 24, 2024
@fire015
Copy link

fire015 commented Feb 24, 2024

Nice one thanks will take a look!

@fire015
Copy link

fire015 commented Feb 24, 2024

A better way to do this is to just run this bash command after install to find/replace (can even execute inside Docker):

sed -i -e 's/Client_MySQL/Client_MySQL2/' node_modules/@directus/api/dist/database/index.js

Also set DB_CLIENT="mysql2" in your .env file.

@makakken
Copy link

this issue gains importance. you cannot start directus with actual versions of mysql8....
even if you use: --mysql-native-password=ON on the mysql-container, the default generated user has no "mysql_native_password" auth... so directus is not starting alongside with mysql bigger than 8.3.

@agantelin
Copy link

this issue gains importance. you cannot start directus with actual versions of mysql8.... even if you use: --mysql-native-password=ON on the mysql-container, the default generated user has no "mysql_native_password" auth... so directus is not starting alongside with mysql bigger than 8.3.

Try this solution. It helped me run the container.
https://stackoverflow.com/a/78447221/4022411

But this issue is really becoming important.

@robinsonjohn
Copy link

+1 for getting this fixed. Not only is using mysql_native_password less secure, but this is making it increasingly difficult to use MySQL databases with Directus. And since Directus allows you to use it with a preexisting database, the answer isn't always as straightforward as saying 'use another database'...

@marchiolidev
Copy link

Based on the suggestion by @fire015, I build this minimal Dockerfile for those using docker.

FROM directus/directus
WORKDIR /directus

#Directus uses pnpm as it's package manager, but the official docker image doesn't come with it installed.
#The current user (node) doesn't have permission to install global packages, so we switch to root and install pnpm.
USER root
RUN npm install -g pnpm@9.0.6 

#We can now switch back to the node user and run our install command to add mysql2 lib.
USER node
RUN pnpm i mysql2

#Then we run the command provided by our friend [fire015](https://github.com/fire015)
RUN sed -i -e 's/Client_MySQL/Client_MySQL2/' node_modules/@directus/api/dist/database/index.js

@paescuj paescuj linked a pull request May 21, 2024 that will close this issue
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 📋 Backlog
9 participants