Fix MySQL configuration for Ruby on Rails Database.yml file

I have this configuration:

development: adapter: mysql2 encoding: utf8 database: my_db_name username: root password: my_password host: mysql://127.0.0.1:3306 

And I get this error:

 Unknown MySQL server host 'mysql://127.0.0.1:3306' (1) 

Is there something obvious I'm doing wrong?

+76
ruby mysql ruby-on-rails yaml
May 03 '11 at 15:57
source share
5 answers

You must separate the host from the port number. You might have something like:

 development: adapter: mysql2 encoding: utf8 database: my_db_name username: root password: my_password host: 127.0.0.1 port: 3306 
+167
May 03 '11 at 3:59 pm
source share
— -

You can also do the following:

 default: &default adapter: mysql2 encoding: utf8 username: root password: host: 127.0.0.1 port: 3306 development: <<: *default database: development_db_name test: <<: *default database: test_db_name production: <<: *default database: production_db_name 
+11
Jan 08 '16 at 6:25
source share

If you may have an empty config / database.yml file, then define the ENV ['DATABASE_URL'] variable, then it will work

 $ cat config/database.yml $ echo $DATABASE_URL mysql://root:my_password@127.0.0.1:3306/my_db_name 

for Heroku: heroku config: set DATABASE_URL='mysql://root:my_password@host.com/my_db_name'

+2
Mar 24 '15 at 4:30
source share

If you have multiple databases for testing and development, this can help.

 development: adapter: mysql2 encoding: utf8 reconnect: false database: DBNAME pool: 5 username: usr password: paswd shost: localhost test: adapter: mysql2 encoding: utf8 reconnect: false database: DBNAME pool: 5 username: usr password: paswd shost: localhost production: adapter: mysql2 encoding: utf8 reconnect: false database: DBNAME pool: 5 username: usr password: paswd shost: localhost 
0
Oct 30 '14 at 6:33
source share

None of these androns worked for me, I found Werner Bihl's answer that fixed the problem.

Getting "Unable to connect to local MySQL server via socket '/var/run/mysqld/mysqld.sock'” error while setting up mysql database for Ruby on Rails application

0
Nov 02 '16 at 17:26
source share



All Articles