1

I use next settings to connect to remote DB:

class MyModel < ActiveRecord::Base
self.table_name = 'users'
establish_connection(
adapter: "mysql2",
host: "host_ip",
encoding: "koi8u",
username: "custom_name",
password: "password",
database: "db_name")
end

It connects well but when I make a query, I receive something like Address: "п⌠п╟п╪п╟п?п╦п? п░п╩я▄я├п╣я│я┌"

I also try another variant of connection like:

connection = Mysql2::Client.new( host: 'host_name',                                                            
username: 'user',                                                                     
password: 'password',                                                                     
port: 3306,                                                                  
database: 'db_name',                                                              
encoding: 'koi8u',                                                                    
reconnect: true                                                                     
)

In this case I receive connection object, but can't make a query... When I use connection.query("SELECT * FROM users") it returns me the connection object... Also when I check encoding it returns:

MyModel.first.Address.encoding.name
MyModel Load (6.8ms)  SELECT `users`.* FROM `users` ORDER BY `users`.`login` ASC LIMIT   
1
=> "UTF-8"

When in settings I use koi8u !

I was checking charset on MySQL server in this DB - it is set to koi8u !

Any ideas? I need to connect to this DB with normal charset

RomanDev
  • 86
  • 3

1 Answers1

0

It seems to me that your database locale is different then you expect it to be Did you changed it or set it in any stage?

It is not enough to declare about it in the connection string

You can find up here how to check what is your database character set

How do I see what character set a MySQL database / table / column is?

Community
  • 1
  • 1
Oz Ben-David
  • 1,589
  • 1
  • 16
  • 26