insert into newtable select * from oldtable where id>1000000;
可以现实两个相同表结构之间的数据转移;
外部SQL文件执行导入
cat a.sql | mysql -uroot -p --default-character-set=gbk database
ex: cat ihome.2011-01-12.sql | mysql -u root --default-character-set=gbk -p ihome_wtj
外部选择导入字符集
进入mysql命令行界面,选择与导入表相同的字符集。source filename 导入数据;
--default-character-set = gbk;
将刚执行过的SQL语句及输出结果写入到一个文件中方便处理;
mysql界面命令行下使用:tee filename;
select unix_timestamp(); 获取当前时间;秒;
FROM_UNIXTIME(createtime,'%Y-%m-%d %H:%i:%s'); 当前字段年月日 时分秒;
%M 月名字(January……December)
%W 星期名字(Sunday……Saturday)
%D 有英语前缀的月份的日期(1st, 2nd, 3rd, 等等。)
%Y 年, 数字, 4 位
%y 年, 数字, 2 位
%a 缩写的星期名字(Sun……Sat)
%d 月份中的天数, 数字(00……31)
%e 月份中的天数, 数字(0……31)
%m 月, 数字(01……12)
%c 月, 数字(1……12)
%b 缩写的月份名字(Jan……Dec)
%j 一年中的天数(001……366)
%H 小时(00……23)
%k 小时(0……23)
%h 小时(01……12)
%I 小时(01……12)
%l 小时(1……12)
%i 分钟, 数字(00……59)
%r 时间,12 小时(hh:mm:ss [AP]M)
%T 时间,24 小时(hh:mm:ss)
%S 秒(00……59)
%s 秒(00……59)
%p AM或PM
%w 一个星期中的天数(0=Sunday ……6=Saturday )
%U 星期(0……52), 这里星期天是星期的第一天
%u 星期(0……52), 这里星期一是星期的第一天
%% 一个文字“%”。
使用MYSQL语句解释时间戳语法举例:
SELECT FROM_UNIXTIME(1234567890, '%Y-%m-%d %H:%i:%S')
select unix_timestamp();//获得一个时间戳; 内可传正规日期时间参数转换
mysql - 某个字段广西类型的进行整体替换:
update jia_local_information set content=replace(content,"\n","<br />") where content like '%\n%';
update {tablename} set pathurl=replace(pathurl,"http:\/\/img.moke.com","") where pathurl like '%img.moke.com%';
mysql - 多表统计查询:
select s.id,s.is_working from ship s where exists (select ship_id,count(ship_id) as c from order_ship os where s.id=os.ship_id group by os.ship_id);
mysql - 多表统计修改:
update ship s set is_working=(select count(ship_id) as c from order_ship os where s.id=os.ship_id group by os.ship_id) where exists (select ship_id,count(ship_id) as c from order_ship os where s.id=os.ship_id group by os.ship_id);