MySQL(MariaDB)常用DOM命令
阿新 • • 發佈:2018-11-28
資料庫管理
--刪除資料庫 drop database if exits bookDB; --建立資料庫 create database bookDB; --修改資料庫 alter database bookDB charset=utf8;
使用者管理:
-- 檢視使用者 select current_user(), user(); select * from mysql.user; --建立使用者 -- 特別需要注意,在 MySQL 中,賬號由兩部分組成: -- 1. user -- 2. host -- 即使 user 相同,只要 host 不同,也會被認為是不同賬號。 -- 這樣可以非常方便對來自不同 ip 地址的訪問進行精細的許可權控制。 -- 預設情況下,建立的使用者 host 為 '%',這是一個匹配符,跟模糊查詢裡的意思一樣,表示匹配所有 create user user_name identified by '密碼'; -- 所有連線 create user[email protected]'127.0.0.1' identified by '密碼'; -- 本地連線 create user [email protected]'192.168.%' identified by '密碼'; -- 192.168 網段的連線 --修改使用者密碼 set password for '使用者名稱'@'服務地址' = password('新密碼'); --刪除使用者 drop user user_name; -- 增加使用者 insert into mysql.user(host, user, password) values (xx, yy, zz); -- 修改密碼 update mysql.user set password=password('新密碼') where user='user_name' and host='%'; -- 修改許可權 update mysql.user set event_priv='Y' where user='user_name' and host='%'; -- 注意,使用 sql 語句修改使用者跟許可權之後,需要手動重新整理許可權表 flush privileges;
許可權管理
--授予許可權 grant all on *.* to [email protected]'127.0.0.1'; -- 將所有資料庫上的所有權利都授予通過本機連線的使用者! grant all privileges on database_name.* to [email protected]'%'; -- 將資料庫 上的所有權利都授予所有連線的 使用者! grant select on database_name.table_name to [email protected]'%'; -- 將資料庫上的 表資料表的訪問許可權開放給所有使用者。 --檢視使用者許可權 show grants for[email protected]'%'; -- 授權的相對完整語法為: grant all/alter/create/drop/select/update/delete on *.* -- db.*/db.table to 'user'@'host' identified by '密碼' with max_user_connections 2 max_connections_pser_hour 5;