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

Make Trilogy the default MySQL adapter #50110

Closed

Conversation

casperisfine
Copy link
Contributor

Trilogy has been production tested on very large Rails applications in the wild, is much easier to install than mysql2 as it doesn't depend on libmysqlclient, and generally is better maintained and performs better.

Addtionally it has always bothered me that you need to pass a mysql2:// or trilogy:// DATABASE_URL as it's a leaky abstraction, the DATABASE_URL should specify the protocol, not the client used.

rails new --database=mysql will now generate an application using Trilogy.

DATABASE_URL=mysql://host will now use the trilogy adapter.

This has no impact on existing applications.

FYI: @kmcphillips @adrianna-chang-shopify

Trilogy has been production tested on very large Rails applications in the wild,
is much easier to install than `mysql2` as it doesn't depend on `libmysqlclient`,
and generally is better maintained and performs better.

Addtionally it has always bothered me that you need to pass a `mysql2://` or
`trilogy://` `DATABASE_URL` as it's a leaky abstraction, the `DATABASE_URL` should
specify the protocol, not the client used.

`rails new --database=mysql` will now generate an application using Trilogy.

`DATABASE_URL=mysql://host` will now use the trilogy adapter.

This has no impact on existing applications.
@dalibor
Copy link
Contributor

dalibor commented Nov 20, 2023

It does not seem to work with MySQL 8.0 (official docker container):

Loading test environment (Rails 7.1.2)
>> User.last
/Users/dnasevic/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/trilogy-2.6.0/lib/trilogy.rb:16:in `_initialize': Trilogy::QueryError: trilogy_auth_recv: TRILOGY_UNEXPECTED_PACKET (ActiveRecord::ConnectionFailed)
/Users/dnasevic/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/trilogy-2.6.0/lib/trilogy.rb:16:in `_initialize': trilogy_auth_recv: TRILOGY_UNEXPECTED_PACKET (Trilogy::QueryError)

MySQL version (docker run -it --rm -p 3306:3306 -e MYSQL_ROOT_PASSWORD=pass mysql:8.0):

bash-4.4# mysql --version
mysql  Ver 8.0.35 for Linux on aarch64 (MySQL Community Server - GPL)

Possibly related to caching_sha2_password support: trilogy-libraries/trilogy#26

@casperisfine
Copy link
Contributor Author

Closing in favor of #50112

@casperisfine casperisfine deleted the trilogy-default-mysql-adapter branch November 20, 2023 14:34
@casperisfine
Copy link
Contributor Author

It does not seem to work with MySQL 8.0 (official docker container):

Right, that should be considered a blocker for making it the default. I think we'll probably have support for it in time for Rails 7.2 though.

@flavorjones
Copy link
Member

flavorjones commented Nov 20, 2023

@casperisfine is that the same issue described at brianmario/mysql2#1286 ?

Edit: I read a bit more and see that it's a separate issue. Ignore.

@byroot
Copy link
Member

byroot commented Nov 20, 2023

Maybe m, I'll have to dig into it. I'd assume mysql2 would have support for it since it binds libmysqlclient.

But it's unclear if the people running to this have libmysqlclient 5 or 8.

And also perhaps there is something mysql2 need to do to enable that support?

@kmcphillips
Copy link
Contributor

I'm not fully sure of the root issue, but the important behaviour difference here, on Ubutnu 22.04 with a default install of MySQL:

$ ~/source/rails/railties/exe/rails new test_app --dev --database=mysql --skip-asset-pipeline --skip-javascript --skip-hotwire --skip-test
...
$ bin/rails db:setup
Created database 'test_app_development'
Created database 'test_app_test'
$ bin/rails runner 'puts ActiveRecord::Base.connection.execute("select version()").to_a'
8.0.35-0ubuntu0.22.04.1
$ ~/source/rails/railties/exe/rails new test_app --dev --database=trilogy --skip-asset-pipeline --skip-javascript --skip-hotwire --skip-test
...
$ bin/rails db:setup
Trilogy::QueryError: trilogy_auth_recv: TRILOGY_UNEXPECTED_PACKET
Couldn't create 'test_app_development' database. Please check your configuration.
bin/rails aborted!
ActiveRecord::ConnectionFailed: Trilogy::QueryError: trilogy_auth_recv: TRILOGY_UNEXPECTED_PACKET (ActiveRecord::ConnectionFailed)

Caused by:
Trilogy::QueryError: trilogy_auth_recv: TRILOGY_UNEXPECTED_PACKET (Trilogy::QueryError)

Trilogy fails to support default authentication out of the box.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants