how to install mysql2 via Gemfile in Rails
You can install MySQL server and client from the packages in the Ubuntu repository. As part of the installation process, you'll set the password for the root user. This information will go into your Rails app's database.yml
file in the future.
sudo apt-get install mysql-server mysql-client libmysqlclient-dev
Installing the libmysqlclient-dev gives you the necessary files to compile the mysql2
gem which is what Rails will use to connect to MySQL when you setup your Rails app.
Install the mysql2 gem for a specific mysql client version?
The problem here was that the MySQL2 gem was compiled for the MySQL version installed by Apple (Development package) not by me using Homebrew.
Using this command when installing the gem solved the problem.
gem install mysql2 -- --with-mysql-config=/usr/local/Cellar/mysql/5.5.14/bin/mysql_config
Don't forget to install mysql using:
sudo brew install mysql
The problem now is that we somehow need to pass the option to bundler, to do that you can use bundler config.
bundle config build.mysql2 --with-mysql-config=/usr/local/Cellar/mysql/5.5.14/bin/mysql_config
Running bundle install
in your ruby app should now work.
Ruby gem mysql2 install error
Since this keeps coming up on google as on of the top results, I should point out that this answers is from almost 2 years ago. Here is a more updated answer: How to use "mysql2" gem in Rails 3 application on Windows 7?
According to the developer there is a already a reported bug for it and he is working on parting mysql2 over to Windows. As of now - it's still in the works. Use the older mysql driver for now - or use sqlite for local development.
This is from the googlegroups discussion
Blockquote
Hey Erwann,
There's a ticket on the mysql2 issue tracker for Win32 support already
at http://github.com/brianmario/mysql2/issues#issue/8 . You can follow
it for progress; I'm doing my best to get things working smoothly for
you guys. Hang tight! :)
Ruby on Rails 4.1.8 Gem::LoadError for mysql2 gem
I think I see what's going on. In your Dockerfile, change your DB_URL from: mysql:// to mysql2://
You are loading the mysql2 gem, but indicating to ActiveRecord that you want to use a connection via the mysql gem.
gem mysql2 instalation errors
You need to install mysql first, the log contains
mysql client is missing. You may need to 'apt-get install libmysqlclient-dev' or 'yum install mysql-devel', and try again.
The documentation page of the mysql2 gem contains:
This gem links against MySQL's libmysqlclient library or Connector/C library, and compatible alternatives such as MariaDB. You may need to install a package such as libmysqlclient-dev, mysql-devel, or other appropriate package for your system. See below for system-specific instructions.
By default, the mysql2 gem will try to find a copy of MySQL in this order:
* Option --with-mysql-dir, if provided (see below).
* Option --with-mysql-config, if provided (see below).
* Several typical paths for mysql_config (default for the majority of users).
* The directory /usr/local.
Try to install mysql or the mentioned libs and try again to install the gem.
The messages do not seem to reflect reality, try this instead of the mentioned package:
sudo apt-get install default-libmysqlclient-dev
Then, your next error clearly shows what is wrong
/home/pi/.rvm/gems/ruby-2.6.3/gems/execjs-2.7.0/lib/execjs/runtimes.rb:58:in `autodetect': Could not find a JavaScript runtime. See github.com/rails/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)
The GH page says:
ExecJS lets you run JavaScript code from Ruby. It automatically picks the best runtime available to evaluate your JavaScript program, then returns the result to you as a Ruby object.
Install one of the javascript runtimes, listed here in the readme, e.g. nodejs (https://nodejs.org/en/download/), therubyracer, etc.
Related Topics
Running Webrick Server in Background
Does Ruby Support Unicode and How Does It Work
Run a Cli Thor App Without Arguments or Task Name
How to Beautify Xml Code in Rails Application
Mail Gem - How to Clean Up the Body String
Dynamically Create Class Attributes with Attr_Accessor
How to Determine Leap Year in Ruby
What Are the Limitations of Opal
Set Default Stage with Capistrano 3
Breaking Ruby Module Across Several Files
Good Explanation of Ruby Object Model -- Mainly, 'Classes Are Objects'
Wicked-Pdf Not Showing Images, 'Wicked_Pdf_Image_Tag' Undefined
How Does Ruby Handle Bytes/Binary
Rails - Paperclip Validating Attachment Size When It Shouldn't Be
What Is the Most Elegant Way in Ruby to Remove a Parameter from a Url