1.複製表結構和數據,可是不復制索引和外鍵:node
- create table a select * from b;
2.複製表結構和索引和外鍵,不復制數據:
3.只複製數據:
- insert into a select * from b;
4.移動表到另外一個庫
5.刪除重複記錄
- --新建一個臨時表
- create table tmp as select * from youtable group by name ;
- --刪除原來的表
- drop table youtable ;
- --重命名錶
- alter table tmp rename youtable;
- --新建一個臨時表
- create table tmp like youtable;
- --取出不重複的數據
- insert into select * from youtable group by name;
- --清空原來的表
- truncate youtable;
- --插入原來的表
- insert into youtable select * from tmp;
- --重命名錶
- drop table tmp;
6.重命名數據庫
到/var/lib/mysql/
修改對應數據庫的文件夾名便可
7.時間格式
- SELECT FROM_UNIXTIME( 1249488000,'%Y-%m-%d %H:%i:%s') ;
- SELECT DATE_FORMAT('1997-10-04 22:23:00', '%Y-%m-%d %H:%i:%s');
- SELECT UNIX_TIMESTAMP('2009-08-06') ;
8.mysql日誌
- --查看日誌
- show binary logs;
- show master logs;
- --清除日誌
- PURGE MASTER LOGS TO 'mysql-bin.000035';
- --手動刪除10天前的mysql binlog日誌
- PURGE MASTER LOGS BEFORE DATE_SUB(CURRENT_DATE, INTERVAL 10 DAY);
9.得到更新記錄數
10.得到找到的記錄數
11.得到插入的id
12.建立特殊表名
- SET sql_mode='ANSI_QUOTES';
- create table "a-b" (a int);
13.插入不重複數據
- insert into node (name) select 'a' where no exists(select id from node where id=2 and name='a')
14.uuid
- select replace(uuid(), '-', '');
15.添加一個遠程用戶,名爲username密碼爲password
- GRANT ALL PRIVILEGES ON *.* TO username@"%" IDENTIFIED BY 'password' WITH GRANT OPTION;
16.從文件導入數據
- LOAD DATA INFILE '/tmp/result100.txt' INTO TABLE analy_ip_file2 FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';
17.添加主鍵
- alter table userconfig add id int(4) auto_increment primary key;
18.查看mysql參數
- show variables like '%max%';
end