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后的命令行是这个样子的:
warmbupt@pchuang:/windows/MyCode/SS$ mysql -u root -ppassw0rd
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 37
Server version: 5.1.37-1ubuntu5.1 (Ubuntu)
Type 'help;' or '\h' for help. Type '\c' to clear the curr ......
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 ......
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.  ......
<?php
/*
* 名称 : MySQL数据库基本操作
* 作者 : pjx
* 版本 : v 2010/02/25 v 1.0
* 说明 : 该类用于对MySQL做一些简单的操作
* 示例 :
* 实例 => $db = new DB_MYSQL($database),打个$database数据库
* 查询数据库 => $db->query($sql_str),查询$sql_st ......
做项目时由于业务逻辑的需要,必须对数据表的一行或多行加入行锁,举个最简单的例子,图书借阅系统。假设
id=1
的这本书库存为
1
,但是有
2
个人同时来借这本书,此处的逻辑为
Select restnum from book where id =1 ;
-- 如果 restnum 大于 0 ,执行 update
Update boo ......