# to connect to the mysqld server on localhost as user root > /usr/local/mysql/bin/mysql -h localhost -u root -p > Password: ********* # to disconnect from the server > QUIT # to view all databases on the server > SHOW databases; # to create a database called 'pet' > CREATE DATABASE pet; # to grant access privileges to a database to a user > GRANT ALL ON pet.* TO gjohnson IDENTIFIED BY 'berries'; > GRANT ALL ON pet.* TO gjohnson@localhost IDENTIFIED BY 'berries'; # to select a database called 'pet' for use > USE pet; # to view all tables in the selected database > SHOW tables; # to create a table in the selected database # NOTE: some common data types are INT, REAL, CHAR, VARCHAR, DATE, BLOB > CREATE TABLE table_name (field_name type, field_name type, ...); # to view the contents of a table > DESCRIBE table_name; # to load the 'pet' table with data from a text file called 'pet.txt' # NOTE: each row in the text file should contain all the values # in each row of the table, separated by tabs or linefeeds. # \N should be used for NULL values. > LOAD DATA LOCAL INFILE 'pet.txt' INTO table pet; # to insert a row into the 'pet' table > INSERT INTO pet -> VALUES ('Puffball', 'Diane', 'hamster', 'f', '1999-03-30', NULL); # to update a row in the 'pet' table > UPDATE pet SET birth = '1989-08-31' WHERE name = 'Bowser'; # to select all columns and rows from the 'pet' table > SELECT * FROM pet; # to select more specifically > SELECT col1 [, col2, col3, ...] -> FROM which_table -> WHERE conditions_to_satisfy; # to select only distinct values > SELECT DISTINCT owner FROM pet; # to sort output in ascending order (default) > SELECT name, birth FROM pet ORDER BY birth; # to sort output in ascending order (default) > SELECT name, birth FROM pet ORDER BY birth DESC; # to sort on multiple columns (in descending order) > SELECT name, species, birth FROM pet ORDER BY species, birth DESC;