I try to run gem 'thinking-sphinx' on my Ruby on Rails project, but something was wrong. When I run any search command on any model, I see this error: ThinkingSphinx::SphinxError (Unknown MySQL error).
More details:
MacOS Mojave -v 10.14.3
mysql -v 8.0.15 (Installed first)
Sphinx -v 2.2.11_2 (Installed via 'brew install sphinx')
thinking-sphinx -v 4.2.0
Rails -v 5.2.2
Before run search command, I runned rails ts:index and rails ts:start
What am I doing wrong?
Sphinx v2.2 (and 3.0) is not compatible with MySQL v8. You'll either want to downgrade MySQL to 5.7 - which can be done with homebrew via brew install mysql#5.7 - and then uninstall and reinstall Sphinx, or download the binaries for Sphinx v3.1.1 (the first version to support MySQL v8) from the Sphinx website (the source code for that release is not currently available, hence it's not installable via homebrew).
Just changed mysql2 from gem "mysql2", '~> 0.4.6' to gem "mysql2", '0.4.10' version, and it worked for me. Thanks
I'm trying to install rails and its giving me a headache, I can't seem to get it working. I'm using osx 10.5 and I used macports to get rub,rails and ruby gems installed in opt/local/bin but mysql is getting frustrating, I have it working in a mamp directory, I also tried installing it via the dmg, which works but the profile won't work everytime I try to load it it says "Could not load mysql preference pane" and if I try in terminal type which mysql I get: /usr/local/mysql/bin/mysql but if I try to check the version I get :
mysql -version
dyld: unknown required load command 0x80000022
Trace/BPT trap
I'm trying to launch webrick inside a rails app i've created but when I run "rails server" I get the error:
Could not find gem 'mysql2 (>= 0)' in any of the gem sources listed in your Gemfile.
I have no idea whats going on
Isn't there an easy way to install rails like MAMP?
UPDATE:
ok I got mysql installed, apprently there is a bug with the latest version causing a problem with the preference pane. mysql is installed in
/usr/local/mysql/bin/mysql
2 questions I have about this. Is this the right path should it not be in /usr/local/mysql ?
and the second is how would I link this to my ruby gem? is this right:
sudo gem install mysql -- --with-mysql-dir=/usr/local/mysql
or
sudo gem install mysql -- --with-mysql-dir=/usr/local/mysql/bin/mysql
I suggest you use HomeBrew to install mysql or ruby instead of MacPorts.
Could not find gem 'mysql2 (>= 0)' in any of the gem sources listed in your Gemfile.
This error is caused because rails requires the mysql2 gem to connect to mysql. All you have to do in include
gem mysql2
to the gemfile in the root directory of the rails app and do a bundle install
If you just trying out rails then you might as well use the default sqlite3 database forget about mysql.
The installation path is correct.
Installing the mysql gem is slightly more complicated than necessary since the installation automatically tries generating both 32bit and 64bit versions.
Assuming you have installed the 64 bit binary package, try the following (from the bash command line):
ARCHFLAGS="-arch x86_64" gem install mysql2 -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
However, it is recommended that you do not mess with the OSX ruby installation and use rvm (The Ruby Version Manager) to create a customized ruby environment. You can find a good tutorial for Rails and RVM here.
I am trying to get the mysql gem to work ... and it just doesn't want to. Every time I do a rake db:migrate, I get
uninitialized constant MysqlCompat::MysqlRes
I've installed mysql from this disk image: mysql-5.5.9-osx10.6-x86_64.dmg
I've run the gem install with the infamous archflags setting:
sudo env ARCHFLAGS="-arch x86_64" gem install --no-rdoc --no-ri mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
And the ruby version I'm using is the default from Snow Leopard:
[~/sites/testdb]$ file `which mysql`
/usr/local/mysql/bin/mysql: Mach-O 64-bit executable x86_64
[~/sites/testdb]$ file `which ruby`
/usr/bin/ruby: Mach-O universal binary with 3 architectures
/usr/bin/ruby (for architecture x86_64): Mach-O 64-bit executable x86_64
/usr/bin/ruby (for architecture i386): Mach-O executable i386
/usr/bin/ruby (for architecture ppc7400): Mach-O executable ppc
My database.yml is pretty simple:
development:
adapter: mysql
host: 127.0.0.1
database: testdb
username: root
password:
Any help would be appreciated.
You can easy fix your problem.
If you don't use rvm:
sudo install_name_tool -change libmysqlclient.16.dylib /usr/local/mysql/lib/libmysqlclient.16.dylib /Library/Ruby/Gems/1.8/gems/mysql-2.8.1/lib/mysql_api.bundleruby
If you use rvm:
install_name_tool -change libmysqlclient.16.dylib usr/local/mysql/lib/libmysqlclient.16.dylib [YOUR_GEMSET_PATH]/gems/mysql-2.8.1/lib/mysql_api.bundle
I blogged about this last week: MySQL 5.5 on Mac OS X.
My alternate solution to using install_name_tool is to set DYLD_LIBRARY_PATH in your shell startup files. The advantage to this you do it once, whereas if you use install_name_tool, you will repeat that every time to re-install or upgrade the gem.
The mysql2 gem will have the same problem with a slightly different error message. The problem is how the libmysqlclient library is built. It doesn't include a full path, so anything linking with it can't find it at runtime.
I ran into the same error. On my machine, though, the mysql gen was built when I still had mysql 5.1 on my machine. Now, after upgrading to MySQL 5.5, the dyld-file referred by the original build /usr/local/mysql/lib/libmysqlclient.16.dylib didn't exist any more and was replaced by a file /usr/local/mysql/lib/libmysqlclient.18.dylib.
Completely rebuilding the mysql gem fixed things, i.e.
gem uninstall mysql
gem install mysql
You could try using the mysql2 gem which may not suffer from the same problems.
I've found it's often a lot better to use ruby and mysql from MacPorts or brew to keep everything on the same page and not mess with the system Ruby.
OS X comes with a version of MySQL that may not match up with what you have installed, or perhaps the gem installer is confused about which config program to use. Make sure mysql_config is returning the correct path.
It´s really a hard job figuring out how to get MySQL and mysql gem up and running on Snow Leopard 10.6.2. I followed the instructions of various posts but was not successful yet:
I build MySQL Version 5.1.39 from source and it installed successfully. When trying to login using (mysql -u root -p) mysql returned the following error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
that obviously meant that the MySQL Server (mysqld) was not running.
which mysql: /usr/local/mysql/bin/mysql
which ruby: ruby 1.8.7 (2009-04-08 patchlevel 160) [i686-darwin9])
gem -v: 1.3.5
mysql: Server version: 5.1.39 MySQL Community Server (GPL)
After a lot of googling around, I found out that
this command can start mysqld:
sudo /usr/local/mysql/bin/mysqld_safe --user=mysql &
The Preference Pane MySQL Tool is probably broken in Mac OS X 10.5 and higher
This command should install the mysql gem correctly on Snow Leopard:
sudo gem uninstall mysql
sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
It ended up that I got the following error using something like rake db:create:
dyld: lazy symbol binding failed: Symbol not found: _mysql_init
Referenced from: /opt/local/lib/ruby/gems/1.8/gems/mysql-2.8.1/lib/mysql_api.bundle
Expected in: flat namespace
dyld: Symbol not found: _mysql_init
Referenced from: /opt/local/lib/ruby/gems/1.8/gems/mysql-2.8.1/lib/mysql_api.bundle
Expected in: flat namespace
This error led me to the following post: http://cho.hapgoods.com/wordpress/?p=158, that basically tells me that the Ruby Version that came together with XCode 3.0 does not work in 64bit environments and a solution could be to install the 32bit versionof MySQL.
Any suggestions, how to proceed?
While building from source is not necessarily a bad idea, even if the official distribution is built using a better compiler, using MacPorts (http://www.macports.org/install.php) to do it is probably a better idea than a self-built installation.
Although you can wrangle the OS X supplied Ruby and MySQL into shape, in my experience it's easier to work entirely within the MacPorts realm (/opt) and leave your original distribution unmolested.
A further advantage is you get a more up-to-date Ruby executable. 10.6 ships with 1.8.7p72 where MacPorts provides 1.8.7p174, for instance.
Example:
sudo port install mysql5
sudo port install mysql5-server
sudo port install rb-mysql
I upgraded to Snow Leopard using the disc we got at WWDC.
Trying to run some of my rails apps now complains about sql
(in /Users/coneybeare/Projects/Ambiance/ambiance-server)
!!! The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql.
Importing all sounds in /Users/coneybeare/Projects/Ambiance/ambiance-sounds/Import 32/Compressed/
-- AdirondackPeepers.caf
!!! The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql.
rake aborted!
dlopen(/opt/local/lib/ruby/gems/1.8/gems/mysql-2.7/lib/mysql.bundle, 9): Library not loaded: /usr/local/mysql/lib/libmysqlclient.16.dylib
Referenced from: /opt/local/lib/ruby/gems/1.8/gems/mysql-2.7/lib/mysql.bundle
Reason: image not found - /opt/local/lib/ruby/gems/1.8/gems/mysql-2.7/lib/mysql.bundle
(See full trace by running task with --trace)
I could have sworn I fixed this once before. The problem is that
sudo gem install mysql
does not work and gives the error:
Building native extensions. This could take a while...
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.
/opt/local/bin/ruby 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
Gem files will remain installed in /opt/local/lib/ruby/gems/1.8/gems/mysql-2.7 for inspection.
Results logged to /opt/local/lib/ruby/gems/1.8/gems/mysql-2.7/gem_make.out
Has anybody gotten mysql to work with rails on snow leopard yet? If so, what is your setup and better yet, what can I do to reproduce it?
I just went through the same pain... here's what worked for me:
Download / install the 64-bit MySQL 5.1.37 from mysql.com
run the following commands:
sudo gem update --system
sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
I also uninstalled all mysql gems that were floating around from my 10.5 days, that may do it if the above doesn't work for you :)
Rebuilding mysql as 64bit or installing the 64bit version is important, but you also need to make sure you build the native parts of the mysql gem as 64bit as well (this doesn't apply if you are on one of the original Intel Core Duo macs).
Here's the magic command:
env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
You should set the ARCHFLAGS as shown above whenever you do a gem install with native components on Snow Leopard.
If you're using bundler, you can use "bundle config" to set the proper build arguments for mysql like so:
bundle config build.mysql --with-mysql-config=/usr/local/mysql/bin/mysql_config
I fought with this for a long time and finally got it working on Snow Leopard. I ended up installing Ruby, RubyGems, and MySQL from source (see the Hivelogic tutorial for installing Ruby and RubyGems. The MySQL tutorial is linked at the bottom). I finally got the gem to install, but I was still getting
dyld: lazy symbol binding failed: Symbol not found: _mysql_init
Referenced from: /Library/Ruby/Site/1.8/universal-darwin10.0/mysql.bundle
Expected in: flat namespace
dyld: Symbol not found: _mysql_init
Referenced from: /Library/Ruby/Site/1.8/universal-darwin10.0/mysql.bundle
Expected in: flat namespace
Trace/BPT trap
I finally deleted the mysql.bundle (I have no idea what this is for) and it all worked.
sudo rm -f /Library/Ruby/Site/1.8/universal-darwin10.0/mysql.bundle
Hope that helps someone.
I have seen this problem many times. almost everytime I build mysql on a machine. I think, you have to pass your mysqlconfig as part of the gem install command.
sudo gem install mysql -- --with-mysql-config=/your/mysql/config
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
Remember that you need mysql dev files to be able to build this gem.
I was having problems with getting my configuration to work after installing snow leopard. I found MAMP at http://www.mamp.info and it bundles Apache, PHP and MySQL. you install it like an application and it just works. Maybe worth giving it a try, and it is free.
mesh
I thought I would answer my own question here. It seems as if the problem isnt in mysql, but in the mysql ruby bindings. I figured this out because when I hooked up Querius (my mysql gui), it was able to connect.
Here is how to build from source fix the bindings:
cd /tmp
wget http://www.tmtm.org/en/ruby/mysql/ruby-mysql-0.2.6.tar.gz
tar xvfz ruby-mysql-0.2.6.tar.gz
cd ruby-mysql-0.2.6
./configure
make
sudo make install
There are plenty of libraries that I will have to build from source on Snow Leopard and they keep popping up. MacPorts doesnt seem to be updated enough for all the libs so I'm off to do it on my own. Next up: freetype (http://download.savannah.gnu.org/releases-noredirect/freetype/)
I proceeded like explained in this post (http://www.schmidp.com/2009/06/14/rubyrails-and-mysql-on-snow-leopard-10a380/), and everything now works fine.
Remember to lookout for the typos in his command to install the mysql driver.
I had this same issue and here is what worked for me.
Install Snow Leopard and the 64bit MySQL DMG.
Create /etc/my.cnf to point to my previous MySQL data directory (as described here) and run sudo mysql_upgrade.
Opened IRB and reinstall all of my gems using (via blog.costan.us/2009/07/rebuild-your-ruby-gems-if-you-update-to.html).`gem list`.each_line {|line| system 'sudo gem install #{line.split.first}'}
Uninstalled the MySQL gems I had installed.
Installed MySQL gem with sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
With that, everything seems to be working so far. *knock wood*
In case you prefer homebrew, instead of installing MySQL manually.
Un-install the existing mysql gem (if any):
sudo gem uninstall mysql
Locate the ‘mysql_config’ file:
find /usr -name 'mysql_config'
Re-install mysql gem:
sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/bin/mysql_config
Note: replace /usr/local/bin/ with the corresponding mysql_config path found in step 2. Also on my blog.
Ian Selby thank you alot but I had to remove the sudo from in front of sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
I was installing to a gemset and am using rvm which I think asks you not to use the sudo keyword. Thanks alot.
I've solved it this way:
after install dmg file of mysql
bundle config build.mysql --with-mysql-config=/usr/local/mysql/bin//mysql_config
env ARCHFLAGS="-arch x86_64"
bundle install
Having had a break from Rails for several years, I just spent some time setting up my development environment. So thought I would create a tutorial on how to install the latest version of Rails 3, MySQL, and RVM on SnowLeopard, to hopefully save others some time who are in my position.
It works as of 21st August 2011, using Rails 3.0.10, MySQL 5.5.15, and RVM 1.7.2. It should work with future Rails 3.0.x, MySQL 5.5.x, and RVM 1.7.x versions.
Install XCode if not already installed. I used 4.0.2. Unfortunately this has now been withdrawn by Apple, but may be available elsewhere on the Internet. Version 3.2.x is free to download from Apple, but I did not test it with this tutorial, it probably works too.
Install rvm:
user$ bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
user$ echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile
user$ source .bash_profile
Install a version of Ruby (e.g. 1.9.2) in rvm, basic usage instructions are here.
user$ rvm install 1.9.2
user$ rvm use 1.9.2
Create a gemset for the rvm ruby installed in step 2 (x is the version number).
user$ rvm gemset create rails30x
user$ rvm 1.9.2#rails30x
Install Rails 3.0.x (x is the version number).
user$ gem install rails -v 3.0.x.
Download and install the MySQL 5.5.x package, the startup item, and the preferences pane. All 3 of these are included in the DMG install file. Also install MySQL WorkBench.
Find /usr/local/mysql-version-name/support-files (inserting the correct MySQL directory name) and edit mysql.server (with root privileges). Around line 46 locate the lines that read:
basedir=
datadir=
and change them to read (inserting the correct MySQL directory name):
basedir=/usr/local/mysql-version-name
datadir=/usr/local/mysql-version-name/data
Save the file. MySQL can now be started from the preferences pane.
To enable rails 3 to use mysql, install the mysql2 gem (see next step). First, you’ll need to set the
DYLD_LIBRARY_PATH to include the MySQL library directory. To do this, edit your ~/.bash_profile in your
home folder and include the following (inserting the correct MySQL directory name):
export DYLD_LIBRARY_PATH=/usr/local/mysql-version-name/lib:$DYLD_LIBRARY_PATH
Without the inclusion of the directory in the DYLD_LIBRARY_PATH, a message about not finding the library
would appear and the server would abort.
Install the mysql2 gem. (as of May 2011, version 0.2.7 is the most recent working version with Rails 3.0.x).
user$ gem install mysql2 -v 0.2.7
Create a rails app, and it's corresponding database (appname_development).
user$ rails new appname
Add this to the app's Gemfile: gem 'mysql2', "0.2.7"
Add this to the app's database.yml:
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: appname_development
pool: 5
username: username
password: pwd
host: localhost
start app and check "About your application's environment". Everything should be working correctly.
The instructions for setting ARCHFLAGS and passing --mysql-config=... didn't seem to be quite enough to solve this for me on Snow Leopard. In addition to doing that, I added:
DYLD_LIBRARY_PATH="/usr/local/mysql/lib:$DYLD_LIBRARY_PATH"
to my bash profile, and this solved it for me.
I tried the archflags trick many times with slight variations but it never worked for me.
What finally did work was switching back to the version of ruby and gem installed with snow leopard.
I had built and installed my own version which has worked for me in every respect except this one.
Since everything else seems to work fine, I can't help guessing the mysql plugin has some funky assumptions in it. Anyway, all I did was switch /usr/bin to be first in my path again. I had installed ruby in /usr/local/ruby-1.8.7 and /usr/local/ruby-1.9.1 to be able to easily switch. Thought I'd mention it since the archflags solution seems to work for many people, but not quite all.
I renamed the mysql_config program from $MYSQL_HOME/bin to something else so that the configuration script from the gem installer is unable to find it. Even though I was using the libs option, the gem installer did always use the compile settings from my mysql installation, which is fat binary. But the default ruby installation is only x86_64 and therefore the compile of the gem fails. After renaming the mysql_config program the following command worked just fine and installed the gem:
sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-dir=/usr/local/mysql
If you are installing the mysql gem with RVM you need to use the following code to install it
sudo env ARCHFLAGS="-arch x86_64" gem install mysql
This method worked for me in Leopard Server, none of the above worked
this article solved the issue for me :)
http://techliberty.blogspot.com/2009/12/dealing-with-rake-aborted-uninitialized.html
Prior to Leopard
sudo gem install mysql -- --with-mysql-dir=/usr/local/mysql
Leopard on a PPC machine:
sudo env ARCHFLAGS="-arch ppc" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
Leopard on an Intel machine:
sudo env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
Snow Leopard (only on Intel):
sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config