Guest User

Untitled

a guest
Apr 12th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. ## Creating a Database
  2. * Using mysql, here are 4 commands when working with databases:
  3. * `SHOW DATABASES;`
  4. * `CREATE DATABASE db_name;`
  5. * `USE db_name;`
  6. * `DROP DATABASE db_name;`
  7. * **DON'T FORGET THE `;`!**
  8. * Start up mysql server: `mysql.server start`
  9. * then run `mysql -u root -p`, enter password
  10. * `CREATE DATABASE name_development`
  11. * Then `USE name_development` to run commands against that db
  12. * Bad to use `root` user in mysql, create a new user for your app!
  13. * This command will create and grant the user all rights to the DB, after the `USE` db command
  14.  
  15. ```
  16. GRANT ALL PRIVILIGES ON db_name.*
  17. TO 'username'@'localhost'
  18. IDENTIFIED BY 'password';
  19.  
  20. SHOW GRANTS FOR 'username'@'localhost';
  21. ```
  22.  
  23. * Now you can exit, and sign in as the new user and log in to a specific db:
  24. `mysql -u simple_cms -p simple_cms_development`
  25. * `SHOW TABLES;`
  26. * `SHOW FIELDS FROM USERS;`
  27. * `SELECT * FROM table_name;` is used to show what data is contained in the table.
  28. * When you execute `SHOW TABLES`, you will notice a table called `schema migrations`. It contains
  29. all the migration files from the `db/migrate` folder.
  30. * Now that you have created a database, you have to tell rails to use it!
  31. * In `config/database.yml`:
  32.  
  33. ```yml
  34. development:
  35. adapter: mysql2
  36. encoding: utf8
  37. database: simple_cms_development
  38. pool: 5
  39. username: simple_cms
  40. password: secretpassword
  41. socket: /tmp/mysql.sock
  42. ```
  43.  
  44. * Migrate the database schema into our app: `rake db:schema:dump`, empty schema, connection
  45. successful!
  46. * **YAML = YAML AIN'T MARKUP LANGUAGE**
Add Comment
Please, Sign In to add comment