1、顯示數據庫
show databases;
2、選擇數據庫
use
數據庫名;
3、顯示數據庫中的表
show tables;
4、顯示數據表的結構
?
describe 表名;
?
5、顯示表中記錄
?
SELECT * FROM 表名
?
6、建庫
create
databse 庫名;
?
7、建表
?
create table 表名 (字段設定列表); mysql > create table name( -> id int auto_increment not null primary key , -> uname char ( 8 ), -> gender char ( 2 ), -> birthday date ); Query OK, 0 rows affected ( 0.03 sec) mysql > show tables; + -- ----------------+ | Tables_in_userdb | + -- ----------------+ | name | + -- ----------------+ 1 row in set ( 0.00 sec) mysql > describe name; + -- --------+---------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | + -- --------+---------+------+-----+---------+----------------+ | id | int ( 11 ) | NO | PRI | NULL | auto_increment | | uname | char ( 8 ) | YES | | NULL | | | gender | char ( 2 ) | YES | | NULL | | | birthday | date | YES | | NULL | | + -- --------+---------+------+-----+---------+----------------+ 4 rows in set ( 0.00 sec) 注: auto_increment 自增 primary key 主鍵
?
8、增加記錄
insert into name(uname,gender,birthday) values ( ' 張三 ' , ' 男 ' , ' 1971-10-01 ' );
?
9、修改記錄
?
update name set birthday = ' 1971-01-10 ' where uname = ' 張三 ' ;
?
10、刪除記錄
?
delete from name where uname = ' 張三 ' ;
?
11、刪除表
?
drop table 表名
?
12、刪除庫
drop database 庫名;
?
13、備份數據庫
?
mysqldump - u root - p -- opt 數據庫名>備份名; //進入到庫目錄
?
14、恢復
?
mysql - u root - p 數據庫名 < 備份名; // 恢復時數據庫必須存在,可以為空數據庫
?
15、數據庫授權
? 格式:grant select on 數據庫.* to 用戶名@登錄主機 identified by "密碼"
例1、增加一個用戶user001密碼為123456,讓他可以在任何主機上登錄,并對所有數據庫有查詢、插入、修改、刪除的權限。首先用以root用戶連入MySQL,然后鍵入以下命令:
mysql > grant select , insert , update , delete on * . * to user001@" % " Identified by " 123456 ";
?
例2、增加一個用戶user002密碼為123456,讓此用戶只可以在localhost上登錄,也可以設置指定IP,并可以對數據庫test進行查詢、插入、修改、刪除的操作 (localhost指本地主機,即MySQL數據庫所在的那臺主機)
??????? //這樣用戶即使用知道user_2的密碼,他也無法從網上直接訪問數據庫,只能通過MYSQL主機來操作test庫。
??????? //首先用以root用戶連入MySQL,然后鍵入以下命令:
mysql > grant select , insert , update , delete on test. * to user002 @localhost identified by " 123456 ";
?
注: 其次也可以采用修改表的方式,處理用戶的登錄方式:
數據庫: Mysql
表:????? User
修改:?? User表中的Host列的值來現實登錄入口
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
