
日期:2008-06-20 作者:喜騰小二 來源:PHPChina
啓動:net start mySql;
進入:mysql -u root -p/mysql -h localhost -u root -p databaseName;
列出資料庫:show databases;
選擇資料庫:use databaseName;
列出表格:show tables;
顯示表格列的內容:show columns from tableName;
建立資料庫:source fileName.txt;
比對字元:可以用萬用字元_代表任何一個字元,%代表任何字串;
增加一個欄位:alter table tabelName add column fieldName dateType;
增加多個欄位:alter table tabelName add column fieldName1 dateType,add columns fieldName2 dateType;
多行指令輸入:注意不能將單字斷開;當插入或變更資料時,不能將欄位的字串展開到多行裡,否則硬回車將被儲存到資料中;
增加一個管理員帳戶:grant all on *.* to user@localhost identified by "password";
每條陳述式輸入完畢後要在末尾填加分號';',或者填加'g'也可以;
查詢時間:select now();
查詢當前使用者:select user();
查詢資料庫版本:select version();
查詢當前使用的資料庫:select database();
1、移除student_course資料庫中的students資料表:
rm -f student_course/students.*
2、備份資料庫:(將資料庫test備份)
mysqldump -u root -p test>c:est.txt
備份表格:(備份test資料庫下的mytable表格)
mysqldump -u root -p test mytable>c:est.txt
將備份資料匯入到資料庫:(導回test資料庫)
mysql -u root -p test
3、建立暫時表:(建立暫時表zengchao)
create temporary table zengchao(name varchar(10));
4、建立表是先判斷表是否存在
create table if not exists students(……);
5、從已經有的表中複製表的結構
create table table2 select * from table1 where 1<>1;
6、複製表
create table table2 select * from table1;
7、對表重新命名
alter table table1 rename as table2;
8、修改列的類型
alter table table1 modify id int unsigned;//修改列id的類型為int unsigned
alter table table1 change id sid int unsigned;//修改列id的名字為sid,而且把內容修改為int unsigned
9、建立索引
alter table table1 add index ind_id (id);
create index ind_id on table1 (id);
create unique index ind_id on table1 (id);//建立唯一性索引
10、移除索引
drop index idx_id on table1;
alter table table1 drop index ind_id;
11、聯合字元或者多個列(將列id與":"和列name和"="連線)
select concat(id,':',name,'=') from students;
12、limit(選出10到20條)<第一個記錄集的編號是0>
select * from students order by id limit 9,10;
13、MySQL不支援的功能
事務,視圖,外鍵和引用完整性,存儲過程和觸發器
14、MySQL會使用索引的運運算元號
<,<=,>=,>,=,between,in,不帶%或者_開頭的like