Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Development Tools

MySQL error creating database - Couldn't create database for - I am using Ubuntu 14.04. I can't get past this.

I cannot get MySQL to work in my ActiveRecord lesson and I am stopped dead in my tracks. The message says "Couldn't create database for {a whole of stuff, etc.} . It also asks me to enter the root password and then tells me "Access denied for user 'root'@'localhost'. Has anyone seen this error? I would appreciate any help I can get!

Thank you.

2 Answers

hello bob

try this command in shell to chevck if root can connect to the database

mysql -u root -p

then put your root password

after check your databases second_biller_development and second_biller_production exists with the command:

show databases;

then create databases if nit exists:

CREATE DATABASE IF NOT EXISTS second_biller_development;

if the databases exists , remove the table schema_migrations

DROP TABLE schema_migrations;

then exit mysql with:

exit;

and try to run:

rake:db migrate

else try to build a new rails app with:

rails new app_name -d mysql

check the mysql gem is set and working properly with:

cd app_name

bundle install

hope this will help

Jeremie, thank you for the information. It was a great help. I tried a lot of different things yesterday to get this thing working. I found that I need to have MySQL server running on my Ubuntu 14,04 OS system. To get it to work for me I went into my database.yml file and entered the password in two places so that it would be passed to MySQL.

I ran rake db:create and I got an error that the rake file did not exist but it did because I saw it. I don't remember what I had to do so that I could find it, but it did. After that I tried to use "mysql -uroot" to open up the command line. It is crazy what a little typo can do to your progress. Anyway, just as you had typed in your response to me I entered "mysql -u root -p" and I was prompted for my password. After entering my password I was presented with the mysql prompt.

I typed in show databases; and all of my the databases that I had not dropped earlier this morning were there. Thank you for your help and the time you spent in helping me out with this challenging effort.

Bob

hello robert , if your database.yml is well configured , maybe mysql disallow root login . try to run in a shell dpkg-reconfigure mysql

best regards

Jeremie,

Here is what my database.yml file looks like. I have tried various things that I saw other places and I cannot get it to work. Thanks for taking a look!

Bob

MySQL. Versions 5.0+ are recommended.

Install the MYSQL driver

gem install mysql2

Ensure the MySQL gem is defined in your Gemfile

gem 'mysql2'

And be sure to use new-style password hashing:

http://dev.mysql.com/doc/refman/5.0/en/old-client.html

default: &default adapter: mysql2 encoding: utf8 pool: 5 username: root password: socket: /var/run/mysqld/mysqld.sock

development: <<: *default database: second_biller_development

Warning: The database defined as "test" will be erased and

re-generated from your development database when you run "rake".

Do not set this db to the same as development or production.

test: <<: *default database: second_biller_test

As with config/secrets.yml, you never want to store sensitive information,

like your database password, in your source code. If your source code is

ever seen by anyone, they now have access to your database.

Instead, provide the password as a unix environment variable when you boot

the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database

for a full rundown on how to provide these environment variables in a

production deployment.

On Heroku and other platform providers, you may have a full connection URL

available as an environment variable. For example:

DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase"

You can use this database configuration with:

production:

url: <%= ENV['DATABASE_URL'] %>

production: <<: *default database: second_biller_production username: second_biller password: <%= ENV['SECOND_BILLER_DATABASE_PASSWORD'] %>