Well, this is a common problem for us beginners. This problem has arisen since the creation of a new project in rails. Suppose there is an example
$ rails new toy βd mysql
- After you run the package and start your server, most likely you will have an error. To fix this, you need to go to database.yml and change the following:
Add the password in the password field as shown below, this is the password that you use to protect mysql.
default: & default
adapter: mysql2
encoding: utf8
pool: 5
username: root
password: mypassword
socket: /tmp/mysql.sock
Also, comment out the database by adding a hash tag (#) in front of the name, as shown below.
development:
: * default
database: #toy_development
- Then restart your command line and go to the root of your application and type:
$ rails s
You need to see the Ruby on Rails welcome page.
- After that you need to create a database.
Create a database.
The error message says that the database is not selected. This is because I did not create it. When you are working with MySQL, you should create it like this:
- Go to the root of my application and type:
$ mysql βu root βp
$ Passwor: mypassword (Enter your password, this is the one you entered to secure MySQL)
Note. In this example, a project called toy works, and the user I wanted to grant privileges to is mark , and the password I give is 45mark . Below you will see where I apply these elements. Remember to apply your own elements in each part of the manual.
Creation and use of this project
- As soon as you enter, you will see a pointer ( mysql> ), so enter after it:
mysql> GRANT ALL PRIVILEGES ON toy_development. * TO 'mark' @ 'localhost' IDENTIFIED BY '45mark';
mysql> exit;
- Make sure it works by typing:
$ mysql βu mark βp toy_development
Enter password: 45mark (You enter the one you gave)
- Open the database.yml file and configure the necessary and correct as necessary. In my case, I will mark the username and password for 45mark
default: & default
adapter: mysql2
encoding: utf8
pool: 5
username: mark
password: 45mark
socket: /tmp/mysql.sock
- In addition, REMOVE hash tag (#) added to
development:
: * default
database: toy_development Save it.
- Go to the root of the application and type
$ rake db: schema: dump
Done !!
Hope this helps. Happy coding!
thanks