mysql基本命令
mysql基本命令
1.show databases; 顯示所有的資料庫
2.use 資料庫名 使用為資料庫名的資料庫
3.show tables 顯示當前資料庫下的所有表
4.desc 表名 查詢表結構
5.create database 資料庫名 建立一個資料庫
6.建立表 create table 表名(
欄位名 欄位屬性,
欄位名 欄位屬性
);
7.alter table 表名 rename 新表名
8.alter table 表名 add 欄位名 欄位屬性 after 欲在哪個欄位後加入 添加列
9.alter table 表名 drop column 欄位名 刪除列
10 alter table 表名 change 原列名 更改後列名 欄位屬性 更改列
11. drop database 資料庫名 刪除一個資料庫
二(1)顯示表記錄 select * from 表名
(2)添加一條記錄 insert into 表名 (欄位1,欄位2)values(值1,值2)
(3)修改一條記錄 update 表明 set 要修改的欄位名=值 where 查詢條件
(4)刪除表中資料 delete from 表明 where 查詢條件
5匯總 select sum(欄位名) from 表名
或 select sum(欄位名) as ‘代名稱’from 表名
sum 總分 avg 平均分 max 最高分 min 最低分
(5)獲得表中的記錄數 select count(*) from 表名
1.精確尋找 select * from 表名 where 條件 如 tid=1
2.模糊尋找 select * from 表名 where 條件 如 name like '%王%'
3.區間搜尋 select * from 表名 where 條件區間 如 s_fenshu between 60 and 90;
4.排序 select * from 表名 where 查詢條件 order by 排序條件 升序或降序
如 select * from 表名 where s_fenshu between 60 and 90 order by s_fenshu desc;
5.分組加排序
select 按什麼分組,sum(欄位名稱) from 表名 group by 按什麼分組 order by 排序條件, 升序或者降序
select s_name,sum(s_fenshu) from new group by s_name order by sum(s_fenshu) desc;
6 當前正在使用的資料庫 select database();
7 當前正在使用的使用者資訊 select user();
三 匯入,匯出mysql
在CMD下,進入你的mysql安裝目錄下的bin目錄
匯出 mysqldump -u 使用者名稱 -p 要匯出的資料庫名>另存的sql檔案名稱
mysqldump -u 使用者名稱 -p cocokiki》d:/cocokiki_sql.sql
匯出表
mysqldump -u 使用者名稱 -p 要匯出的資料庫名 表名>另存的sql檔案名稱
mysqldump -u 使用者名稱 -p cocokiki new》d:/cocokiki_sql.sql
只匯出表結構
mysqldump -u 使用者名稱 -p -d -add 要匯出的資料庫名 表名>另存的sql檔案名稱
mysqldump -u 使用者名稱 -p -d -add cocokiki new》d:/cocokiki_sql.sql
匯入表
首先建立表,mysqladmin -u 使用者名稱 -p create 資料庫名
mysqladmin -u 使用者名稱 -p create test
mysql -u 使用者名稱 -p 匯入的資料庫名<源檔案名稱
mysql -u 使用者名稱 -p test<d:/cocokiki_sql.sql