Last active
August 29, 2015 14:19
-
-
Save danielfttorres/fb8d3e572c1ee7f2416e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Acess MySQL with root | |
mysql -u root | |
-- Acess MySQL with a user | |
mysql -u your_username -p p4sw0rd | |
-- Display all databases | |
SHOW DATABASES; | |
-- Create a database | |
CREATE DATABASE my_db; | |
-- Delete a database | |
DROP DATABASE my_db; | |
-- Access a database | |
USE my_db; | |
-- Display tables in a database | |
SHOW tables; | |
-- Delete a table | |
DROP TABLE my_table; | |
-- Create a table in selected database | |
CREATE TABLE my_table ( | |
id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, | |
name VARCHAR(20), | |
confirmed CHAR(1), | |
signup_date DATE | |
); | |
-- Display table organization | |
DESCRIBE my_table; | |
-- List information in a table | |
SELECT * FROM my_table; | |
-- Add information in a table | |
INSERT INTO my_table (id, name, confirmed, signup_date) VALUES (NULL, "Daniel","N", "2015-04-21"); | |
-- Update information in a table | |
UPDATE my_table SET confirmed="Y" WHERE my_table.name="Daniel"; | |
-- Add a column in a table | |
ALTER TABLE my_table ADD email VARCHAR(40); | |
ALTER TABLE my_table ADD email VARCHAR(40) AFTER name; | |
-- Delete a column in a table | |
ALTER TABLE my_table DROP email; | |
-- Delete a row in a table | |
DELETE from my_table where column_name=field_name; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment