mysql常識和基本操作

來源:互聯網
上載者:User
mysql 欄位類型  
   1.INT[(M)]  

   正常大小整數類型

   2.DOUBLE[(M,D)] [ZEROFILL]  

   正常大小(雙精密)浮點數字類型

   3.DATE  

   日期類型。支援的範圍是'1000-01-01'到'9999-12-31'。MySQL以'YYYY-MM-DD'格式來顯示DATE值,但是允許你使用字串或數字把值賦給DATE列

   4.CHAR(M)  

   定長字串類型,當儲存時,總是是用空格填滿右邊到指定的長度

   5.BLOB TEXT  

   BLOB或TEXT類型,最大長度為65535(2^16-1)個字元。

   6.VARCHAR

   變長字串類型。  

   1: 顯示資料庫  
   
   SHOW DATABAS,  

   2:當前選擇的資料庫,  

   mysql> SELECT DATABASE();  
   +------------+  
   | DATABASE() |  
   +------------+  
   | test ;  
   +------------+  
   | DATABASE() |  
   +------------+  
   | test    |  
   +------------+  

   當前資料庫包含的表資訊:  

   mysql> SHOW TABLES;  
   +---------------------+  
   | Tables in test   
   mysql> SHOW TABLES;  
   +---------------------+  
   | Tables in test   |  
   +---------------------+  
   | mytable1      |  
   | mytable2      |  
   +---------------------+  

   擷取表結構  

   mysql> desc mytable1;  
   +---------+-------------+------+-----+---------+-------+  
   | Field  mysql> desc mytable1;  
   +---------+-------------+------+-----+---------+-------+  
   | Field  | Type  | Null | Key | Default | Extra |  
   +---------+-------------+------+-----+---------+-------+  
   | s1  | varchar(20) | YES |NULL  |    |  
   +---------------------+------+-----+---------+-------+  



   5.匯入資料庫表  
   (1)建立.sql檔案

   (2)先產生一個庫如auction.c:mysqlbin>mysqladmin -u root -p creat auction,會提示輸入密碼,然後成功建立。

   (2)匯入auction.sql檔案

   c:mysqlbin>mysql -u root -p auction < auction.sql。

   通過以上操作,就可以建立了一個資料庫auction以及其中的一個表auction。

   6.修改資料庫

   (1)在mysql的表中增加欄位:

   alter table dbname add column userid int(11) not null primary key auto_increment;

   這樣,就在表dbname中添加了一個欄位userid,類型為int(11)。

   7.mysql資料庫的授權

   mysql>grant select,insert,delete,create,drop

   on *.* (或test.*/user.*/..)

   to 使用者名稱@localhost

   identified by '密碼';

   如:建立一個使用者帳號以便可以訪問資料庫,需要進行如下操作:

   mysql> grant usage

   -> ON test.*
   -> TO testuser@localhost;
   Query OK, 0 rows affected (0.15 sec)

   此後就建立了一個新使用者叫:testuser,這個使用者只能從localhost串連到資料庫並可以串連到test 資料庫。下一步,我們必須指定testuser這個使用者可以執行哪些操作:

   mysql> GRANT select, insert, delete,update
   -> ON test.*
   -> TO testuser@localhost;
   Query OK, 0 rows affected (0.00 sec)

   此操作使testuser能夠在每一個test資料庫中的表執行SELECT,INSERT和DELETE以及UPDATE查詢操作。現在我們結束操作並退出MySQL客戶程式:

   mysql> exit
   Bye  


聯繫我們

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