2008年3月2日 星期日

mysql command

start mySQL:
sudo /usr/local/mysql/bin mysqld_safe

stop mySQL:
sudo /usr/local/mysql/bin mysqladmin shutdown

create an account:
mysql -h localhost -p -u root
GRANT ALL ON*.* TO'deeplove'@'localhost'IDENTIFIED BY'111';
create new user account "deeplove", with password 111,
connect to database from "localhost", ALL means you can do anything( SELECT, INSERT, ...)
*.* means you can connect to every database ( Dog.* means you can only connect to Dog database)

connect to database:
mysql -h localhost -p -u deeplove
-h means host, connect to localhost
-p means password , -u means user

create database:
ex: CREATE DATABASE dog;

create table:
mysql> USE dog;
mysql> CREATE TABLE dogTable (thing VARCHAR(20), legs INT, arms INT);
mysql> INSERT INTO dogTable (thing,legs,arms) VALUES('human',2,2);
mysql> INSERT INTO dogTable (thing,legs,arms) VALUES('insect',6,0);
use dog means use database "dog"

dogTable is the name of table
The table has three field, thing, legs, and arms

leave mysql:
QUIT

which is current database:
SELECT database();

show database information
\s

show tables
show tables in this database

show databases
show databases

show columns from books
show columns of table books

describe books
describe table books

select * from books
show the content of table books

delete from books where title='story';
delete the records with title = 'story' from table books

沒有留言: