Mysql Not Installing - Trying to Use it with RoR - mysql

I'm following the guides in a Lynda program teaching Ruby on Rails.
The guy suggests using mysql instead of using the default mysqlite3.
I ran this:
rails new simple_cms -d mysql
and this is part of the error
An error occured while installing mysql2 (0.3.11), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.11'` succeeds before bundling.

There are many people asking this question already.
If you are using linux,
sudo apt-get install libmysqlclient-dev
If you are using mac, use homebrew
brew install mysql
then run gem install mysql2

Related

Mysql2 error in starting rails server in mac m1

I have installed mysql2 in mac m1 using the below command
gem uninstall mysql2
gem install mysql2 -v '0.3.21' -- --srcdir=/usr/local/Cellar/mysql/8.0.28_1/bin/include --with-mysql-include=/usr/local/Cellar/mysql/8.0.28_1/include/mysql --with-mysql-lib=/usr/local/Cellar/mysql/8.0.28_1/lib --with-cppflags=-I/usr/local/opt/openssl#1.0/include --with-opt-dir=/usr/local/opt/openssl#1.0 --platform=ruby
Installation works but when I starts rails s , I get the below error
/gems/mysql2-0.3.21/lib/mysql2.rb:31:in `require': cannot load such file -- mysql2/mysql2 (LoadError)
I am using Rails 3.2.22.5 and ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin21]
I downgraded the openssl to 1.0 to install ruby 2.3.0 using rosetta
I already installed mysql8 using brew install mysql .
Above is working in my another project which is running on Rails 4.2 and Ruby 2.3.1 but dont know why its not working here.
I also tried to downgrade mysql8 to 5.7 and then install mysql2 using the below
gem install mysql2 -v 0.3.21 -- --with-mysql-config=/usr/local/Cellar/mysql#5.7/5.7.37/bin/mysql_config --srcdir=/usr/local/Cellar/mysql#5.7/5.7.37/bin/include --with-ldflags=-L/usr/local/opt/mysql#5.7/lib --with-cppflags=-I/usr/local/opt/mysql#5.7/include --platform=ruby
But same error, installation complete but getting load error in rails s
Any help to fix this error will be appreciated.
I am able to solve this issue by downgrading mysql to 5.7 and then installing mysql-client#5.7
Below are the steps:
#stop mysql
brew services stop mysql
# install mysql5.7
brew install mysql#5.7
#Link mysql5.7
brew unlink mysql
brew link mysql#5.7 --force
# install mysqlclient
brew install mysql-client#5.7
#uninstall old mysql versions if already installed
gem uninstall mysql2
#install mysql2
gem install mysql2 -v 0.3.21 -- --with-mysql-config=/usr/local/bin/mysql_config --with-ldflags=-L/usr/local/Cellar/openssl#1.0/1.0.2u/lib --with-cppflags=-I/usr/local/Cellar/openssl#1.0/1.0.2u/include
Try this way, it's work for me
brew install openssl zstd mysql
LIBRARY_PATH=$(brew --prefix zstd)/lib/:$(brew --prefix openssl)/lib/ gem install mysql2

How to use MySQL in Rails with XAMPP in Ubuntu 16.04

I have XAMPP and use it to develop my PHP projects. I have also Ruby on Rails on my system, and I want to use MySQL from my XAMPP stack in my Rails projects. I installed the mysql2 gem:
sudo gem install mysql2 -- --with-mysql-config="/opt/lampp/bin/" --with-mysql-include="/opt/lampp/include/" --with-mysql-lib="/opt/lampp/lib/mysql/"
Also, I tried:
bundle update mysql2 -- --with-mysql-config="/opt/lampp/bin/" --with-mysql-include="/opt/lampp/include/" --with-mysql-lib="/opt/lampp/lib/mysql/"
But in both the cases I got the following error when I ran rails s:
/home/sanjib/.rubies/ruby-2.3.0/bin/ruby: symbol lookup error: /home/sanjib/.gem/ruby/2.3.0/gems/mysql2-0.4.5/lib/mysql2/mysql2.so: undefined symbol: mysql_server_init
First install ruby, ruby on rails and XAMPP. Then, type in your terminal...
sudo apt-get update
sudo apt-get install mysql-client libmysqlclient-dev
gem install mysql2
Before create proyect, create the follow databases in phpmyadmin
appname_development
appname_test
appname_production
Lastly, to create your proyect... type this in your terminal:
rails new appname -d mysql
Reference:How To Use MySQL with Your Ruby on Rails Application on Ubuntu 14.04

mysql2 gem hangs during installation

I'm using mysql as the database for a rails app and trying to bundle install the mysql2 gem. During the step
Installing mysql2 0.3.19 with native extensions
rather than failing and giving me an error message, it simply hangs and never gives any output at all.
For background I'm installing on a fresh digital ocean droplet that comes with rails installed on Ubuntu 14.04, using ruby 2.0.0 and without specifying a version for the mysql2 gem.
It looks like I had the wrong version of mysql installed. Uninstalling all versions of mysql and then running
sudo apt-get install mysql-client libmysqlclient-dev
worked for me.

gem install mysql2 -v '0.3.18' fails

I'm using OS X 10.9.5. Recently updated ruby to 2.2.1 and it messed up everything in my system. I'm having a hard time with this. I'm trying to do a bundle install on my project and it fails saying
Make sure that gem install mysql2 -v '0.3.18' succeeds before bundling
I was going through the same issue yesterday. All I did was to uninstall mysql and reinstall it, then re install mysql2 and it worked. I', trying the same thing now but it wouldn't let me install mysql2.
I tried,
gem install mysql2 'gem install mysql2 -v '0.3.18'
Also Tried,
gem install mysql2 -v '0.3.18' -- --with-mysql-dir=/usr/local/bin/mysql
It gives me the following error,
LInk to the error.
I'm thinking if this could be a gcc issue. when I run which gcc it gives me gcc: aliased to /usr/local/bin/cpp-4.8. could this be the reason?
can anyone guide me in fixing this? thanks in advance
I got the same errors when I deploy my app to VPS(Ubuntu 14.04)
What I did to make it out is
sudo apt-get install libmysqlclient-dev
Not sure for OS X , but hope this can help you.

gem install mysql failure in Snow Leopard

I successfully installed MySql x86_64 in Snow Leopard and Ruby and Ruby Gems seems to be installed properly:
$ which mysql
/usr/local/mysql/bin/mysql
$ which ruby
/usr/bin/ruby
$ which gem
/usr/bin/gem
$ mysql
Your MySQL connection id is 404
Server version: 5.1.37 MySQL Community Server (GPL)
$ ruby -v
ruby 1.8.7 (2008-08-11 patchlevel 72) [universal-darwin10.0]
$ gem -v
1.3.5
Unfortunatly I get an error installing mysql gem:
$ sudo gem update --system
...
$ sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
Building native extensions. This could take a while...
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb --with-mysql-config=/usr/local/mysql/bin/mysql_config
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ruby.h
Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/mysql-2.8.1 for inspection.
I think you should try to uninstall the old mysql gem first before recompiling
sudo gem uninstall mysql
sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
Installing the Xcode that's bundled with the Snow Leopard fixed the problem.
For me, it was adding the UNIX Tools option (if I recalled the name accurately), which include the headers. When I installed XCode originally, I didn't include this component because I didn't think that I would be writing UNIX code. Little did I know...
If you've installed MySQL 5 using MacPorts, then use the command:
sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/opt/local/bin/mysql_config5
I had this problem when I updated to Lion. In this case, I when to the app store and downloaded the latest Xcode. Then I uninstalled and reinstalled the database.
The issue had to do with a broken link during the update. Ruby likes to be in /System while Apple places ruby in /Developer.
was stuck with same problem:
Tried most of the solution's: At the end
Edit the app/config/database.yml, change the adapter to mysql2
production:
adapter: mysql2
database: commissi_production
username: root
password: root
host: localhost
& run on terminal
gem install activerecord-mysql2-adapter
Solved the problem.