Mysql2 error in starting rails server in mac m1 - mysql

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

Related

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

Mysql Not Installing - Trying to Use it with RoR

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

How to install MySQL gem on Mac OS X

What do I need to install mysql gem on Mac OS X ? I'm getting error "failed to build native extensions".
Install MySQL first, either by using binary or Homebrew.
Then:
gem install mysql2
Or:
gem install ruby-mysql
Just pick one and you are good to go.
Edit
In case you upgraded to MySQL version 5.6.12 on OS X, mysql2 will fail to compile. Solution is to downgrade MySQL as described here: https://stackoverflow.com/a/17252887/45254
Edit2
In case you don't want to have mysql installed (maybe you use docker to manage your services) but do want to use mysql2 gem, you can instead install mysql-connector-c (using homebrew).
Some time back I wrote some instructions on my blog on how to do it in 10.6, but I think it's the same in 10.5.
I comes down to this command:
ARCHFLAGS="-arch x86_64" gem install mysql -- \
--with-mysql-config=/path/to/mysql_config
but you need to find the real value for /path/to/mysql_config. My blog post has a few tips, but there's one very important thing: you must have installed MySQL with headers. The official .pkg installer from MySQL doesn't IIRC. The best thing to do is to install MySQL with Homebrew (in the post I use examples from a MacPorts install, but that's because Homebrew wasn't mature when I wrote it).
If you install MySQL with Homebrew mysql_config will be located at /usr/local/bin/mysql_config and if you install it with MacPorts it will be at /opt/local/lib/mysql5/bin/mysql_config.
I concur with the other answer that suggest that you install the mysql2 gem instead of mysql. I think the command above should work for mysql2 too.
if you already have MySQL server running elsewhere on the network and would like to still install the gem without having to install MySQL try the following
brew install mysql-connector-c
followed by
gem install mysql
I'm running Mac OS X Lion with Homebrew.
The correct command to install a ruby gem is…
gem install mysql -- \ --with-mysql-config=/usr/local/bin/mysql_config
I'm using Mac OS X Mountain Lion, and installed MySQL with DMG.
gem install do_mysql -- \ --with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib --with-mysql-include=/usr/local/mysql/include
and
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
This works for me ;)
For me it did the most easy:
brew install mysql
gem install mysql
Brew is a package manager for Mac OS, a must have. Using it to install mysql first brings everything that the gem command is missing.
I'm using Mac OS X 10.10 (Yosemite), and to me worked with the command bellow:
gem install mysql2 -- \ --with-mysql-config=/usr/local/mysql/bin/mysql_config
I installed MySQL with Homebrew and I had to use this to finally be able to upgrade the gem:
gem install mysql2 -- --with-mysql-dir=/usr/local/opt/mysql/
I install MySQL with DWG mysql_config will be located at /usr/local/mysql/bin/mysql_config
gem install mysql -- \ --with mysql-config=/usr/local/mysql/bin/mysql_config
I came across this issue while setting up MySQL gem on MacOs Mojave .This worked for me
1 Ensure Xcode command line tools are installed.
xcode-select --install
For me the build was still failing with some header files missing which you have to install
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
This link pointed to right direction. Can't compile C program on a Mac after upgrade to Mojave

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.

gem install mysql problem in rails

Im getting an error with a rails app.
The bundled mysql.rb driver has been
removed from Rails 2.2. Please install
the mysql gem and try again: gem
install mysql.
And when i try to do gem install mysql it still doesnt work and im getting this error.
WARNING: Installing to ~/.gem since
/Library/Ruby/Gems/1.8 and /usr/bin
aren't both writable. WARNING: You
don't have
/Users/bartligthart/.gem/ruby/1.8/bin
in your PATH, gem executables will
not run.
I also tried this but it didn't work
sudo gem install mysql −− −−with−mysql−config≡/usr/local/mysql/bin/mysql_config
what could i do to install mysql?
you need to install this first:
apt-get install libmysqlclient-dev
Did you install the MySQL db server? If so, does this file actually exist?:
/usr/local/mysql/bin/mysql_config
If mysql isn't installed, install that first. Then make sure that the mysql_config script you point to is actually there.
What worked for me is adding this to ~/.bash_profile:
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/
After installing the MySQL gem like this (64 bit version on an Intel osx 10.6):
export ARCHFLAGS="-arch x86_64" ; sudo gem install --no-rdoc --no-ri mysql -v 2.7 -- --with-mysql-dir=/usr/local --with-mysql-config=/usr/local/mysql/bin/mysql_config
Try
sudo gem update --include-dependencies
sudo gem install mysql
sudo apt-get install libsqlite3-dev
sudo gem install sqlite3-ruby
This article helped me at the time:
http://craiccomputing.blogspot.com/2008/11/installing-rails-22-on-mac-os-x-mysql.html
To fix that, add "gem: --no-user-install" in your ~/.gemrc file
via