MySQL

Cheat Sheet
Add column to existing table : ALTER TABLE contacts ADD email VARCHAR(60); Update value                : UPDATE example SET age='22' WHERE age='21' Retrieve data               : select fields from tablename where field='value'; Regular expressions         : select * from messages where name regexp "[Bb]and?ana.*"; Create database             : create database newdatabase; Create user                 : grant all on newdatabase.* to 'user'@'localhost' identified by 'somepassword'; Update password             : SET PASSWORD FOR 'user'@'localhost' = PASSWORD('newpassword'); Create table                : CREATE TABLE events (                                   id int not null auto_increment,                                   time datetime,                                   title varchar(255) default 'no title',                                   description text,                                   primary key(id)                                ); Insert value into table     : insert into events values (0,                                   '2006-03-25 19:59:59', 'example',                                   'This is an example'); Adjust date                 : UPDATE gamelog_entries SET datetime = addtime(datetime, '-03:00:00') WHERE datetime > '2013-06-16';"

Renaming a Database

 * 1) cd /var/lib/mysql
 * 2) mv name newname

Command-line mysql
$ mysql database -uusername -p

Backup of schmid.wiki Database
Backup: Restore: mysql> create database wikidb;
 * 1) mysqldump --opt -uwikiuser -ppassword wikidb | bzip2 -c >schmid.wiki.sql.bz2
 * 1) bunzip2 schmid.wiki.sql.bz2
 * 2) mysql -uroot -p
 * 1) mysql -uroot -p  wikidb < schmid.wiki.sql