Chinaunix首页 | 论坛 | 博客
  • 博客访问: 198907
  • 博文数量: 69
  • 博客积分: 1400
  • 博客等级: 上尉
  • 技术积分: 720
  • 用 户 组: 普通用户
  • 注册时间: 2005-08-03 11:35
文章分类

全部博文(69)

文章存档

2011年(13)

2010年(46)

2009年(10)

我的朋友

分类: Mysql/postgreSQL

2009-12-17 14:28:46

MySql 091217: General Cmd

@ http://zcatt.cublog.cn

1.    Connect and Disconnect

mysql -h host -u user -p

mysql -u user -p

 

h

Hostname or IP

u

user name

p

password

 

select version(), current_date;

select now();

select user();

2. Creating DB

show databases;

 

create databases dbname;

 

use dbname

 

show tables;

 

CREATE TABLE pet (name VARCHAR(20), owner VARCHAR(20),

species VARCHAR(20), sex CHAR(1), birth DATE, death DATE);

 

DESC pet;

 

LOAD DATA LOCAL INFILE '/path/pet.txt' INTO TABLE pet

LINES TERMINATED BY '\r\n';

 

INSERT INTO pet

 VALUES ('Puffball','Diane','hamster','f','1999-03-30',NULL);

 

 

DELETE FROM pet;

LOAD DATA LOCAL INFILE 'pet.txt' INTO TABLE pet;

 

UPDATE pet SET birth = '1989-08-31' WHERE name = 'Bowser';

 

3.  Select sentence

SELECT what_to_select

FROM which_table

WHERE conditions_to_satisfy;

 

SELECT name, birth FROM pet ORDER BY birth;

 

SELECT name, species, birth FROM pet

 ORDER BY species, birth DESC;

 

SELECT * FROM pet WHERE name LIKE 'b%';

 

SELECT * FROM pet WHERE name LIKE '_____';

 

SELECT * FROM pet WHERE name REGEXP 'fy$';

 

SELECT * FROM pet WHERE name REGEXP '^.....$';

 

SELECT owner, COUNT(*) FROM pet GROUP BY owner;

 

SELECT p1.name, p1.sex, p2.name, p2.sex, p1.species

 FROM pet AS p1 INNER JOIN pet AS p2

 ON p1.species = p2.species AND p1.sex = 'f' AND p2.sex = 'm';

 

 

4. Get info

SELECT DATABASE();

 

SHOW TABLES;

 

DESCRIBE pet;

 

 

5. Batch Mode

mysql> source filename;

 

 

 

 

 

阅读(1056) | 评论(0) | 转发(0) |
0

上一篇:MySql 091216: Install(2/2)

下一篇:RPM命令简记

给主人留下些什么吧!~~