Ubuntu
手动安装遭遇各种困难,实在搞不定,最后装了apt-get的,安装后不知道root用户密码,需要修改 http://www.linuxidc.com/Linux/2012-12/75231.htm
Fedora
以后可以试试,yum
MySQL指令:http://dev.mysql.com/doc/refman/5.7/en/database-use.html
1、数据库和表
show databases;
use DATABASE;
show tables;
create table (if not exists) Stock (exchange ENUM('SH', 'SZ'), symbol CHAR(6), name VARCHAR(20));
# ENUM('SH', 'SZ'): 枚举型
# VARCHAR(20): 长度不同的字符串,20是最大长度,可取1到65535
# CHAR(8): 固定长度的字符串
describe Stock;
drop table (if exists) Stock;
2、插入数据
load data local infile '/tmp/Stock.ms' into table Stock
fields terminated by ' '
(lines terminated by '\r\n');
# 启动mysql时需要加上参数--enable-local-infile才能执行load data
# 数据文件Stock.ms:空值用 \N 表示
insert into Stock values ('SZ', '300300', NULL);
3、查找数据
select (distinct) ?1 from ?2 where ?3;
# distinct: 去重
# ?1: 星号 * 查找所有字段,或用字段名symbol,name,逗号分隔多个字段
# ?2: table name
# ?3: condition
select * from Stock;
select symbol,name from Stock where exchange = 'SZ' and symbol = '000300';
select * from Stock where num >= 0;
select * from Stock where (exchange = 'sh' AND symbol = '600000') OR (exchange = 'sz' AND symbol = '000300');
# AND, OR
3.1 查找+排序
select * from Stock order by symbol (desc),name (desc);
# 排序,默认升序,desc代表降序
# 按多个字段排序时,desc需要写在每个字段后面
3.2 模糊查找
like模式:like/not like
%:表示0或多个字符,中文需用%%表示
_:表示单个字符,中文需用__表示
正则模式:rlike/not rlike/regexp/not regexp
4、删除数据
delete from Stock;
delete from Stock where exchange = 'SH';
delete from Stock where name is NULL;
5、修改数据
update Stock set name = 'chuang' where exchange = 'SZ' and symbol = '300300';
6、日期类型和计算