mysql訪問控制由兩部分構成
許可權位置
mysql 資料庫包含五個主要的授權表
create
user yourname identified by
'password'
;create
user yl@localhost identified by
'yl'
;--新建本地賬戶
create
user yl@% identified by
'yl'
;--新建遠端和本地通用賬戶
create
user [email protected] identified by
'yl'
;--新建遠端ip制定賬戶
--檢視賬戶許可權
show grants for yl@localhost
;---grant usage on *.* to 'yl'@'localhost' identified by password '*密文密碼'
--*.* 顯示 yl 使用者帳戶只能登入到資料庫伺服器, 沒有其他許可權
--兩個星號的區別:前者表示資料庫, 後者表示表
--重新整理許可權、在刪除賬戶,新建賬戶並授權之後
flush privileges
;
grant privilege,
[privilege],.
.on privilege_level
touser
[identified by password]
[require tsl_option]
[with
[grant_option | resource_option]
];
--授予所有許可權
grant
allon*.
*to'yl'@'localhost' with grant option;
show grants for yl@localhost;
--grant all privileges on *.* to 'yl'@'localhost' identified by password '
*密文密碼' with
grant
option
flush privileges
;
revoke privilege_type [
(column_list)][
, priv_type [
(column_list)]]
...on
[object_type] privilege_level
from
user[,
user].
..
revoke
allprivileges
,grant
option
from yl;
use mysql;
select
user
, host from mysql.
user
;--刪除使用者,刪除多個時用逗號(,)隔開
drop
user
'yl@localhost'
;--例外:如果刪除時該使用者已經連線到資料庫,那麼刪除之後該使用者仍可使用到會話結束,可以採取在刪除之前先關閉使用者的會話
show processlist;
kill id;
--殺死id
drop
user yl@localhost
;
mysqldump -u [username] –p[password]
[database_name]
>
[dump_file.
sql]
[username] : 有效的mysql使用者名稱。
[password] : 使用者的有效密碼。 請注意, -p 和密碼之間沒有空格。
[database_name] : 要備份的資料庫名稱
[dump_file.
sql] : 要生成的轉儲檔案
--mysql資料庫備份指令格式:
mysqldump -h主機名 -p埠 -u使用者名稱 -p密碼 (–database
) 資料庫名 > 檔名.
sql--1、備份mysql資料庫的命令
mysqldump -hhostname -uusername -ppassword databasename > backupfile.
sql--2、備份mysql資料庫為帶刪除表的格式,能夠讓該備份覆蓋已有資料庫而不需要手動刪除原有資料庫。
mysqldump -–add
-drop
-table
-uusername -ppassword databasename > d:\111.
sql--3、直接將mysql資料庫壓縮備份
mysqldump -hhostname -uusername -ppassword databasename | gzip > d:\111.
sql.gz
--4、備份mysql資料庫某個(些)表
mysqldump -hhostname -uusername -ppassword databasename specific_table1 specific_table2 > d:\111.
sql--5、同時備份多個mysql資料庫
mysqldump -hhostname -uusername -ppassword –-
databases databasename1 databasename2 databasename3 > d:\111.
sql--6、僅備份資料庫結構
mysqldump -uroot -proot –-no-
data –-
databases project3 project3 project4 > d:\111.
sql--7、備份伺服器上所有資料庫
mysqldump -uroot -proot –-
all-
databases
> d:\111.
sql
資料庫還原有三種方式:source命令、mysql、gunzip命令
source命令
進入mysql資料庫控制台,登入
mysql -u root -p
mysql>
use 資料庫
然後使用source命令,後面引數為指令碼檔案(如這裡用到的.
sql)
mysql>source d:\test.
sql
mysqlmysql -hhostname -uusername -ppassword test < d:\test.
sql
gunzip命令gunzip < d:\test.
sql.gz | mysql -uusername -ppassword test
--列出所有的資料庫
show
databases
;--模糊查詢資料庫(pro%:以pro開頭;%pro:以pro結尾;%pro%:含有pro)
show
databases
like
'%pro%'
;--列出資料庫下所有的表
show
tables
;--列出資料庫下所有的表和檢視
show
full
tables
;create
view selectall as
select
*from employee;
--模糊查詢表參考模糊查詢資料庫,二者一樣
--檢視表結構
describe employee;
desc employee;
show
columns
from employee;
show
full
columns
from employee;
--模糊查詢參看模糊查詢資料庫
show
full
columns
from employee like
'%pro%'
--列出所有使用者
select
user
from mysql.
user
;--顯示當前登入使用者
select
user()
;
從零開始的MySQL學習,資料庫索引
二 如何建立索引 三 檢視索引 四 刪除索引 create index 索引的名字 on tablename 列的列表 舉例 create table stu01 id int 2 not null name varchar 10 not null score int 4 index index s...
資料庫從零開始 3
繼續資料庫操作 1 列轉行 原始資料庫 select c.id,語文 課程,yw 成績 from cjb c union all select c.id,數學 課程,sx from cjb c 轉化後的資料 2 行轉列 將 1 中轉化後的表建立檢視,名稱 v myview create view v...
從零開始的MySQL學習,資料庫基礎命令
二 基本資料庫管理命令 三 sql語句 1 登入mysql mysql uroot p2 檢視資料庫的列表資訊 show databases 3 切換庫並檢視當前庫的所有表 use 資料庫名 show tables 4 顯示表的結構 describe 資料庫名.表名建立資料庫 create data...