mysql 基本操作命令

來源:互聯網
上載者:User

1.         查看連接埠

             Netstat –an

2.         登陸mysql伺服器

             Mysql –u root –p         mysql–hlocahost –u root –p

3.         選擇資料庫

            Show databases  

4.         設定字元集

            set names 'gbk';

5.         查詢資料庫中的表

             show tables;

6.      設定字元集

             set names'gbk';

7.     
建立表

          create tabletest(

          tid int(10) not null,

          tname varchar(100) notnull,

          tdate datetime not null default'0000-00-00',

          primary key(tid));

8.         查看錶結構

          desc test;

9.         增加列

          alter table testadd(tage int(3));

10.      修改列的預設值

          alter table test altertag set default '0';

11.    刪除預設值

          alter table test altertag drop default;

12.    刪除列

           alter table test dropcolumn tag;

13.      插入資料

           insert intotest(tid,tname,tdate) value(1,'ymm','2012-11-04');

14.    刪除表

         drop table test;

15.    修改表名

         alter tabletest rename test1;

16.      顯示資料庫版本

          select version();

17.    重新整理資料庫

          flush privileges;

18.    查詢目前時間

           select current_date;

19.    將查詢出的資料寫入檔案

          select * from test1into outfile "F:/test.txt" fields terminated by ",";

20.     查看資料庫狀態

            status;

21.    MySQL基本操作查看所有編碼

           show variables like'character_set_%';

 22.   主鍵設定自子增長

          tid int(10) not null
auto_increment,//設定主鍵的時候 

          alter table auto auto_increment=(10);

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.