1:使用SHOW語句找出在伺服器上當前存在什麼資料庫:
mysql> SHOW DATABASES;
2:2、建立一個資料庫MYSQLDATA
mysql> CREATE DATABASE MYSQLDATA;
3:選擇你所建立的資料庫
mysql> USE MYSQLDATA; (按斷行符號鍵出現Database changed 時說明操作成功!)
4:查看現在的資料庫中存在什麼表
mysql> SHOW TABLES;
5:建立一個資料庫表
mysql> CREATE TABLE MYTABLE (name VARCHAR(20), sex CHAR(1));
6:顯示表的結構:
mysql> DESCRIBE MYTABLE;
7:往表中加入記錄
mysql> insert into MYTABLE values (”hyq”,”M”);
8:用文本方式將資料裝入資料庫表中(例如D:/mysql.txt)
mysql> LOAD DATA LOCAL INFILE “D:/mysql.txt” INTO TABLE MYTABLE;
9:匯入.sql檔案命令(例如D:/mysql.sql)
mysql>use database;
mysql>source d:/mysql.sql;
10:刪除表
mysql>drop TABLE MYTABLE;
11:清空表
mysql>delete from MYTABLE;
12:更新表中資料
mysql>update MYTABLE set sex=”f” where name=’hyq’;
13.查詢時間:select now();
查詢目前使用者:select user();
查詢資料庫版本:select version();
查詢當前使用的資料庫:select database();
14、刪除student_course資料庫中的students資料表:
rm -f student_course/students.*
15、備份資料庫:(將資料庫test備份)
mysqldump -u root -p test>c:\test.txt
備份表格:(備份test資料庫下的mytable表格)
mysqldump -u root -p test mytable>c:\test.txt
將備份資料匯入到資料庫:(導回test資料庫)
mysql -u root -p test<c:\test.txt
16、建立暫存資料表:(建立暫存資料表zengchao)
create temporary table zengchao(name varchar(10));
17、建立表是先判斷表是否存在
create table if not exists students(……);
18、從已經有的表中複製表的結構
create table table2 select * from table1 where 1<>1;
19、複製表
create table table2 select * from table1;
20、對錶重新命名
alter table table1 rename as table2;
21、修改列的類型
alter table table1 modify id int unsigned;//修改列id的類型為int unsigned
alter table table1 change id sid int unsigned;//修改列id的名字為sid,而且把屬性修改為int unsigned
22、建立索引
alter table table1 add index ind_id (id);
create index ind_id on table1 (id);
create unique index ind_id on table1 (id);//建立唯一性索引
23、刪除索引
drop index idx_id on table1;
alter table table1 drop index ind_id;
24、聯合字元或者多個列(將列id與":"和列name和"="串連)
select concat(id,':',name,'=') from students;
25、limit(選出10到20條)<第一個記錄集的編號是0>
select * from students order by id limit 9,10;
26、MySQL不支援的功能
事務,視圖,外鍵和參考完整性,預存程序和觸發器