professional documents
home
Profile
docsters
request
Blogs
Upload
about me
contact me
user photo
Ganesh Nalawade
IT
Solution Engineer
InMage Systems
http://ganesh.nalawade.googlepages.com/aboutme
submit clear
Word Document

MySQL Command center doc

Selecting a database: mysql> USE database; Listing databases: mysql> SHOW DATABASES; Listing tables in a db: mysql> SHOW TABLES; Describing the format of a table: mysql> DESCRIBE table; Creating a database: mysql> CREATE DATABASE db_name; Creating a table: 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); Load tab-delimited data into a table: mysql> LOAD DATA LOCAL INFILE "infile.txt" INTO TABLE table_name; (Use \n for NULL) Inserting one row at a time: mysql> INSERT INTO table_name VALUES ('MyName', 'MyOwner', '2002-08-31'); (Use NULL for NULL) Retrieving information (general): 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"; Reloading a new data set into existing table: mysql> SET AUTOCOMMIT=1; # used for quick recreation of table mysql> DELETE FROM pet; mysql> LOAD DATA LOCAL INFILE "infile.txt" INTO TABLE table; Fixing all records with a certain value: mysql> UPDATE table SET column_name = "new_value" WHERE record_name = "value"; Selecting specific columns: mysql> SELECT column_name FROM table; Retrieving unique output records: mysql> SELECT DISTINCT column_name FROM table; Sorting: mysql> SELECT col1, col2 FROM table ORDER BY col2; Backwards: SELECT col1, col2 FROM table ORDER BY col2 DESC; Date calculations: 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. Pattern Matching: mysql> SELECT * FROM table WHERE rec LIKE "blah%"; (% is wildcard -arbitrary # of chars) Find 5-char values: SELECT * FROM table WHERE rec like "_____"; (_ is any single character) Extended Regular Expression Matching: 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" Counting Rows: mysql> SELECT COUNT(*) FROM table; Grouping with Counting: mysql> SELECT owner, COUNT(*) FROM table GROUP BY owner; (GROUP BY groups together all records for each 'owner') Selecting from multiple tables: (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') Currently selected database: mysql> SELECT DATABASE(); Maximum value: mysql> SELECT MAX(col_name) AS label FROM table; Auto-incrementing rows: mysql> CREATE TABLE table (number INT NOT NULL AUTO_INCREMENT, name CHAR(10) NOT NULL); mysql> INSERT INTO table (name) VALUES ("tom"),("dick"),("harry"); Adding a column to an already-created table: mysql> ALTER TABLE tbl ADD COLUMN [column_create syntax] AFTER col_name; Removing a column: mysql> ALTER TABLE tbl DROP COLUMN col; (Full ALTER TABLE syntax available at mysql.com.) Batch mode (feeding in a script): # mysql -u user -p < batch_file (Use -t for nice table layout and -vvv for command echoing.) Alternatively: mysql> source batch_file; Backing up a database with mysqldump: # mysqldump --opt -u username -p database > database_backup.sql (Use 'mysqldump --opt --all-databases > all_backup.sql' to backup everything.)
rate this doc
email this doc
embed this doc
add to folder
digg reddit stumble delicious
flag this doc
745
74
not rated
0
11/6/2007
English
search termpage on Googletimes searched
Preview

MySQL

honeytech 11/12/2007 | 337 | 24 | 0 | technology
Preview

database scalability with MySQL Cluster

alon 10/5/2007 | 345 | 19 | 0 | technology
Preview

mysql_cheat_sheet[1]

anonymous 2/1/2008 | 165 | 31 | 0 | technology
Preview

MySQL 5.0 Stored Procedures

anonymous 2/1/2008 | 269 | 42 | 0 | technology
Preview

MySQL 5.0 Triggers

anonymous 2/1/2008 | 201 | 28 | 0 | technology
Preview

MySQL Lifecycle Policy

anonymous 2/1/2008 | 151 | 9 | 0 | technology
Preview

How MySQL Powers Web 2.0

anonymous 10/5/2007 | 434 | 63 | 0 | technology
Preview

OpenOffice.org 1.0_ ODBC_ and MySQL 'How-to'

anonymous 2/1/2008 | 154 | 6 | 0 | technology
Preview

mixi Delivers Massive Scale-out with MySQL

anonymous 2/1/2008 | 114 | 1 | 0 | technology
Preview

Web Performance and Scalability with MySQL

alon 10/5/2007 | 751 | 65 | 0 | technology
Preview

MySQL General Information Comparison of Oracle_ MySQL and PostgreSQL DBMS

alon 10/5/2007 | 1049 | 31 | 1 | technology
Preview

Top 84 MySQL Performance Tips

alon 10/5/2007 | 776 | 124 | 0 | technology
Preview

MySQL Presentaion - Optimizing MySQL

alon 10/5/2007 | 238 | 19 | 0 | technology
Preview

MySQL Tornado Database (onetor 1950-2007) Format

NWS 6/30/2008 | 11 | 0 | 0 | legal
Preview

mysql Cheat Sheet Business Document Template Printout

bamafun 1/1/2008 | 408 | 82 | 0 | technology
Preview

All Car Details

ganeshnalawade 6/17/2008 | 89 | 19 | 0 | technology
Preview

Indian Languages cheat sheet

ganeshnalawade 5/19/2008 | 177 | 59 | 0 | educational
Preview

Indian Tourist Place- Western Maharashtra

ganeshnalawade 4/26/2008 | 176 | 19 | 0 |
Preview

MOSS 2007 Installation

ganeshnalawade 4/15/2008 | 493 | 39 | 1 | technology
Preview

Indian Premier League details

ganeshnalawade 4/15/2008 | 260 | 23 | 0 | business
Preview

Vmware VM, ESX, GSX Cheat Sheet

ganeshnalawade 3/26/2008 | 488 | 78 | 0 | technology
Preview

Automotive Terminology

ganeshnalawade 3/18/2008 | 299 | 29 | 0 | educational
Preview

Personal Finance Management Sheet

ganeshnalawade 3/15/2008 | 759 | 151 | 0 | financial
Preview

City Bus routes in Mumbai Metro City

ganeshnalawade 3/15/2008 | 480 | 17 | 1 | creative
Preview

Indian Union Budget Highlights

ganeshnalawade 2/29/2008 | 460 | 10 | 0 | financial
mysql time_diff17
time_diff mysql13
mysql command to delete all rows at a time22
mysql count command42
mysql select backwards12
mysql command update value table11
mysql command to remove a row in table11
select * from [table name] where rec like "^a$";11
mysql command101
mysql command net send71
mysql command for max value11
mysql time_diff()11
mysql command to delete * from table11
select top 10 rec from mysql11
mysql selecting maximum fields31
create table mysql command upload11
add multiple records mysql command11
mysql command select like11
upload database mysql command11
select top 10 * from mysql11
 
review this doc