標籤:類型 localhost char oca value sel mit select default
mysql表操作1,//建立表mysql>Create table usertest(id int(12) primary key not null auto_increment,url varchar(34) not null);2,//改表名mysql>Alter table usertest rename to cmf_usertest;mysql>alter table zm_useroplog day date not null default current_date;3,//插資料mysql>Insert into cmf_usertest (downurl) values (‘dfsafa’);4,//增加主鍵mysql>alter table zm_useroplog add id int auto_increment primary key;5,//加索引mysql> alter table 表名 add index 索引名 (欄位名1[,欄位名2 …]); 例子: mysql> alter table employee add index emp_name (name);6,//刪除某個索引mysql> alter table 表名 drop index 索引名;7,加唯一限制條件的索引mysql> alter table 表名 add unique 索引名 (欄位名);8, 增加欄位mysql> ALTER TABLE table_name ADD field_name field_type; 9, 修改原欄位名稱及類型mysql> ALTER TABLE table_name CHANGE old_field_name new_field_name field_type; 10, 刪除欄位MySQL ALTER TABLE table_name DROP field_name; 11,修改一個欄位mysql> alter table user MODIFY new1 VARCHAR(10); //修改一個欄位的類型mysql> alter table user CHANGE new1 new4 int; //修改一個欄位的名稱,此時一定要重新指定該欄位的類型12,匯出表,設定編碼,限制條數。mysqldump --default-character-set=latin1 -u root -h localhost -ppassword db_name tab_name --where="true limit 10" >> tab_name.sql13,查詢時間戳記顯示時間mysql> select from_unixtime(a.ptime,‘%Y-%m-%d‘) as pdate , a.col as a_cal, b.cal as b_cal from tab1_name a left join tab2_name b on a.id = b.id group by a_col , b_col ;14,插入目前時間now()函數以`yyyy-mm-dd hh:mm:ss返回當前的日期時間,可以直接存到datetime欄位中。curdate()以’yyyy-mm-dd’的格式返回今天的日期,可以直接存到date欄位中。curtime()以’hh:mm:ss’的格式返回當前的時間,可以直接存到time欄位中。
mysql修改表結構