ts4z.net > mysql cheatsheet Y! site search:   

mysql cheatsheet

This is a collection of everything I've learned about MySQL, then forgotten and had to look up again. Which is a lot.

typical use

describe TABLE;
show the layout of a table
drop table TABLE;
throw out a whole table
select * from TABLE
get all data from a table
select * from TABLE1 natural join TABLE2;
Select from two tables, doing a "natural join" on any columns with the same name
insert into TABLE values (VALUE1, VALUE2, ...);
insert a new row into a table
update TABLE set WHAT where WHERE-CLAUSE
update TABLE, changing WHAT values in wherever WHERE-CLAUSE matches
grant select, insert, update, delete on DATABASE.* to 'USER@'localhost' identified by 'PASSWORD'
grant rights on a database—doing so creates a user
UPDATE mysql.user SET Password=PASSWORD('PASSWORD') WHERE User='USER';
change a password
create table TABLENAME (COLUMN serial);
Create a new table. serial is an alias for bigint key auto_increment not null.

how to reset the root password of a mysql installation

Restart mysqld with the --skip-grant-tables option, which disables access control. Then, see above.


tjs@psaux.com &mdash last modified by tjs at Tue Dec 26 00:20:04 2006