溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Mysql數(shù)據(jù)庫常用命令總結(jié)

發(fā)布時間:2021-08-09 14:29:41 來源:億速云 閱讀:126 作者:chen 欄目:數(shù)據(jù)庫

本篇內(nèi)容介紹了“Mysql數(shù)據(jù)庫常用命令總結(jié)”的有關(guān)知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

  啟動Mysql數(shù)據(jù)庫

  C:》cdMysql5.0bin

  C:Mysql5.0bin》mysqld–install安裝Mysql服務(wù)

  C:Mysql5.0bin》netstartmysql啟動Mysql服務(wù)

  請求的服務(wù)已經(jīng)啟動。

  連接mysql

  用戶須要提供Mysql的用戶名和密碼來連接服務(wù)器,要是服務(wù)器不是在本機(jī),則還須要一個主機(jī)名或IP來指定服務(wù)器的位子。

  C:Mysql5.0bin》mysql-hlocalhost-uroot-p

  EnterpassWord:****

  WelcometotheMySQLmonitor.Commandsendwith;org.

  YourMySQLconnectionidis6toserverversion:5.0.18-nt

  Type‘help;’or‘h’forhelp.Type‘c’toclearthebuffer.

  mysql》

  使用一條簡單的查詢語句

  mysql》selectversion(),current_date;

  mysql》selectversion();selectnow();

  新建或刪除一個數(shù)據(jù)庫

  Mysql》createdatabasemydb;

  Mysql》dropdatabasemydb;

  打開的數(shù)據(jù)庫的命令

  mysql》usemysql

  Databasechanged

  察看數(shù)據(jù)庫的命令

  mysql》showdatabases;

  查看數(shù)據(jù)表的詳盡結(jié)構(gòu)

  mysql》descfunc;

  新建數(shù)據(jù)庫

  mysql》createdatabaseschool;

  QueryOK,1rowaffected(0.00sec)

  新建表

  mysql》createtableuser01(

  -》idvarchar(20)NOTNULL,

  -》userNamevarchar(10)NOTNULL,

  -》ageint(11)default‘0’,

  -》sexchar(2)NOTNULLdefault‘m’,

  -》PRIMARYKEY(id)

  -》)TYPE=InnoDB;

  QueryOK,0rowsaffected,1warning(0.02sec)mysql》descstudent;

  Mysql數(shù)據(jù)庫常用命令有哪些

  插入和刪除表中的數(shù)據(jù)

  Createtablestudent(stuNamevarchar(20),agevarchar(20),idvarchar(20),set0char(1));

  插入

  mysql》insertintostudent(id,stuName)values(‘1’,‘tomcat’);

  QueryOK,1rowaffected(0.00sec)

  刪除

  mysql》deletefromstudentwhereid=‘1’;

  QueryOK,1rowaffected(0.01sec)

  刪除表中所有數(shù)據(jù)

  mysql》truncatetablestudent;

  QueryOK,1rowaffected(0.01sec)

  刪除表

  mysql》createtabletemp(tvarchar(1));

  QueryOK,0rowsaffected(0.00sec)

  mysql》droptabletemp;

  QueryOK,0rowsaffected(0.00sec)

  創(chuàng)建新用戶并給予權(quán)限

  mysql》grantallprivilegeson*.*todbuser@localhostidentifiedby‘1234’

  withgrantoption;

  更改Mysql用戶密碼

  c:Mysql5.0bin》mysqladmin-uroot-ppassword1234

  Enterpassword:****

  備份數(shù)據(jù)庫及表

  我們用mysqldump命令來備份數(shù)據(jù)庫

  c:mysqlbin》mysqldump–uroot–p3306mysql》d:backup.sql

  執(zhí)行此語句將把mydb備份到D盤的backup.sql文件中

  備份多個數(shù)據(jù)庫表

  c:mysqlbin》mysqldump–uroot–p3306schooluser01user》d:backup.sql

  此句的意思是把school庫中的user01表和user表的內(nèi)容和表的定義備份到D盤backup.sql文件中。

  備份所有的數(shù)據(jù)庫

  c:myqlbin》mysqldump–uroot–p3306–all–database》d:backup.sql

  還原Mysql數(shù)據(jù)庫

  c:mysqlbinmysql–uroot–p3306school

  還原其中的一個表

  mysql》sourced:books.sql;

  ERROR:

  Unknowncommand‘b’。

  QueryOK,0rowsaffected(0.00sec)

  QueryOK,1rowaffected(0.00sec)

  退出Mysql聯(lián)接

  mysql》quit(exit)

  關(guān)閉mysql服務(wù)

  C:mysqlbin》netmysql

“Mysql數(shù)據(jù)庫常用命令總結(jié)”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實用文章!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI