-
Notifications
You must be signed in to change notification settings - Fork 385
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
MySQL JDBC adapter fails to support utf8mb4 encoding #481
Comments
Further research shows that the way to handle utf8mb4 encoding is to specify character_set_server=utf8mb4 on the server. From there, we're supposed to not send a characterEncoding parameter as part of the connection string. This was taken from: http://bugs.mysql.com/bug.php?id=64823 If we choose to remove 'encoding' from the database.yml, it looks like ActiveRecord is by default specifying characterEncoding=utf8. Suggestions on how to override that? |
thanks for the report ... not really - you will need to monkey-patch ArJdbc::ConnectionMethods.module_eval do
def mysql_connection(config)
begin
require 'jdbc/mysql'
::Jdbc::MySQL.load_driver(:require) if defined?(::Jdbc::MySQL.load_driver)
rescue LoadError # assuming driver.jar is on the class-path
end
config[:username] = 'root' unless config.key?(:username)
# jdbc:mysql://[host][,failoverhost...][:port]/[database]
# - if the host name is not specified, it defaults to 127.0.0.1
# - if the port is not specified, it defaults to 3306
# - alternate fail-over syntax: [host:port],[host:port]/[database]
unless config[:url]
host = config[:host]; host = host.join(',') if host.respond_to?(:join)
url = "jdbc:mysql://#{host}"
url << ":#{config[:port]}" if config[:port]
url << "/#{config[:database]}"
config[:url] = url
end
config[:driver] ||= defined?(::Jdbc::MySQL.driver_name) ? ::Jdbc::MySQL.driver_name : 'com.mysql.jdbc.Driver'
config[:adapter_spec] ||= ::ArJdbc::MySQL
config[:adapter_class] = ActiveRecord::ConnectionAdapters::MysqlAdapter unless config.key?(:adapter_class)
properties = ( config[:properties] ||= {} )
properties['zeroDateTimeBehavior'] ||= 'convertToNull'
properties['jdbcCompliantTruncation'] ||= 'false'
properties['useUnicode'] ||= 'true'
if config.has_key?(:encoding)
encoding = config[:encoding]
else
encoding = 'utf8'
end
properties['characterEncoding'] = encoding if encoding
jdbc_connection(config)
end
alias_method :jdbcmysql_connection, :mysql_connection
alias_method :mysql2_connection, :mysql_connection
end ... and set encoding: false for now - we'll need to investigate this if removing the utf8 default would not cause issues |
interestingly it should have been working as is ... at least that what the change-log for 5.1.13 says :
http://dev.mysql.com/doc/relnotes/connector-j/en/news-5-1-13.html |
any news on this ... didn't you happen to be using an old (< 5.1.13) driver version ? regardless of encoding: utf8 |
Hi kares, I'm using whatever was bundled with the acriverecord-jdbc-mysql-adapter with 1.3.0.rc1. :\ We ended up monkey patching it. Haven't ran into any issues at all with it since then! |
Thanks, please use 1.3.2 instead or at least 1.3.0 there's been some fixes since the first RC :) |
Great! We're going to try 1.3.2 and using jdbc-mysql (5.1.27). I'll report back once we have a chance to run it through our test suite. |
I am converting my MRI Rails 3 app to Jruby, and it fails to start due to this.
Gems:
Database.yml
Why does it not just allow utf8mb4? Should I set my encoding to false? |
it's probably the official connector-j driver playing smart ... once again we'll probably default to |
hey guys ! I just find out a way to avoid that issue. It works!! |
The comment above didnt work for me, I'm now using this:
|
Hi -
I need to use utf8mb4 encoding in order for MySQL to support 4 byte characters. A new encoding type, "utf8mb4" was introduced as of MySQL 5.5 to support this. However when I try and use an encoding type of "utf8mb4" in my database.yml, I receive the following exception after the first SQL request:
ActiveRecord::JDBCError: The driver encountered an unknown error: java.sql.SQLException: Unsupported character encoding 'utf8mb4'.
Am I missing something? Shouldn't this just "pass through" and work appropriately?
The text was updated successfully, but these errors were encountered: