下文主要給大家?guī)聿僮鱉ySQL數(shù)據(jù)庫的高級方法,希望這些內(nèi)容能夠帶給大家實(shí)際用處,這也是我編輯操作MySQL數(shù)據(jù)庫的高級方法這篇文章的主要目的。好了,廢話不多說,大家直接看下文吧。
10多年專注成都網(wǎng)站制作,企業(yè)網(wǎng)站制作,個(gè)人網(wǎng)站制作服務(wù),為大家分享網(wǎng)站制作知識、方案,網(wǎng)站設(shè)計(jì)流程、步驟,成功服務(wù)上千家企業(yè)。為您提供網(wǎng)站建設(shè),網(wǎng)站制作,網(wǎng)頁設(shè)計(jì)及定制高端網(wǎng)站建設(shè)服務(wù),專注于企業(yè)網(wǎng)站制作,高端網(wǎng)頁制作,對工商代辦等多個(gè)領(lǐng)域,擁有豐富建站經(jīng)驗(yàn)。
1.數(shù)據(jù)備份與還原
(1)備份
mysqldump:
mysqldump -u username -p password dbname [tbname1 [tbname2....] ]> filename.sql
mysqldump -u root -p mydb2 > C:\mysql\dump\mydb2_dump.sql
(2)恢復(fù):只能恢復(fù)數(shù)據(jù)庫的表和記錄,不能恢復(fù)數(shù)據(jù)庫本身
mysql:方法一 mysql -u username -p password [dbname] < filename.sql
mysql:方法二,source命令
在MySQL命令提示符下:創(chuàng)建數(shù)據(jù)庫 進(jìn)入數(shù)據(jù)庫 source xxx.sql 文件 將備份的sql文件在當(dāng)前位置執(zhí)行
source filename.sql //路徑
2.user表
3.創(chuàng)建普通用戶
(1)使用GRANT語句創(chuàng)建用戶
GRANT privileges ON dtabase.table
TO 'username' @ 'hostname' [IDENTIFIED BY [PASSWORD] 'password'] [,'username' @ 'hostname' [IDENTIFIED BY [PASSWORD] 'password']]...............
//錯(cuò)誤
(2)使用CREATE語句
CREATE USER 'username'@'hostname' [IDENTIFIED BY [PASSWORD] 'password'] [,'username' @ 'hostname' [IDENTIFIED BY [PASSWORD] 'password']]...............
create user 'haha'@'localhost' identified by '123456';
(3) 使用INSERT語句
4.刪除普通用戶
~ROP USER 'username'@'hostname' [,'username'@'hostname'];
drop user 'ha'@'localhost';
~ELETE FROM mysql.user WHERE Host= 'hostname' AND User = 'username';
delete from mysql.user where host = 'localhost' and user = 'ha';
flush privileges; #由于直接對user表執(zhí)行操作,要重新加載用戶權(quán)限
5.修改用戶密碼
(1)修改root用戶密碼
+++++++++++++++++++++++++++++++++++++++++++++++
UPDATE mysql.user set Password = PASSWORD('new_password') WHERE User='username' and Host='hostname';
FLUSH PRIVILEGES;
update mysql.user set password=PASSWORD('QWE123!@#') where user='root' and host='localhost';
flush privileges;
+++++++++++++++++++++++++++++++++++++++++++++
//不成功
(2)root用戶修改普通用戶密碼
SET PASSWORD FOR 'username'@'hostname'=PASSWORD('new_password');
set password for 'haha'@'localhost'=PASSWORD('123');
+++++++++++++++++++++++++++++++++++++++
//不成功
(3)普通用戶修改密碼
SET PASSWORD=PASSWORD('new_password');
6.授予權(quán)限:使不同用戶有不同權(quán)限
(1)GRANT privileges [ (columns) ] [,privileges[(columns)]] ON database.table TO 'username'@'hostname' [IDENTIFIED BY [PASSWORD] 'password' ] [ 'username'@'hostname' [IDENTIFIED BY [PASSWORD] 'password' ]]...........
[WITH with_option [with_option]...]
with_option參數(shù)如下:
(1)GRANT OPTION:將自己的權(quán)限授予其他用戶
(2)MAX_QUERIES_PER_HOUR count:設(shè)置每小時(shí)最大查詢次數(shù)count。
(3)MAX_UPDATES_PER_HOUR count:設(shè)置每小時(shí)最多可執(zhí)行多少次更新
(4)MAX_CONNECTIONS_PER_HOUR count:設(shè)置每小時(shí)最大連接數(shù)量
(5)MAX_USER_CONNECTIONS:設(shè)置每個(gè)用戶最多可以同時(shí)建立連接數(shù)量
GRANT INSERT,SELECT ON mydb2.star TO 'haha'@'localhost' IDENTIFIED BY '123456'
WITH GRANT OPTION;
++++++++++++++++++++++++++++++++++++++++++++
//不成功
7.查看權(quán)限
(1) SHOW GRANTS FOR 'username'@'hostname';
show grants for 'haha'@'localhost';
8.收回權(quán)限
REVOKE privileges [ (columns) ] [,privileges[(columns)]] ON database.table FROM 'username'@'hostname' [,'username'@'hostname' ]....
對于以上關(guān)于操作MySQL數(shù)據(jù)庫的高級方法,大家是不是覺得非常有幫助。如果需要了解更多內(nèi)容,請繼續(xù)關(guān)注我們的行業(yè)資訊,相信你會喜歡上這些內(nèi)容的。
網(wǎng)頁標(biāo)題:操作MySQL數(shù)據(jù)庫的高級方法
鏈接地址:http://muchs.cn/article2/igecoc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供手機(jī)網(wǎng)站建設(shè)、靜態(tài)網(wǎng)站、電子商務(wù)、網(wǎng)站策劃、品牌網(wǎng)站設(shè)計(jì)、網(wǎng)站收錄
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)