MySQL Cheat Sheet

Reviews
Shared by: armani11
Stats
views:
81
rating:
not rated
reviews:
0
posted:
11/9/2008
language:
English
pages:
0
MySQL Cheat Sheet http://nparikh.freeshell.org/unix/mysql.php mysql> USE database; mysql> SHOW DATABASES; mysql> SHOW TABLES; mysql> DESCRIBE table; mysql> CREATE DATABASE db_name; mysql> CREATE TABLE table_name (field1_name TYPE(SIZE), field2_name TYPE(SIZE)); Ex: mysql> CREATE TABLE pet (name VARCHAR(20), sex CHAR(1), birth DATE); mysql> LOAD DATA LOCAL INFILE "infile.txt" INTO TABLE table_name; (Use \n for NULL) mysql> INSERT INTO table_name VALUES ('MyName', 'MyOwner', '2002-08-31'); (Use NULL for NULL) mysql> SELECT from_columns FROM table WHERE conditions; All values: SELECT * FROM table; Some values: SELECT * FROM table WHERE rec_name = "value"; Multiple critera: SELECT * FROM TABLE WHERE rec1 = "value1" AND rec2 = "value2"; mysql> SET AUTOCOMMIT=1; # used for quick recreation of table mysql> DELETE FROM pet; mysql> LOAD DATA LOCAL INFILE "infile.txt" INTO TABLE table; ! mysql> UPDATE table SET value = "new_value" WHERE record_name = "value"; " ! mysql> SELECT column_name FROM table; ! #! ! "! mysql> SELECT DISTINCT column_name FROM table; mysql> SELECT col1, col2 FROM table ORDER BY col2; Backwards: SELECT col1, col2 FROM table ORDER BY col2 DESC; ! mysql> SELECT CURRENT_DATE, (YEAR(CURRENT_DATE)-YEAR(date_col)) AS time_diff [FROM table]; MONTH(some_date) extracts the month value and DAYOFMONTH() extracts day. $ % mysql> SELECT * FROM table WHERE rec LIKE "blah%"; (% is wildcard - arbitrary # of chars) 1 of 2 4/12/2005 9:17 AM MySQL Cheat Sheet http://nparikh.freeshell.org/unix/mysql.php Find 5-char values: SELECT * FROM table WHERE rec like "_____"; (_ is any single character) & ! & " % mysql> SELECT * FROM table WHERE rec RLIKE "^b$"; (. for char, [...] for char class, * for 0 or more instances ^ for beginning, {n} for repeat n times, and $ for end) (RLIKE or REGEXP) To force case-sensitivity, use "REGEXP BINARY" ! mysql> SELECT COUNT(*) FROM table; ' !" ! mysql> SELECT owner, COUNT(*) FROM table GROUP BY owner; (GROUP BY groups together all records for each 'owner') ! " (Example) mysql> SELECT pet.name, comment FROM pet, event WHERE pet.name = event.name; (You can join a table to itself to compare by using 'AS') ! ( mysql> SELECT DATABASE(); % ! ! mysql> SELECT MAX(col_name) AS label FROM table; )! mysql> CREATE TABLE table (number INT NOT NULL AUTO_INCREMENT, name CHAR(10) NOT NULL); mysql> INSERT INTO table (name) VALUES ("tom"),("dick"),("harry"); ) ! ( mysql> ALTER TABLE tbl ADD COLUMN [column_create syntax] AFTER col_name; ! mysql> ALTER TABLE tbl DROP COLUMN col; (Full ALTER TABLE syntax available at mysql.com.) * " # mysql -u user -p < batch_file (Use -t for nice table layout and -vvv for command echoing.) Alternatively: mysql> source batch_file; ! "# $##% "#&$'&%( ) 2 of 2 4/12/2005 9:17 AM

Related docs
MySQL Cheat Sheet
Views: 27  |  Downloads: 10
MySQL Cheat Sheet
Views: 6  |  Downloads: 2
MySQL Cheat Sheet
Views: 3  |  Downloads: 4
MySQL Cheat Sheet.graffle
Views: 40  |  Downloads: 11
photography cheat sheet
Views: 314  |  Downloads: 12
mootools cheat sheet
Views: 542  |  Downloads: 17
graphics cheat sheet
Views: 80  |  Downloads: 5
adobe connect cheat sheet
Views: 22  |  Downloads: 0
excel 2007 cheat sheet
Views: 281  |  Downloads: 20
adobe flex 3 cheat sheet
Views: 67  |  Downloads: 13
digital files cheat sheet
Views: 10  |  Downloads: 1
Other docs by armani11
Dirty Joke Doc I Got A Problem
Views: 2750  |  Downloads: 14
Jon Stewart
Views: 203  |  Downloads: 0
ASSIGNMENT OF MONEY DUE
Views: 255  |  Downloads: 2
The Communist Manifesto
Views: 327  |  Downloads: 12
Employee termination contract
Views: 1232  |  Downloads: 31
Directors Dissent Declaration of Dividend
Views: 196  |  Downloads: 1
DD Form 1707 Information to Offerors or Quoters
Views: 441  |  Downloads: 3
Notice of Special Meeting of Directors
Views: 140  |  Downloads: 1
SALES FOLLOW UP LETTER
Views: 829  |  Downloads: 58
Transmittal Letter to IRS Enclosing Form SS-4
Views: 184  |  Downloads: 0
Urcarco Inc Ammendments and By laws
Views: 209  |  Downloads: 0