mysql创建表的时候日期给个默认值_mysql 创建表时 日期字段默认值为当前时间...
mysql 創(chuàng)建表時(shí) 日期字段默認(rèn)值為當(dāng)前時(shí)間
mysql version 5.1
在mysql創(chuàng)建表的時(shí)候經(jīng)常會(huì)遇到創(chuàng)建日期字段需要設(shè)置當(dāng)前時(shí)間為默認(rèn)值的時(shí)候,就如sqlserver2000一樣,把默認(rèn)值設(shè)為getdate()即可,我在網(wǎng)上查了N久都沒(méi)有查到使用有效的方法,最后自己研究了一些方法與大家分享:
數(shù)據(jù)庫(kù):test_db1
創(chuàng)建表:test_ta1
兩個(gè)字段:id????????????? (自增 且為主鍵),
createtime 創(chuàng)建日期(默認(rèn)值為當(dāng)前時(shí)間)
方法一、是用alert table語(yǔ)句:
use test_db1;
create table test_ta1(
id mediumint(8) unsigned not nulll auto_increment,
createtime datetime,
primary key (id)
)engine=innodb default charset=gbk;
alert table test_ta1 change createtime createtime timestamp not null default now();
方法二、直接創(chuàng)建方便:
use test_db1;
create table test_ta1(
id mediumint(8) unsigned not nulll auto_increment,
createtime timestamp not null default current_timestamp,
primary key (id)
)engine=innodb default charset=gbk;
相關(guān)文檔:
第一種方法:
root用戶登錄系統(tǒng)
usr/local/mysql/bin/mysqladmin -u root -p password 新密碼
enter password 舊密碼
第二種方法:
root用戶登錄mysql數(shù)據(jù)庫(kù)
mysql> update mysql.user set password=password("新密碼")where User="root";
mysql> flush privileges;
mysql> quit ;
mysql忘記root密碼如何 ......
完美解決mysql下utf-8的亂碼問(wèn)題
建表時(shí)先加上default charset=utf8;
插入中文數(shù)據(jù)之前(Mysql命令提示符下)是用set names gb2312;
在php頁(yè)面中設(shè)置是mysql_query('SET NAMES UTF8');
在php頁(yè)面(已設(shè)定為utf8后)中插入中文數(shù)據(jù)不會(huì)出現(xiàn)亂碼,應(yīng)該插入數(shù)據(jù)庫(kù)的時(shí)候就是以u(píng)tf8字符集插入中文數(shù)據(jù)的故不會(huì)出現(xiàn)問(wèn)題!
在php ......
為了讓用戶不需要自己運(yùn)行mysql安裝程序安裝mysql數(shù)據(jù)庫(kù),軟件發(fā)布時(shí)需要打包免安裝版本的mysql。從mysql官網(wǎng)上直接下載的免安裝版本需要各種配置,如果配置不好,很容易產(chǎn)生各種各樣的問(wèn)題。尤其是錯(cuò)誤碼為1067的問(wèn)題,我試驗(yàn)了網(wǎng)上的很多方法都沒(méi)起作用,最后想了一個(gè)最簡(jiǎn)單的方法:
(1)首先使用安 ......
query result(14 records)
id
uid
gid
1
11
502
2
107
502
3
100
503
4
110
501
5
112
501
6
104
502
7
100
502
8
100
501
9
102
501
10
104
502
11
100
502
12
100
501
13
102
501
14
110
501
第七條與第十一條重復(fù)等
方法一
mysql> create temporary table tmp_wrap ......
來(lái)源? http://e-xia.com/2009/06/rownum-in-mysql/
在工作中碰到這樣的問(wèn)題,在生成報(bào)表時(shí)第一列要輸出top 1, top 2, ... , top 10。而mysql并不自帶這樣的功能。假設(shè)我們有這樣的一個(gè)表:
mysql> create table tbl (
-> id int primary key,
-> col int
-> );
Query OK, 0 ......
總結(jié)
以上是生活随笔為你收集整理的mysql创建表的时候日期给个默认值_mysql 创建表时 日期字段默认值为当前时间...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: python大神的成长之路_我的Pyth
- 下一篇: linux cmake编译源码,linu