MySQL Cheat Sheet - The Essential Commands for MySQL Administration

## Mysql Cheat Sheet ##

install: sudo apt-get install mysql
  lamp stack: sudo tasksel install lamp-server

run: mysql -u root -p

database functions:   show databases;
                      use [database name];
                      create database [database name];
                      drop database [database name];

table functions:      show tables;
                      describe [table name];
                      create table [table name] 

                          ([row1 name] [row1 type],...);
                      drop table [table name];

data functions:       load data local infile 'file path.txt' 

                          INTO TABLE [table name];
                      insert into [table name]

                          values('val1',...);
                      delete from [table name] where [condition];
                      update [table name] set [token] = 

                        [value] where [condition];

user functions:       create user '[username]'@'[hostname]' 

                          identified by '[password]';
                      create user '[username]'@'%' 

                          identified by '[password]';
                      GRANT ALL PRIVILEGES ON [database].[table]

                          TO '[username]'@'[hostname]';
                      GRANT ALL PRIVILEGES ON *.* 

                          TO '[username]'@'[hostname]';
                      revoke ALL PRIVILEGES ON [database].[table]

                          from '[username]'@'[host]';
                      rename user '[username]'@'[hostname]' 

                          to '[username]'@'[hostname]'      

import functions:     load data local infile '[full path]' 

                          into table [table name];

reset password:       /etc/init.d/mysql stop
                      mysqld_safe --skip-grant-tables &
                      mysql -u root
                      mysql> use mysql;
                      mysql> update user set

                          password=PASSWORD("NEW-ROOT-PASSWORD") 
                          where User='root';
                      mysql> flush privileges;
                      mysql> quit
                      /etc/init.d/mysql stop
                      /etc/init.d/mysql start




## Other Good MySQL Cheat Sheets ##
Stephen Scott's MySQL Cheat Sheet 


Nature's Intricacy is Infinite, says the succulent.
 

No comments:

Post a Comment