How can I execute a SQL query from a Rails application to a MySQL database?
My application uses Postgres as a primary database, but I need to read some information from a secondary MySQL database. I can’t create models because the MySQL database has more than 100 tables, named in an incompatible way for every table. Can it be done without ActiveRecord or some other way?
You can use mysql2 gem directly. Read the documentation here:
https://github.com/brianmario/mysql2
Or:
You can create a new class like MysqlConnection like this:
From now on, you can do,
Follow the link to understand how to store the configuration details in database.yml: http://weare.buildingsky.net/2006/12/06/multiple-concurrent-database-connections-with-activerecord