Setting up and using MySQL

by Walt Stoneburner
v1.1
"You wouldn't believe how many times I've forgotten this stuff."

Shutting down MySQL:
$ mysqladmin -u root -p shutdown

Starting MySQL:
# cd /usr/local/mysql
# bin/safe_mysql &

Creating a new database:
$ mysqladmin -u root -p create new_database_name

Granting Permissions:

mysql> GRANT DELETE, INSERT, ALTER, SELECT, UPDATE, CREATE, DROP, INDEX
  ON DatabaseName.* TO username@localhost IDENTIFIED BY 'password';
mysql> flush privileges;
Typically you want to do yourself, root, and whatever user you run the the web server as. Optionally, you may wish to restrict which tables are accessable rather than just using *.

Database names are case sensitive. To list them:
mysql> show databases;

To select a database:
mysql> use DatabaseName;

To see what tables are in a database:
mysql> show tables;

To see what makes up a given table:
mysql> describe TableName;

To create a database:
mysql> create database DatabaseName;

To add a table:
mysql> create table TableName ( colname coltype( precision ), ... );

To add a column:
mysql> alter table TableName ADD COLUMN ( column defintion );


SlingCode Search Results About     Articles     Links     Search Tips  
SEARCH: