Mysql文集
导入数据指定列
load data local infile 'D:\\service_func_utf8.txt' into table service_func fields terminated by '\t' (service_id, func_id1, func_id2, func_id3, func_id4, func_id5, func_id6);
MYSQL将查询结果导出到文件
select * from tablename into outfile '/tmp/test.txt';
MYSQL联合主键
create table oldmail(
id varchar(200) not null,
username varchar(255) not null ,
primary key(id,username)
)
3 mysql的主键问题:
Mysql的两种主键。Primary key 和not null auto_incriment在建立mysql表时,给一个字段添加了主键primary key 在insert数据时可以不用insert主键,mysql会自动添加0,但是在第二次insert时没有填写值mysql数据库还是默认添加0,会导致有重复的主键,这是不可以的。所有在定义了primary key时,在insert数据时要给主键填写值。在建立mysql表时,给一个字段添加了主键not null auto_increment=1;这也是一个主键。时自增长的以1为开始。这个字段是可以不用填写值的,mysql数据库会自动给填写值,不会出现primary key的状况。Alter table tb add primary key(id);Alter table tb change id id int(10) not null auto_increment=1;
4 删除自增长的主键id先删除自增长在删除主键
Alter table tb change id id int(10);//删除自增长
Alter table tb drop primary key;//删除主建
重命名表
ALTER TABLE 旧表名 RENAME TO 新表名;
相关文档:
mysql 导出表:
mysqldump -u 用户名 -p --opt 数据库用户名 表名
> 表名.sql
mysql 导出数据库:
mysqldump -u
用户名 -p --opt 数据库用户名
>
数据库
名.sql
mysql 导入表:
>source e:\base\pet.sql;
mysql 导入表数据:
>LOAD DATA LOCAL INFILE 'e:path/pet.txt ......
http://www.itlearner.com/article/2009/4325.shtml
这次是Fotolog
的经验,传说中比Flickr更大的网站
,Fotolog在21台服务
器上部署了51个memcached实例,总计有254G缓存空间可用,缓存了多达175G的内容,这个数量比很多网站的数据库都要大的多,原文是A Bunch of Great Strategies for Using Memcached and MySQL Bet ......
MySQL语句优化的基本原则:
◆1、使用索引来更快地遍历表。
缺省情况下建立的索引是非群集索引,但有时它并不是最佳的。在非群集索引下,数据在物理上随机存放在数据页上。合理的索引设计要建立在对各种查询的分析和预测上。一般来说:
a.有大量重复值、且经常有范围查询( > ,< ,> =,< ......
BLOB
TEXT
一个BLOB或TEXT列,最大长度为65535(2^16-1)个字符。
MEDIUMBLOB
MEDIUMTEXT
一个BLOB或TEXT列,最大长度为16777215(2^24-1)个字符。
LONGBLOB
LONGTEXT
一个BLOB或TEXT列,最大长度为4294967295(2^32-1)个字符。
可通过修改php.ini文件,改变最大长度设置。
; Valid range 0 - 2147483647.  ......
显示所有数据库 show databases;
创建数据库 create dababase stu;
删除数据库drop database stu;
切换到数据库use stu;
取得当前的数据库,带()表示函数:select database();
创建表(要切换到数据库中)
mysql> create table stu_info(
-> stu_id int(8) ......