創(chuàng)建用戶(hù)
CREATE?USER?'root'@'%'?IDENTIFIED?BY?'password';
創(chuàng)建用戶(hù)并賦予指定權(quán)限
grant?create,select,update,insert,delete,alter?on?bbs.*?to?lvtao@localhost?identified?by?'password';
創(chuàng)建用戶(hù)并賦予全部權(quán)限
Grant?all?privileges?on?*.*?to?'root'@'%'?identified?by?'password'?with?grant?option;
創(chuàng)建備份用戶(hù)
GRANT?SELECT,RELOAD,SHOW?DATABASES,LOCK?TABLES,EVENT,REPLICATION?CLIENT??ON?*.*?TO?'bak'@'localhost'?IDENTIFIED?BY?'password';
備份所有數(shù)據(jù)庫(kù)
mysqldump?-u?root?-p?--all-databases?--ignore-database=performance_schema?--ignore-database=information_schema?--skip-lock-tables?>?/home/db.sql
導(dǎo)出一個(gè)數(shù)據(jù)庫(kù)結(jié)構(gòu)
mysqldump?-u?root?-p?-d?–add-drop-table?database?>/home/db.sql
恢復(fù)數(shù)據(jù)
A:常用source?命令 進(jìn)入mysql數(shù)據(jù)庫(kù)控制臺(tái), 如mysql?-u?root?-p mysql>use?數(shù)據(jù)庫(kù) 然后使用source命令,后面參數(shù)為腳本文件(如這里用到的.sql) mysql>source?wcnc_db.sql B:使用mysqldump命令 mysqldump?-u?username?-p?dbname?<p>創(chuàng)建數(shù)據(jù)庫(kù)</p><pre class="brush:sql;toolbar:false;">create?database?;
顯示所有的數(shù)據(jù)庫(kù)
show?databases;
刪除數(shù)據(jù)庫(kù)
drop?database?;
選擇數(shù)據(jù)庫(kù)
use?;
查看當(dāng)前使用的數(shù)據(jù)庫(kù)
select?database();
當(dāng)前數(shù)據(jù)庫(kù)包含的表信息:
show?tables;
建表
create?table??(???[,..?]); mysql>?create?table?MyClass( >?id?int(4)?not?null?primary?key?auto_increment, >?name?char(20)?not?null, >?sex?int(4)?not?null?default?'0', >?degree?double(16,2));
獲取表結(jié)構(gòu)
desc?表名,或者show?columns?from?表名 mysql>DESCRIBE?MyClass; mysql>desc?MyClass;? mysql>show?columns?from?MyClass;
刪除表
drop?table? mysql>?drop?table?MyClass;
插入數(shù)據(jù)
insert?into??[(?[,..?])]?values?(?值1?)[,?(?值n?)] mysql>?insert?into?MyClass?values(1,'Tom',96.45),(2,'Joan',82.99),?(2,'Wang',?96.59);
查詢(xún)表中的數(shù)據(jù)
1)、查詢(xún)所有行 命令:?select??from??where? 例如:查看表?MyClass?中所有數(shù)據(jù) mysql>?select?*?from?MyClass;2)、查詢(xún)前幾行數(shù)據(jù) 例如:查看表?MyClass?中前2行數(shù)據(jù) mysql>?select?*?from?MyClass?order?by?id?limit?0,2; 或者: mysql>?select?*?from?MyClass?limit?0,2;
刪除表中數(shù)據(jù)
delete?from?表名?where?表達(dá)式 mysql>?delete?from?MyClass?where?id=1;
修改表中數(shù)據(jù)
update?表名?set?字段=新值,…?where?條件 mysql>?update?MyClass?set?name='Mary'?where?id=1;
在表中增加字段:
alter?table?表名?add字段?類(lèi)型?其他;? mysql>?alter?table?MyClass?add?passtest?int(4)?default?'0'
更改表名:
rename?table?原表名?to?新表名;? mysql>?rename?table?MyClass?to?YouClass;
更新字段內(nèi)容
update?表名?set?字段名?=?新內(nèi)容update?表名?set?字段名?=?replace(字段名,'舊內(nèi)容','新內(nèi)容'); 文章前面加入4個(gè)空格update?article?set?content=concat(' ',content);
更新字段部分字符串
update?contents?set?`text`=REPLACE(text,'http://www.lvtao.net','https://www.lvtao.net')
字段:數(shù)值類(lèi)型
字段:字符串型
字段:日期型
? 版權(quán)聲明
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載。
THE END