(*) Note: This is somewhere from the Web, but I have no idea where this comes from...
CREATE DATABASE database_name;
USE database_name;
SOURCE path/filename.txt (NOT 'path/filename.txt') Load from text file
SHOW TABLES;
CREATE TABLE pet (name VARCHAR(20), owner VARCHAR(20),species
VARCHAR(20), sex CHAR(1), birth DATE, death DATE);
DROP TABLE pet; Delete table
DESCRIBE pet; Shows the fields and field types, not the elements inside
SELECT * FROM pet; Shows all the elements on the table
SELECT * FROM pet WRERE name='cat'; Shows all the rows where name=cat
SELECT owner FROM pet WRERE name='cat'; Shows all the owners that own cats
-----------------------------------------------------------------------
INSERT INTO pet VALUES
('Puffball','Diane','hamster','f','1999-03-30',NULL);
LOAD DATA LOCAL INFILE '/path/filename.txt' INTO TABLE pet;
Note that if you created the file on Windows with an editor that uses
\r\n as a line terminator, you should use:
LOAD DATA LOCAL INFILE '/path/filename.txt' INTO TABLE pet LINES
TERMINATED BY '\r\n';
(This is used after you create a text file by putting the values for
each separated by TAB and each row separated by ENTER)
DELETE FROM pet; Deletes everything from the table.
DELETE FROM pet WHERE name='cat'; Deletes based all rows that have name=cat.
-----------------------------------------------------------------------