3

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:

  1. Verify that user and password are correct (I'm running w/ no password for root on my dev box)

  2. Verify that the socket is correct - I can cat the socket, so I assume it's correct

  3. 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?

0

6 Answers 6

6

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!!

Sign up to request clarification or add additional context in comments.

Comments

2

It could be a number of things.

  • Is your database set for utf8 character set?
  • Is the path to the socket correct, since it varies from OS.
  • Have you reinstalled the mysql gem? sudo gem install mysql
  • It might be MySQL, you might want to downgrade the version to 5.0

Other than that, I'm not sure.

1 Comment

+1 On Ubuntu 16.04 my problem was that my socket /tmp/mysql.sock was different than the usual one. /var/run/mysqld/mysqld.sock
2

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

create database foobar CHARACTER SET utf8 COLLATE utf8_general_ci

2 Comments

Ah, good point. Let me post 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. Good idea on the charset test: mysql> create database foobar CHARACTER SET utf8 COLLATE utf8_general_ci; Query OK, 1 row affected (0.00 sec) But no luck, unfortunately.
Note I posted above with a better formatted version of the comment
0

Does the blog_development database already exist?

If so, you can just continue to the next step.

Try running ruby script/server in the blog/ 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.

1 Comment

Thanks for the suggestion, much appreciated! After I created the blog_development DB manually I was able to start rails and continue. I'm a little concerned about the error though, perhaps this means I will have DB connection problems in the future?
0

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.

Comments

0

Re-install mysql-server and mysql-client using this command:

sudo apt-get install mysql-server mysql-client

and then some libraries you need to install to make MySQL available to ruby:

sudo apt-get install libmysql-ruby

This all solved my problem. Try it !!! :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.