I'm attempting to get my first "hello world" rails example going using the rails' getting started guide on my OSX 10.6.3 box.
When I go to execute the first rake db:create
command (I'm using mysql) I get:
simon@/Users/simon/source/rails/blog/config: rake db:create (in /Users/simon/source/rails/blog) Couldn't create database for {"reconnect"=>false, "encoding"=>"utf8", "username"=>"root", "adapter"=>"mysql", "database"=>"blog_development", "pool"=>5, "password"=>nil, "socket"=>"/opt/local/var/run/mysql5/mysqld.sock"}, charset: utf8, collation: utf8_unicode_ci (if you set the charset manually, make sure you have a matching collation)
I found plenty of stackoverflow questions addressing this problem with the following advice:
Verify that user and password are correct (I'm running w/ no password for root on my dev box)
Verify that the socket is correct - I can cat the socket, so I assume it's correct
Verify that the user can create a DB (As you can see root can connect and create a this DB no problem)
simon@/Users/simon/source/rails/blog/config: mysql -uroot -hlocalhost Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 16 Server version: 5.1.45 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database blog_development; Query OK, 1 row affected (0.00 sec)
to ensure that this wasn't a charset issue I also tried:
mysql> create database foobar CHARACTER SET utf8 COLLATE utf8_general_ci;
Query OK, 1 row affected (0.00 sec)
Note: here is my database.yaml:
development:
adapter: mysql
encoding: utf8
reconnect: false
database: blog_development
pool: 5
username: root
password:
socket: /opt/local/var/run/mysql5/mysqld.sock
# host: localhost
Note that I tried switching socket to localhost with no effect.
Any idea on what might be going on here?
Re-install mysql-server and mysql-client using this command:
and then some libraries you need to install to make MySQL available to ruby:
This all solved my problem. Try it !!! :)
I just had the same issue : it was an old mysql gem which was not up to date. Re-installing the mysql gem did the trick.
Does the
blog_development
database already exist?If so, you can just continue to the next step.
Try running
ruby script/server
in theblog/
directory.If it doesn't error out, then you should be able to navigate to
localhost:3000
and continue the tutorial from here http://guides.rubyonrails.org/getting_started.html#hello-rails.Leave me a comment if
ruby script/server
errors out.You should post here your database.yml
To make your test better, i would try to create a database UTF-8 to see if your database supports utf-8
It could be a number of things.
sudo gem install mysql
Other than that, I'm not sure.
Thanks for all the help guys. Looks like the problem had to do with my install of the mysql gem under OSX.
@tim after I proceeded to the next step and got up and going I got an error on the console, so I did a bit of searching and found this helpful thread.
After I uninstalled my ruby gems
gem uninstall mysql
I installed the proper mysql gems using this command (from the thread):export ARCHFLAGS="-arch i386 -arch x86_64" ; gem install --no-rdoc --no-ri mysql -- --with-mysql-dir=/opt/local/lib/mysql5 --with-mysql-config=/opt/local/lib/mysql5/bin/mysql_config
After executing this one I was able to successfully run
rake db:create
and proceed.Thanks!!