You are on page 1of 2

Mysqul u root mysql h host u user p SELECT USER(); SHOW DATABASES; SELECT DATABASE(); USE database; CREATE DATABASE

testDB - login to mysql - see which user is logged in - see which databases currently exist on server - see which database is currently selected - Use the database called database - create a database called testDB

SHOW TABLES;

- see which tables exist in the selected database

CREATE TABLE test_table (name VARCHAR(20), id INT); - to create a table called test_table with columns name and id DESCRIBE test_table; - see table design

LOAD DATA LOCAL INFILE /path/input.txt INTO TABLE test_table; - to populate a table using a text file (tab separated, \N for null field) LOAD LINES TERMINATED BY \r\n ; - to populate table if text file created on windows where \r\n end lines

INSERT INTO test_table VALUES ( Jack , 58976); - add a new record into a table DELETE FROM test_table; - empty the table

UPDATE test_table SET id = 12345 WHERE name = Jack ; - fix a record To pull information from a table: SELECT what_to_select FROM which_table WHERE conditions_to_satisfy; - what_to_select can be a list of columns, or * for all - WHERE is optional SELECT * FROM test_table; - retrieves everything from a table - order by descending order - order by ascending order

SELECT * FROM test_table ORDER BY test_id DESC; SELECT * FROM test_table ORDER BY test_id ASC;

You might also like