Unable to rake db: create: all - Failed to create database for {"encoding" => "utf8", "username" => "root", "adapter" => "mysql"
I am trying to run the rails application on my computer and am having problems creating databases. I correctly installed / installed rails, mysql and installed gem mysql 2.8.1 (I checked this with a list of gems).
So now I try to run "rake db: create: all" and I get the following error:
Failed to create database for {"Encoding" => "utf8", "Username" => "root", "adapter" => "mysql", "database" => "pyo", "host" => " localhost "," password "=> nil," socket "=>" /tmp/mysql.sock "}, charset: utf8, mapping: utf8_unicode_ci (if you set the encoding manually, make sure you have the appropriate sort)
Failed to create database for {"Encoding" => "utf8", "Username" => "root", "adapter" => "MySQL", "Database" => "pyo_test", "host" => "localhost", "password" => nil, "socket" => "/tmp/mysql.sock"}, charset: utf8, mapping: utf8_unicode_ci (if you set the encoding manually, make sure you have the proper sorting)
I am currently running 5.5.10 MySQL Community Server (GPL) on Snow Leopard (10.6.6)
And here is what 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 the end of the error says: "charset: utf8, collation: utf8_unicode_ci (if you set the encoding manually, make sure you have the appropriate sorting)" is the problem? And if so, how to fix it?
I am stuck with this thing for hours and canโt find anything that helps on Google. Therefore, any help at this stage would be greatly appreciated.
Thanks!!
So, after about 3 or 4 days of searching on Google and a lot of different things, I somehow came across this:
http://geryit.com/blog/2011/01/installing-mysql-with-rails-on-mac-os-x-snow-leopard/
And guess what? IT WORKS! IN EXCELLENCE. This makes me think that the problem lies in MySQL 5.5.10. Something in this case will not just play well with my ruby โโ/ rails environment. However, as soon as I followed the instructions in the link above (including uninstalling mysql and reinstalling 5.1), my application now works fine on my local machine.
Hope this helps someone!
I guess 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.
I was getting the same issue with mysql2 stone. Then I found that my MySQL only listens for "localhost" and not "127.0.0.1", so I changed it to "localhost" and now I no longer get this problem. Everything is working now.
I know this thread is out of date, but as an IT guy who believes in good documentation in one place, itโs coming:
The problem is actually related to your config / database.yml file. You point ROR to the wrong location for MySQL Socket.
I ran into this problem, and as it turned out, the stone was built on a Mac system, and the developer did not take into account other operating systems, placing his file "mysql.sock" in the directory "/ tmp" and not "/ var / run / mysqld /mysqld.sock ".
So his database.yml file looked like this:
development: adapter: mysql2 #encoding: utf8 database: somedatabase pool: 5 username: someusername password: somepassword socket: /tmp/mysql.sock
Since 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, but it has nothing to do with your โencodingโ or it is used by localhost or 127.0.0.1 (at least on Linux / UNIX systems they translate to the same thing and are synonymous)
Start editing
It is also not good to comment on the encoding, as I do above. Therefore, I am providing a modification here for reference.
development: adapter: mysql2 encoding: utf8 database: somedatabase pool: 5 username: someusername password: somepassword socket: /var/run/mysqld/mysqld.sock
End of editing
I want to share my decision. I had my database.yml as follows
default: &default adapter: mysql2 encoding: utf8 username: root password: host: 127.0.0.1 port: 3306 development: <<: *default database: dev.database My mistake was on this line
database: dev.database So, I write without (.)
database: devdatabase