-
Notifications
You must be signed in to change notification settings - Fork 0
Rails and mysql DB
richlewis14 edited this page Apr 5, 2013
·
8 revisions
Command to access databases in Rails on local machine
Good resource @ http://www.pantz.org/software/mysql/mysqlcommands.html
mysql -u root
List of commands when in mysql
Show Databases
show databases;
Delete Database
drop database <database name>;
Use Database
use <databasename>;
Show Tables (Once in Selected Database)
show tables;
View Columns in Table
describe <tablename>;
Vertical Output for Tables
select * from users where name = 'Richard Lewis' \G;
Good article here http://pento.net/2009/02/27/the-g-modifier-in-the-mysql-command-line-client/
An example of the output is like so
id: 1
email: [email protected]
encrypted_password: $2a$10$.TdzyhI7TsJN9aSk/bst/.8dmbzBt2zl18EfJumFtRyK.oohFsPtW
reset_password_token: NULL
reset_password_sent_at: NULL
remember_created_at: NULL
sign_in_count: 1
current_sign_in_at: 2013-04-05 17:51:54
last_sign_in_at: 2013-04-05 17:51:54
current_sign_in_ip: 127.0.0.1
last_sign_in_ip: 127.0.0.1
created_at: 2013-04-05 17:51:54
updated_at: 2013-04-05 17:51:54
admin: NULL
name: NULL
Delete Record from column
DELETE FROM users WHERE name='Richard Lewis';
Update a specific column in a table
UPDATE <tablename> SET name = 'Richard Lewis' WHERE id=1;