mysql在DOS下的操作

來源:互聯網
上載者:User

標籤:

1、串連到本機上的MYSQL。
     首先開啟DOS視窗,然後進入目錄mysql\bin,再鍵入命令mysql -u root -p

     如果剛安裝好MYSQL,超級使用者root是沒有密碼的,故直接斷行符號即可進入到MYSQL中了。

     MYSQL的提示符是: mysql>

2、串連到遠程主機上的MYSQL。假設遠程主機的IP為:110.110.110.110,使用者名稱為root,密碼為abcd123。則鍵入以下命令:
     mysql -h110.110.110.110 -u root -p 123;(注:u與root之間可以不用加空格,其它也一樣)

3、退出MYSQL命令: exit (斷行符號)

4、修改密碼 :mysqladmin -u使用者名稱 -p舊密碼 password 新密碼

     給root加個密碼ab12。首先在DOS下進入目錄mysql\bin,然後鍵入以下命令mysqladmin -u root -password ab12(因為開始時root沒有密碼,所以-p舊密碼就可以省略)

     再將root的密碼改為djg345。mysqladmin -u root -p ab12 password djg345

5、新增使用者名稱:grant select on 資料庫.* to 使用者名稱@登入主機 identified by “密碼”;

     增加一個使用者test1密碼為abc,讓他可以在任何主機上登入,並對所有資料庫有查詢、插入、修改、刪除的許可權。首先用root使用者連入MYSQL,然後鍵入以下命令:

     grant select,insert,update,delete on *.* to [[email protected]”%][email protected]”%[/email]” Identified by “abc”;

     增加一個使用者test2密碼為abc,讓他只可以在localhost上登入,並可以對資料庫mydb進行查詢、插入、修改、刪除的操作(localhost指本地主機)

     這樣使用者即使用知道test2的密碼,他也無法從internet上直接存取資料庫,只能通過MYSQL主機上的web頁來訪問了。
     grant select,insert,update,delete on mydb.* to [[email protected]][email protected][/email] identified by “abc”;

6、建立資料庫:create database <資料庫名> character set utf8;

7、顯示資料庫:show databases;

8、串連資料庫: use databases;

9、當前資料庫資訊: select database();

            select version(); 

          select now(); 

          select dayofmonth(current_date);

            select "welecome to my blog!";

          select ((4 * 4) / 10 ) + 25; 

          select CONCAT(f_name, " ", l_name) ;

10、建立資料表:create table <表名> ( <欄位名1> <類型1> [,..<欄位名n> <類型n>]);

11、修改表名:rename table 原表名 to 新表名;

12、刪除資料表: drop table < 表名 >;

13、表插入資料:insert into <表名> [( <欄位名1>[,..<欄位名n > ])] values ( 值1 )[, ( 值n )];

14、查詢資料:

  查詢多條:select <欄位1,欄位2,...> from < 表名 > where < 運算式 >

  查詢幾行:select * from < 表名 > order by id limit 0,2;

15、刪除表中資料:delete from < 表名 > where 運算式;

16、修改資料:update < 表名 > set 欄位=新值,… where 條件;

17、添加欄位:alter table < 表名 > add 欄位 類型 其他(not null ...);

18、備份資料庫:(匯出檔案預設是存在mysql\bin目錄下)

  命令在DOS的[url=file://\\mysql\\bin]\\mysql\\bin[/url]目錄下執行

  匯出整個資料庫: mysqldump -u 使用者名稱 -p 資料庫名 > 匯出的檔案名稱

      匯出一個表: mysqldump -u 使用者名稱 -p 資料庫名 表名> 匯出的檔案名稱

      匯出一個資料庫結構:mysqldump -u 使用者名稱 -p -d –add-drop-table 資料庫名 > 匯出的檔案名稱(-d 沒有資料 –add-drop-table 在每個create語句之前增加一個drop table)

      帶語言參數匯出:mysqldump -uroot -p –default-character-set=latin1 –set-charset=gbk –skip-opt 資料庫名 > 匯出的檔案名稱

19、刪除資料庫:drop database if exists <資料庫名>;

mysql在DOS下的操作

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.