Handy MySQL Commands
Handy MySQL Commands
Description
Command
show databases;
Switch to a
database.
To delete a db.
To delete a table.
Returns the
columns and
column information show columns from [table name];
pertaining to the
designated table.
Show certain
selected rows with
SELECT * FROM [table name] WHERE [field name] = "whatever";
the value
"whatever".
Show all records
containing the
name "Bob" AND
the phone number
'3444444'.
Show all records
not containing the
name "Bob" AND
the phone number
'3444444' order by
the phone_number
field.
Show all records
starting with the
letters 'bob' AND
the phone number
'3444444'.
Use a regular
expression to find
records. Use
"REGEXP
BINARY" to force SELECT * FROM [table name] WHERE rec RLIKE "^a$";
case-sensitivity.
This finds any
record beginning
with a.
Show unique
records.
Show selected
records sorted in an
SELECT [col1],[col2] FROM [table name] ORDER BY [col2] DESC;
ascending (asc) or
descending (desc).
Count rows.
Change a users
password.(from
MySQL prompt).
Switch to mysql
db.Give user
(Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_pri
privilages for a db. v,Drop_priv) VALUES ('%','db','user','Y','Y','Y','Y','Y','N');
To update info
already in a table.
Delete a row(s)
from a table.
Update database
permissions/privila FLUSH PRIVILEGES;
ges.
Delete a column.
alter table [table name] change [old column name] [new column name]
varchar (50);
Make a unique
column so you get alter table [table name] add unique ([column name]);
no dupes.
Make a column
bigger.
VARCHAR(255));
Create Table
Example 2.