Missing MySQL client - mysql

So I was following along with this tutorial:
https://www.youtube.com/watch?v=MX6wYbsUO-Y
It uses git.bash to install the mysql2 gem, and I'm stuck on the final step. The process he uses won't work for me, so instead, i just type:
gem install mysql2 -s http://rubygems.org
After this, it begins to work, but then it says the mysql client is missing:
gem install mysql2-0.3.7.gem --platform=ruby -- --with-mysql-dir=X: --with-mysql-lib=X:\lib
ERROR: Failed to build gem native extension.
c:/RailsInstaller/Ruby2.1.0/bin/ruby.exe extconf.rb
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
checking for mysql_query() in -lmysqlclient... no
-----
mysql client is missing. Check your installation of MySQL or Connector/C, and try again.
-----
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
I am very new to using mysql, and I don't even know where to begin, if anything, could anyone simply direct me to a resource where I could figure it out myself?

First of all please provide the version numbers when you are asking specific platform related questions
This is a 2 year old question but the problem still exists when starting ruby on windows
here are some steps needed to solve it ( as of aug 2017)
Please install Devkit and MSYS(now comes with ruby installer)
when installing mysql2 gem check if the version supplied from the rubygem repo is actually for your architecture and ruby version e.g. mysql2 0.4.9 does not provide compiled version for windows for ruby 2.4
if it is not provided then you need to compile it
3.a. First download the Mysql c connector from here the zip version is better
https://dev.mysql.com/downloads/connector/c/
important please keep in mind of your os architecture for example you must download 64 bit if you want to run it on 64 bit machine
3.b. Second extract it somewhere and the run this command
gem install mysql2 --platform=ruby -- '--with-mysql-lib="[your_full_path_to_extracted_mysql_connector]\lib" --with-mysql-include="[your_full_path_to_extracted_mysql_connector]\include"'
please keep in mind of the ' at the end it is important
It should say 1 gem installed
Check your connection using this command
rails db:schema:dump inside your project root directory. you will see a
new file in the db folder named schema.rb it means that it is working.
You will see specific problems displayed in the console, if any search it in the google you will find answers.
good luck :)

You need to download and install MySQL first.
If it's still not able to be found after you've installed it, supply the path on gem install.

Related

Ruby On Rails, MySQL windows 8.1 64bit mysql gem frustrating

(as an aside its telling me I have code in here and have to format it as such, so if anything looks strange its because it wouldn't let me post it otherwise.)
I've actually reinstalled windows 8 three times in the last two days and actually created a dual boot with Ubuntu with how frustrating this problem has been. (decided learning a whole new operating system was more annoying then trying to fix the windows problem)
So, i'm new to coding in general, but I've been fooling around with ruby and rails and decided to try and get the database stuff working and every time I run into the same sorts of problems, this seems to be some sort of windows 64 bit MySQL ruby version confusion.
I'm using windows 6.1 64 with ruby 2.0.0p353 (2013-11-22) [x64-mingw32] rails 4.0.2 with MySQL 5.6
I've installed the devkit and did the test using ruby -rubygems -e "require 'json'; puts JSON.load('[42]').inspect" and it returned 42 and that whole installation seemed to go fine.
rails installed ruby installed, all -v showing the version I listed.
now when I go to install MySQL gem it gives me this.
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.
C:/Ruby200-x64/bin/ruby.exe extconf.rb
checking for main() in -llibmysql... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
I read up and tried doing this after installing the MySQL c connector. And it returns as follows.
C:\Users\ryan>gem install mysql2 --platform=ruby -- '--with-mysql-dir="C:/mysql-
connector-c-6.1.3-win32/"'
Temporarily enhancing PATH to include DevKit...
Building native extensions with: '--with-mysql-dir="C:/mysql-connector-c-6.1.3-w
in32/"'
This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
C:/Ruby200-x64/bin/ruby.exe extconf.rb --with-mysql-dir="C:/mysql-connector-
c-6.1.3-win32/"
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
-----
Cannot find include dir at C:/mysql-connector-c-6.1.3-win32//include
-----
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
I have devoted days to this problem, and reinstalled more things than I care to admit. Does anyone have any ideas how I could possibly fix this... ?
ok this is what its spitting out now..
C:\Users\ryan>gem install mysql --platform=ruby -- --with-mysql-dir=c:\mysql-con
nector-c-6.1.3-win32
Temporarily enhancing PATH to include DevKit...
Building native extensions with: '--with-mysql-dir=c:\mysql-connector-c-6.1.3-wi
n32'
This could take a while...
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.
C:/Ruby200-x64/bin/ruby.exe extconf.rb --with-mysql-dir=c:\mysql-connector-c
-6.1.3-win32
checking for main() in -llibmysql... no
* extconf.rb failed *
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=C:/Ruby200-x64/bin/ruby
--with-mysql-dir
--with-mysql-include
--without-mysql-include=${mysql-dir}/include
--with-mysql-lib
--without-mysql-lib=${mysql-dir}/
--with-libmysqllib
--without-libmysqllib
Gem files will remain installed in C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/mysql
-2.9.1 for inspection.
Results logged to C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/mysql-2.9.1/ext/mysql_
api/gem_make.out
gave up and installed windows 7 32 bit on a second harddrive and just use that for rails stuff.
Set that up using an amazing video on youtube I randomly found, but it worked perfectly.
https://www.youtube.com/watch?feature=player_embedded&v=-eFwV8lRu1w
no joke I was close to giving up! It seems like lots of rails problems are oriented around 64 bit windows anyway, but 8.1 can't be helping anything.
It's almost a silly answer to say just give up, and i'm sure its possible to get the most recent version of rails and ruby working on windows 8.1 64 right at this moment, but I think with the effort required it is actually easier for a new person to just install a 32 bit version of, preferably, an earlier version of windows.
I had faced same issue.
You can find solution here.
http://blog.mmediasys.com/2011/07/07/installing-mysql-on-windows-7-x64-and-using-ruby-with-it/
Here in the blog a invalid path for mysql-connector-c-noinstall-6.0.2-win32
gem install mysql --platform=ruby -- --with-mysql-dir=C:/mysql-connector-c-noinstall-6.0.2-win32
So for this you have to check your folder structure for mysql-connector then use it.
Thanks

Where does Ruby's have_header method look for header files?

On a CentOS 5.7 box, I'm having trouble installing the newest version of the mysql2 gem; it's not finding errmsg.h:
/usr/bin/ruby extconf.rb
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... no
checking for mysql_query() in -lmysqlclient... yes
checking for mysql.h... no
checking for mysql/mysql.h... yes
checking for errmsg.h... no
-----
errmsg.h is missing. please check your installation of mysql and try again.
-----
*** extconf.rb failed ***
The mysql header files exist at /usr/include/mysql. An older version of the gem exists on the server, so it must have been built successfully at one point.
Note that it fails on a check for mysql.h, but succeeds on mysql/mysql.h. However, it doesn't repeat this for errmsg.h. By this I'm guessing that it's not looking at /usr/include, but I'm not sure.
I've dug into the extconf.rb source code and discovered that it's using the have_header method to locate the header files. I debugged the execution to find out that it's looking for a relative path of "mysql/errmsg.h". But I haven't found any documentation that explains how it expands that into an absolute path.
Where & how does have_header locate its header files?
I believe I've found an answer.
It appears that have_header looks at the system include path. If the relevant environment variables are not set, the default include paths are /usr/local/include and /usr/include.
If you want to set them manually, you would do something like:
export C_INCLUDE_PATH=/usr/include/mysql/
That's true even if you're compiling a C++ program, if the header file is a C file. If, on the other hand, your header file is C++, not C, you would do:
export CPLUS_INCLUDE_PATH=/usr/include/mysql
Of course, you found the work-around, which is to include dir_config('mysql') in your extconf.rb. That enables you to use the --with-mysql-include option and supply the path manually.
Here's my source: http://www.network-theory.co.uk/docs/gccintro/gccintro_23.html
And here's a more general version of the same question (with answers): How to add a default include path for gcc in linux?

Ruby mysql2 gem, cannot build on Windows 7

I come from OSX where Ruby runs super flawlessly 90% of the time. I haven't touched it in awhile though and happen to be working on a Windows 7 machine right now. I'm trying to run a simple Ruby on Rails project but I can't seem to get past any of my database setup.
I want to run on mysql but when I try to install the mysql2 gem (via bundle install or gem install mysql2) I get these errors:
Installing mysql2 (0.2.9) with native
extensions
C:/Ruby192/lib/ruby/site_ruby/1
.9.1/rubygems/installer.rb:533:in
`rescue in block in build_extensions':
ERROR: Failed to build gem native
extension.
(Gem::Installer::ExtensionBuildError)
C:/Ruby192/bin/ruby.exe extconf.rb checking for
rb_thread_blocking_region()... *
extconf.rb failed * Could not create
Makefile due to some reason, probably
lack of necessary libraries and/or
headers. Check the mkmf.log file for
more details. You may need
configuration options.
I'm pretty much a complete newb when it comes to this kind of thing so if anyone has any advice, please help!
To install and compile extensions sometimes you need libraries and headers of the dependencies. In this case, you need MySQL headers and libraries to properly compile.
Assuming you downloaded Ruby from RubyInstaller and also installed the Development Kit and followed it's installation instructions, to successfuly install mysql2 gem I recommend you read this answer in our Troubleshooting page:
Download MySQL Connector/C
Extract into a path without spaces
When installing mysql2 gem, provide the additional options (gem install mysql2 -v 0.2.10 -- --with-mysql-include=... --with-mysql-lib...)
Provide for --with-mysql-include option the path to the include directory of MySQL Connector/C. The same for --with-mysql-lib but this time point to lib directory.
Don't forget to copy libmysql.dll to your Ruby bin directory.
Hope this helps.
The problem with native extensions on Windows is that there are two different compiler infrastructures: one based on MS VC and its Visual Studio and one based on MinGW (Minimalist GCC for Windows).
There are Ruby native extensions that can be compiled with any of them and other, that only support one. And since most of them come from some kind of Unix, chances are that mingw works better that MSVC.
So you may try to install mingw and use it to compile mysql gem - there is a special package called devkit, which contains a minimal necessary mingw installation which you just put inside your ruby installation.
I had a success compiling several native extensions using devkit: eventmachine, linecache, bson-ext to name a few. And within devkit you will feel much more are home :-) (coming from OSX)
If you have the devkit setup correct as #Tomasz mentions, please make sure you check the compatibility of mysql2 gem version with windows, I have experienced in the past for it to cause issues and had to go and install a previous version to get it working. Last I remember v0.2.6 was the version that supported windows.

Where are WAMP's MySQL "lib" and "include" directories?

I have provide the path to MySQL's lib and include directories as described in step #10 here.
However, I can't find these directories in my WAMP installation on Windows 7 (32-bits).
I tried to point to the bin directory:
gem install mysql2 --
'--with-mysql-lib="c:\wamp\bin\mysql\mysql5.5.8\bin"
--with-mysql-include="c:\wamp\bin\mysql\mysql5.5.8\bin"'
but it doesn't work:
...
checking for rb_thread_blocking_region()... yes
checking for main() in -llibmysql... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
...
Please advise.
Here's what worked for me:
gem install mysql2 -- '--with-mysql-dir="C:\wamp\bin\mysql\mysql5.5.xx"'
Been searching for a few hours and not seen this variation suggested, so hopefully it will help someone!
Change the directory location to point both to the bin directory both dll's are in there.
I.E.:
gem install mysql2 -- '--with-mysql-lib="c:\wamp\bin\mysql5.1.xx\bin" --with-mysql-include="c:\wamp\bin\mysql5.1.xx\bin"'
that should work. just change the version file with the correct version.

mysql gem install fails on snow leopard. My computer is 32bit (mac mini core duo)

My end goal is local development of a Radiant CMS installation. So, need rails and a db to play nice. Previous frustrations with mysql led me to try mamp. I have installed MAMP. It is working. I am open to other avenues though.
Tried to install the mysql gem but got no love.
john-breedloves-mac-mini-2:~ john_breedlove$ sudo gem install mysqlPassword:
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
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lmygcc... no
checking for mysql_query() in -lmysqlclient... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Provided configuration options:
<Omitted>
Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/mysql-2.8.1 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/mysql-2.8.1/ext/mysql_api/gem_make.out
I have found a lot of advice about installing gems after upgrading to snow leopard but all the good answers seem to point people to getting the 64bit version of mysql installed. I have a 32bit processor.
I have xcode installed.
How do I get this gem installed?
Have you installed mysql on the machine ?
That's the first thing you must do.
Then the problem with Mac OS is that it doesn't install things at the same standard emplacement than on linux. So you must specify the mysql directory.
With macports mysql, I do the following :
sudo gem install mysql --with-mysql-include=/opt/local/include/mysql5 --with-mysql-lib=/opt/local/lib/mysql5 --with-mysql-config=/opt/local/lib/mysql5/bin/mysql_config
Short story is you are going to need to compile mysql by hand to get the libraries you need.
By the time you do that, you might not need mamp :P I just kick off mysql manually, and use the dev environment.
http://hivelogic.com/articles/compiling-mysql-on-snow-leopard/
Edit: Just noticed you found Hivelogic. That is the way to go. Once it is compiled, you can't point the mysql gem in the correct direction per the instructions. Also, I believe getting the docs working for the gem is a whole other headache, i would just let it slide.
If you installed mysql through homebrew you might use this:
sudo gem install mysql -- --with-mysql-include=/usr/local/include/mysql --with-mysql-lib=/usr/local/lib/mysql
The '--' is helpful when adding additional configuration parameters.
With bundler you should do something like so:
# bundle config build.mysql --with-mysql-config=/usr/local/bin/mysql_config
# bundle install