Installing MySQL gem on Windows & cygwin for Rails
October 26th, 2008 by matt
This post assumes that you’ve followed the Setting up Rails on Windows with Cygwin guide and are using Cygwin on Windows for your Rails development.
If you’re upgrading to Rails 2.2 (or running on edge), you’ll need to build the mysql gem from source, as it’s being removed from the Rails pacakge. You’ll know if you need to do this if you get the following error when building your app:
!!! The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql.
Installing MySQL from source
First thing you’ll need to do is to download the source files from MySQL.
The next steps are all from the command line (and will probably take a while to complete!):
tar xzvf mysql-5.0.67.tar.gz cd mysql-5.0.57 ./configure make make install
UPDATE: As those who’ve commented here have noted, a common error you may come across while running make is:
readline/readline.h:70:29: sys/ttydefaults.h: No such file or directory
The easiest way to solve this issue is to download the readline packages from cygwin (using the cygwin installer) and running
./configure --without-readline CFLAGS=-O2
Instead of plain ./configure
Also note, if you’ve already run ./configure you’ll need to clean up the directory by running
make distcleanThis will actually install the entire MySQL library, but we won’t be using it. We just needed the library files to build the gem with. Once MySQL is built, you just need to install the gem, and you’re good to go:
gem install mysqlDon’t forget to tell MySQL which configuration we want to load. By default, it’ll try to use a local socket, but we want it to use the server we installed in Windows (outside of cygwin). Check out the Getting Cygwin/Rails to work with MySQL section of our previous guide.
Posted in Guides | comments (rss)
You can leave a response, or trackback from your own site.
Responses
Reuben on December 7th, 2008 at 2:17 am
Thanks for this little Howto Matt -it worked Awesome!
I tried a different approach previously, using information found Ruby Forum: http://www.ruby-forum.com/topic/160358#705485, but didn’t have much success, and it just was not a clean enough approach.
Now I now for sure that the Ruby Gem of MySQL is built using the same version of libraries that the native Windows binary installation MySQL 5.2.67 uses.
I’m getting together some very concise how-to articles and video tutorials together, and will definitely be linking back to those sites that have been most resourceful in providing information for building a solid Cygwin + RoR + Windows Vista development environment. Your articles found here will be included.
-Reuben :)+<
Setting up Rails on Windows with Cygwin | Phase Shift on January 8th, 2009 at 9:51 am
[...] Article « Ubuntu 8.04 LTS 64-bit Server on Linode Installing MySQL gem on Windows & cygwin for Rails [...]
Lonnon on January 14th, 2009 at 8:34 am
Thank you for taking the time to post these instructions. I’ve been tearing out my hair for days trying to get this work. Compiling the whole darn thing from source under Cygwin might be extreme (and it sure took a while on this slow laptop), but it works beautifully.
After compiling everything and installing the mysql gem, I did have to re-run MySQL’s Server Instance Configuration Wizard to get the mysql service up and running again; somehow in this process the service was stopped and removed. But after doing so, everything is happy again, including me.
As much as I adore the idea of using sqlite, I’d really prefer to use the same database for development that I’ll be using in production. I’m not expecting huge concurrency in my deployed application, but I expect enough that sqlite probably won’t cut it. Besides, I’m leery of sqlite’s limited subset of ALTER TABLE commands; it seems that the omission of things like DROP and ALTER COLUMN could cause real trouble when it comes to agile development of the database schema itself.
Joe The User on January 28th, 2009 at 12:43 am
“Thank you for taking the time to post these instructions. I’ve been tearing out my hair for days trying to get this work. Compiling the whole darn thing from source under Cygwin might be extreme (and it sure took a while on this slow laptop), but it works beautifully.”
It is extreme. I am sorry but even knowing how to do all the configuration stuff on linux, pseudo-unix-windows , I am not happy it.
I very much appreciate you telling me how this BS work but I don’t appreciate the Rails folks pulling the rug out from under me.
The folks who talk about how much better Linux is, they like pain. The average user, they don’t like pain. Well the pain-lovers, just screw them.
Alexis N. Mueller on March 24th, 2009 at 3:53 pm
I have a bit of a problem. I followed these instructions to the letter (except by now the versions are newer). I just can’t get mysql to compile in cygwin. I’ve got cygwin installed with a full install. I’ve got a Windows Installation of MySql Server up and running. I have Ruby and Rubygems working. I downloaded the source for mysql and untarred it as instructed. I’m using Ruby 1.8.7 and mysql 5.1.32.
Running
./configureseems to work as well. But when I runmake install, it starts the install but crashes out with the following error on installing libedit:Making install in libedit
make[2]: Entering directory `/cygdrive/c/Users/alex/mysql-5.1.32/cmd-line-utils/libedit’
gcc -DHAVE_CONFIG_H -I. -I../../include -I../../include -I../../include -O3 -MT readline.o -MD -MP -MF .deps/readline.Tpo -c -o readline.o readline.c
In file included from readline.c:54:
readline/readline.h:70:29: sys/ttydefaults.h: No such file or directory
make[2]: *** [readline.o] Error 1
make[2]: Leaving directory `/cygdrive/c/Users/alex/mysql-5.1.32/cmd-line-utils/libedit’
make[1]: *** [install-recursive] Error 1
make[1]: Leaving directory `/cygdrive/c/Users/alex/mysql-5.1.32/cmd-line-utils’
make: *** [install-recursive] Error 1
I’d love any pointers to get this to work. It seems without this, I wont be able to do
gem install mysqlwithout it complaining at me about libraries and such with the following error:Building native extensions. This could take a while…
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.
/usr/bin/ruby.exe extconf.rb install mysql
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
*** 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=/usr/bin/ruby
–with-mysql-config
–without-mysql-config
–with-mysql-dir
–without-mysql-dir
–with-mysql-include
–without-mysql-include=${mysql-dir}/include
–with-mysql-lib
–without-mysql-lib=${mysql-dir}/lib
–with-mysqlclientlib
–without-mysqlclientlib
–with-mlib
–without-mlib
–with-mysqlclientlib
–without-mysqlclientlib
–with-zlib
–without-zlib
–with-mysqlclientlib
–without-mysqlclientlib
–with-socketlib
–without-socketlib
–with-mysqlclientlib
–without-mysqlclientlib
–with-nsllib
–without-nsllib
–with-mysqlclientlib
–without-mysqlclientlib
Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/mysql-2.7 for inspection.
Results logged to /usr/lib/ruby/gems/1.8/gems/mysql-2.7/gem_make.out
Finally, I’ve also tried doing the following:
env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-dir=/cygdrive/c/Program Files/MySQL/MySQL Server 5.1 --with-mysql-lib=/cygdrive/c/Program Files/MySQL/MySQL Server 5.1/lib --with-mysql-include=/cygdrive/c/Program Files/MySQL/MySQL Server 5.1/includematt on March 24th, 2009 at 4:06 pm
Alexis, I’m not sure what could be going on there. I checked into libedit and it might be hiding out in cygwin as libreadline. I would check to make sure that the package libreadline6 is installed in your cygwin installation.
For reference, I’m using the mirror http://mirrors.dotsrc.org
Alexis N. Mueller on March 24th, 2009 at 4:47 pm
Yeah. libreadline5 and 6 are both installed. I started out first by only installing those items that I thought i needed in cygwin. No luck. Then I tried a full install, installing every package. No luck. Tried using the new cygwin beta. No luck. Tried using an older mysql src version (5.0.45). No luck.
At this point I’m almost inclined to use postgresql, except, I’d really prefer to stick with mysql so I don’t have to retool my production systems for full compliance.
Alexis N. Mueller on March 24th, 2009 at 4:55 pm
Oddly, when I try to compile mysql 5.0.45, the error is as follows:
Making install in libedit
make[3]: Entering directory `/cygdrive/c/Users/alex/mysql-5.0.45/cmd-line-utils/libedit’
if gcc -DUNDEF_THREADS_HACK -DHAVE_CONFIG_H -DNO_KILL_INTR -I. -I. -I../.. -I../../include -I../../include -I./../.. -I.. -O3 -DDBUG_OFF -MT unvis.o -MD -MP -MF “.deps/unvis.Tpo” -c -o unvis.o `test -f ‘np/unvis.c’ || echo ‘./’`np/unvis.c; \
then mv -f “.deps/unvis.Tpo” “.deps/unvis.Po”; else rm -f “.deps/unvis.Tpo”; exit
1; fi
np/unvis.c:81: error: parse error before “int”
np/unvis.c:86: error: parse error before ‘{‘ token
make[3]: *** [unvis.o] Error 1
make[3]: Leaving directory `/cygdrive/c/Users/alex/mysql-5.0.45/cmd-line-utils/libedit’
make[2]: *** [install-recursive] Error 1
make[2]: Leaving directory `/cygdrive/c/Users/alex/mysql-5.0.45/cmd-line-utils’
make[1]: *** [install-recursive] Error 1
make[1]: Leaving directory `/cygdrive/c/Users/alex/mysql-5.0.45′
make: *** [install] Error 2
Wonder if that helps. Should I try blowing away cygwin one more time and going back to the non-beta with just the packages I need? Maybe it’s some compiler conflict?
Alexis N. Mueller on March 24th, 2009 at 5:44 pm
Ok sorry to fill up these comments. So after your comment about checking whether the libedit (and readline) packages were installed in Cygwin, I went and checked. Both were there. So, I decided to put my thinking cap on and do the
configureas follows:./configure –without-libedit
The install appears to be chugging along. I guess the lesson is, for purposes of a dummy mysql compile to run
gem install mysql, if the compile crashes, just exclude that package from the configuration.I’ll let you know if that works. Thanks again for your help.
Alexis N. Mueller on March 25th, 2009 at 10:09 am
Funny enough, doing the configure with the exclusions made the install get a lot further. It ultimately still crashed out in the ‘client’ directory. However, apparently it got far enough to install enough of the headers and libraries to allow me to do
gem install mysqland I am now up and running. Thanks again for your help. Feel free to prune these comments as necessary.drub on March 28th, 2009 at 5:58 pm
I’m having the same experience.
Compiled to mysqlclient successfully. This still does not allow a successful “gem install mysql”. What else was required to make the gem install work?
Did you copy .so files somewhere?
Did you copy .h files somewhere?
Many thanks!
daren on March 30th, 2009 at 10:09 pm
I couldn’t find a cygwin package containing /usr/include/sys/ttydefaults.h so I copied the file from my cent0S box and it built without errors.
luke on April 8th, 2009 at 3:45 am
Thanks a lot, Alexis, I went through the same difficulties you described. And thanks to your comments I was able to finally install gem mysql :-)
mads on June 10th, 2009 at 7:07 am
./configure –without-libedit –without-readline –without-server CFLAGS=-O2
worked flawlessly on cygwin with make/gcc/readline installed (not libreadline, that’s a dependency anyway; I mean readline under Devel). This was MySQL 5.1.35.
This is unrelated to Rails, I needed the mysql-client to install MySQLdb on cygwin, but it’s the same issue.
Shahin Kordasti on July 15th, 2009 at 8:17 am
Uhm useful guide I guess but I had to run make before running make install or the gem command would fail. Would be nice if that had been mentioned as it took me hours to figure out why it didnt work :/
roger rubygems on August 13th, 2009 at 10:46 am
Note also that you can install libmysql-devel from cygwin ports and then it will also work.
See http://betterlogic.com/roger/?p=1829
roger rubygems on August 13th, 2009 at 10:49 am
also you need to have installed the gcc package for cygwin [a gotcha for me] so that compilation of the mysql gem works
ssaidwho on December 8th, 2009 at 2:12 pm
I had errors similar to Alexis, but his fixes didn’t work for me. Daren’s suggestion to copy the file from another system did the trick for me:
cp ttydefaults.h /usr/include/sys/
then I ran configure without arguments and make install.
I didn’t try copying from this source, but its probably the same file: http://opensource.apple.com/source/xnu/xnu-1456.1.26/bsd/sys/ttydefaults.h
I checked out the betterlogic solution but couldn’t find the mysql development package in the recommended location
Rafael on February 17th, 2010 at 8:05 pm
guys, i had the same problem with the recursive errors on make install. first, i recommend running make first and then make install. second, you have two options to resolve. one is to get ttydefaults.h and put it in your system directory (as noted above). the other is to install readline from cygwin so that you can do:
./configure –without readline CFLAG=-02″
See here for more help:
http://bugs.mysql.com/bug.php?id=45057
i would also like to thank the author for showing us the way to get this up and running.
matt on February 25th, 2010 at 7:46 pm
Guys, thanks for the helpful comments. I’ve updated this post with the new information.
Pete on July 29th, 2010 at 11:04 am
I couldn’t get the latest versions of mysql to compile at all on cygwin. Using the version listed on this page works, but the link is dead…Use this one instead.
Also, don’t put the mysql source in a path with spaces, because that’ll cause problems too.