mysql高階操作 MySQL資料庫的高階操作

2021-10-17 21:35:46 字數 2794 閱讀 2299

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 ***.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']]...............

grant select on mydb2.* to 'haha' @'localhost' identified by '123456';

//錯誤

(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';

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高階高階資料操作

mysql 插入高階操作 衝突處理 on duplicate key update 更新教室 class 222 主鍵衝突替換 replace into my class values b1 333 高階資料更新 複製建立表 create table my copy like my class 蠕蟲...

MySQL 高階資料操作

目錄 高階資料操作 新增資料 更新資料 刪除資料 多資料插入 只要寫一次insert指令,但是可以直接插入多條記錄 基本語法 insert into 表名 字段列表 values 值列表 值列表 沒寫欄位名時字段值從第乙個開始寫到最後乙個,即使主鍵自增也必須寫主鍵 新增時涉及主外來鍵關係,要先新增主...

mysql4 mysql4 高階操作

一 聯結 使用 where 早 和 join 晚 都可以完成聯結 1.1 從 teacher 表和 profession 表中,查詢出老師的名字和所屬專業的名稱。select t.l name t.f name p.name from teacher as t,profession as p whe...