If you want to create a rails application with mysql on windows and run it. You may encountered an error below:
C:/Ruby193/lib/ruby/gems/1.9.1/gems/mysql-2.9.0-x86-mingw32/lib/mysql.rb:4:in `require’: Incorrect MySQL client library version! This gem was compiled for 6.0.0 but the client library is 5.5.27. (RuntimeError)
That means that your installed Mysql client was version 5.5.27 and is not compatible to the installed mysql gem, in which you’ve previously installed by using the command gem install mysql
To fix the issue, remove first the previous installed mysql gem: bundle exec gem uninstall mysql2
And install the mysql2 gem library: gem install mysql2
C:\railsproject\demo_app>gem install mysql2
You've installed the binary version of mysql2.
It was built using MySQL Connector/C version 6.0.2.
It's recommended to use the exact same version to avoid potential issues.
At the time of building this gem, the necessary DLL files where available
in the following download:
Copy/paste the lib\libmysql.dll file in your Ruby bin directory, for example C:\Ruby22\bin
Download the mysql connector, copy libmysql.dll in C:\Ruby\bin directory. Thats it!
Then, run the app again:
Another problem when using mysql2 that u might encountered an error below:
Please install the mysql2 adapter: `gem install activerecord-mysql2-adapter` (cannot load such file — active_record/connection_adapters/mysql2_adapter)
Solution: You need to add gem ‘mysql2’ in the Gemfile for example: gem ‘mysql2’, ‘~> 0.2.11’ and then bundle install.
Problem that you may encountered also is TZInfo::DataSourceNotFound:
C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/tzinfo-1.2.3/lib/tzinfo/data_source.rb:182:in `rescue in create_default_data_source':
No source of timezone data could be found. (TZInfo::DataSourceNotFound)
Please refer to http://tzinfo.github.io/datasourcenotfound for help resolving this error.
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/tzinfo-1.2.3/lib/tzinfo/data_source.rb:179:in `create_default_data_source'
Solution: You need to edit the Gemfile.
Note: If you are using a 64-bit version of Ruby on Windows, then add :x64_mingw to the list of platforms as follows:
gem ‘tzinfo-data’, platforms: [:mingw, :mswin, :x64_mingw]
Or lets simply remove the platforms option e.g. gem ‘tzinfo-data’ for OS portability.