1.數據備份與還原mysql
(1)備份
mysqldump:
mysqldump -u username -p password dbname [tbname1 [tbname2....] ]> filename.sqlsql
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 //路徑ide
2.user表code
3.建立普通用戶it
(1)使用GRANT語句建立用戶io
GRANT privileges ON dtabase.table
TO 'username' @ 'hostname' [IDENTIFIED BY [PASSWORD] 'password'] [,'username' @ 'hostname' [IDENTIFIED BY [PASSWORD] 'password']]...............table
//錯誤class
(2)使用CREATE語句date
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' ]....