9/22/2010

Mysql query command

-Use regular expressions in MySQL SELECT statements :

MySQL allows the following regular expression metacharacters

. match any character
? match zero or one
* match zero or more
+ match one or more
{n} match n times
{m,n} match m through n times
{n,} match n or more times
^ beginning of line
$ end of line
[[:<:]] match beginning of words [[:>:]] match ending of words
[:class:] match a character class
i.e., [:alpha:] for letters
[:space:] for whitespace
[:punct:] for punctuation
[:upper:] for upper case letters
[abc] match one of enclosed chars
[^xyz] match any char not enclosed
| separates alternatives

Etc.
SELECT * FROM events WHERE id REGEXP '5587$'
SELECT * FROM reviews WHERE description REGEXP '[[:<:]]excellent[[:>:]]'
SELECT something FROM table WHERE column REGEXP 'regexp'

-Describe the column structure of a MySQL table :
describe tablename;

-Display a list of databases on a MySQL server :
show databases;

-Change the MySQL root user password :
#mysqladmin -u root password PaSsWoRd