Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot rake db:create:all -- Couldn't create database for {"encoding"=>"utf8", "username"=>"root", "adapter"=>"mysql"

I'm trying to get a rails app up and running on my computer, and I'm having issues with creating the databases. I've properly installed/setup rails, mysql and have installed the mysql 2.8.1 gem (I verified this with gem list).

So now, I'm trying to run 'rake db:create:all' and I'm getting the following error:

Couldn't create database for {"encoding"=>"utf8", "username"=>"root", "adapter"=>"mysql", "database"=>"pyo", "host"=>"localhost", "password"=>nil, "socket"=>"/tmp/mysql.sock"}, charset: utf8, collation: utf8_unicode_ci (if you set the charset manually, make sure you have a matching collation)

Couldn't create database for {"encoding"=>"utf8", "username"=>"root", "adapter"=>"mysql", "database"=>"pyo_test", "host"=>"localhost", "password"=>nil, "socket"=>"/tmp/mysql.sock"}, charset: utf8, collation: utf8_unicode_ci (if you set the charset manually, make sure you have a matching collation)

I'm currently running 5.5.10 MySQL Community Server (GPL) on Snow Leopard (10.6.6)

And here is what is in my database.yml file

development:
  adapter: mysql
  encoding: utf8
  database: pyo
  username: root
  password:
  socket: /tmp/mysql.sock
  host: localhost

test:
  adapter: mysql
  encoding: utf8
  database: pyo_test
  username: root
  password:
  socket: /tmp/mysql.sock
  host: localhost

I notice how the end of the error says "charset: utf8, collation: utf8_unicode_ci (if you set the charset manually, make sure you have a matching collation)" -- Is that the issue? And if so, how do I fix it?

I've been stuck on this thing for hours and can't find anything that helps on Google. So any help at this point would be much appreciated.

Thanks!!

like image 445
DeG Avatar asked Apr 07 '11 04:04

DeG


2 Answers

I know this thread is old but being a IT guy who believes in keeping good solid documentation in one place here goes:

The problem actually stems from your "config/database.yml" file. You are pointing ROR to the wrong location for the MySQL Socket.

I ran into this problem and what it turned out to be is the gem was built on a mac system and the developer did not account for other operating systems by putting his "mysql.sock" file in the "/tmp" directory rather than the "/var/run/mysqld/mysqld.sock" .

So his "database.yml" file looked like:

development: adapter: mysql2 #encoding: utf8 database: somedatabase pool: 5 username: someusername password: somepassword socket: /tmp/mysql.sock

Because I was on a Ubuntu System I had to change mine to the following:

development: adapter: mysql2 #encoding: utf8 database: somedatabase pool: 5 username: someusername password: somepassword socket: /var/run/mysqld/mysqld.sock

Yes the error can be misleading however it has nothing to do with your "encoding" or whether you are using localhost or 127.0.0.1 (At least in linux/UNIX systems these translate to the same thing and are synonymous)

Begin Edit

Also it is not good to have encoding commented out like I do above. So I am providing the modification here for reference.

development: adapter: mysql2 encoding: utf8 database: somedatabase pool: 5 username: someusername password: somepassword socket: /var/run/mysqld/mysqld.sock

End Edit

like image 85
The Gugaru Avatar answered Oct 12 '22 11:10

The Gugaru


think I had something like this...fixed by adding this to database.yml:

host: 127.0.0.1

Or in your case, changing it from localhost.

like image 25
Plattsy Avatar answered Oct 12 '22 12:10

Plattsy