1、系統(tǒng)管理
mysql -h主機(jī)地址 -u用戶名 -p
連接MYSQL(在mysql/bin)
exit
退出MYSQL命令
mysqladmin -u用戶名 -p舊密碼 password新密碼
修改密碼(在mysql/bin)
grantselect[insert][,update][,delete]on數(shù)據(jù)庫.*to用戶名@localhost("%", 表示任何主機(jī))identifiedby "密碼"
增加用戶
mysqldump –u root –p opt數(shù)據(jù)庫名>備份文件名
備份數(shù)據(jù)庫(在mysql/bin)
mysql –u root –p < batchfile (例如備份文件名)
使用批處理
mysql.server start
啟動服務(wù)器
mysql.server stop
停止服務(wù)器
msql.serverlog
2、查詢命令
select version()
查詢版本號
select current_date
查詢當(dāng)前日期
3、顯示命令
show databases
顯示數(shù)據(jù)庫列表
show tables 顯示庫中的數(shù)據(jù)表
describe 表名 顯示數(shù)據(jù)表的結(jié)構(gòu)
select * from 表名 顯示表中的記錄
select what_to_select from which table [whereconditions_to_satisfy and (or) where conditions_to_satisfy] 從一個表中檢索數(shù)據(jù)『滿足條件』
select 字段1,字段2,… from 表名 顯示特定列的值
select * from 表名 order by 字段名 排序行
select 字段1,包含字段2的運(yùn)算式as 新字段 from 表名 字段值運(yùn)算操作
select 字段1 is null(is not null) 空值操作
Select*from表名where字段名like(not like) “ 字符”
注: 允許使用“_”匹配任何單個字符, 而“%” 匹配任意數(shù)目字符 模式匹配
Select * from表名where字段名regexp(not regexp)或者rlike(not rlike) “.”匹配任何單個的字符 一個字符類[…]匹配方框內(nèi)任何字符。例如[a],[asd],[az] 匹配任何小寫字母,[09] 匹配任何數(shù)
字。 “*”匹配零個或者多個在它前面的東西。 正則表達(dá)式區(qū)分大小寫[aA] 。 如果它出現(xiàn)在被測試值的任何地方,模式都匹配。 定位,在模式開始處用“^”,結(jié)尾處用“$”,例如“^b”
擴(kuò)展正則表達(dá)式
Select count(*) from 表名
Select 字段名,count(*) from 表名 group by 字段名 行計數(shù)
4、編輯命令
use database 庫名
使用的數(shù)據(jù)庫
create database 庫名
創(chuàng)建數(shù)據(jù)庫
create table 表名
在數(shù)據(jù)庫中創(chuàng)建表
insert into表名values (“data”,”data”)
向表中添加記錄
Load data infile “/path/filename” intotable 表名
從文件中向表添加數(shù)據(jù), 文件每行包括一條記錄, 用定位符(tab) 把值分開。
drop database 庫名
刪除數(shù)據(jù)庫
drop table 表名
刪除數(shù)據(jù)庫中的表
delete from表名where
刪除數(shù)據(jù)庫表中的記錄
Update表名set字段=”值” wherewhereconditions_to_satisfy
更新數(shù)據(jù)庫表中記錄的值