mysql常識和基本操作
2024-07-24 12:55:16
供稿:網友
字段類型
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 [email protected];
query ok, 0 rows affected (0.15 sec)
此后就創建了一個新用戶叫:testuser,這個用戶只能從localhost連接到數據庫并可以連接到test 數據庫。下一步,我們必須指定testuser這個用戶可以執行哪些操作:
mysql> grant select, insert, delete,update
-> on test.*
-> to [email protected];
query ok, 0 rows affected (0.00 sec)
此操作使testuser能夠在每一個test數據庫中的表執行select,insert和delete以及update查詢操作?,F在我們結束操作并退出mysql客戶程序:
mysql> exit
bye
本文來源于網頁設計愛好者web開發社區http://www.html.org.cn收集整理,歡迎訪問。