您好,登錄后才能下訂單哦!
下文主要給大家帶來操作MySQL數據庫的高級方法,希望這些內容能夠帶給大家實際用處,這也是我編輯操作MySQL數據庫的高級方法這篇文章的主要目的。好了,廢話不多說,大家直接看下文吧。
1.數據備份與還原
(1)備份
mysqldump:
mysqldump -u username -p password dbname [tbname1 [tbname2....] ]> filename.sql
mysqldump -u root -p mydb2 > C:\mysql\dump\mydb2_dump.sql
(2)恢復:只能恢復數據庫的表和記錄,不能恢復數據庫本身
mysql:方法一 mysql -u username -p password [dbname] < filename.sql
mysql:方法二,source命令
在MySQL命令提示符下:創建數據庫 進入數據庫 source xxx.sql 文件 將備份的sql文件在當前位置執行
source filename.sql //路徑
2.user表
3.創建普通用戶
(1)使用GRANT語句創建用戶
GRANT privileges ON dtabase.table
TO 'username' @ 'hostname' [IDENTIFIED BY [PASSWORD] 'password'] [,'username' @ 'hostname' [IDENTIFIED BY [PASSWORD] 'password']]...............
//錯誤
(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表執行操作,要重新加載用戶權限
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.授予權限:使不同用戶有不同權限
(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參數如下:
(1)GRANT OPTION:將自己的權限授予其他用戶
(2)MAX_QUERIES_PER_HOUR count:設置每小時最大查詢次數count。
(3)MAX_UPDATES_PER_HOUR count:設置每小時最多可執行多少次更新
(4)MAX_CONNECTIONS_PER_HOUR count:設置每小時最大連接數量
(5)MAX_USER_CONNECTIONS:設置每個用戶最多可以同時建立連接數量
GRANT INSERT,SELECT ON mydb2.star TO 'haha'@'localhost' IDENTIFIED BY '123456'
WITH GRANT OPTION;
++++++++++++++++++++++++++++++++++++++++++++
//不成功
7.查看權限
(1) SHOW GRANTS FOR 'username'@'hostname';
show grants for 'haha'@'localhost';
8.收回權限
REVOKE privileges [ (columns) ] [,privileges[(columns)]] ON database.table FROM 'username'@'hostname' [,'username'@'hostname' ]....
對于以上關于操作MySQL數據庫的高級方法,大家是不是覺得非常有幫助。如果需要了解更多內容,請繼續關注我們的行業資訊,相信你會喜歡上這些內容的。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。