Rails: Cannot create the database using "rake"


I’m trying to create a database by running rake db:create RAILS_ENV=production --trace. Unfortunately, I got this error:

[color=#C71585][size=x-small](in /home/my_user/my_sub_domain.com)
** Invoke db:create (first_time)
** Invoke db:load_config (first_time)
** Invoke rails_env (first_time)
** Execute rails_env
** Execute db:load_config
** Execute db:create
Can’t connect to MySQL server on ‘my_sub_domain.com’ (111)
Couldn’t create database for {“reconnect”=>false, “encoding”=>“utf8”, “username”=>“my_username”, “adapter”=>“mysql”, “database”=>“my_db_name”, “host”=>“my_subdomain.com”, “pool”=>5, “password”=>“my_password”}, charset: utf8, collation: utf8_unicode_ci[/size][/color]

Any ideas what could be the reason for this error ?


First guess would be that you’ve input the MySQL server hostname incorrectly. Database host should not be the same as the name of your site — it should probably be something like “mysql.mydomain.com”.


Thanks a lot!
I changed it to mysql.mydomain.com and it solved the problem :slight_smile: