1. 程式人生 > >mysql DCL數據控制語言

mysql DCL數據控制語言

-h string employees 所有 leg 切換 general 建數據庫 不存在

-- 維護性操作 都是在cmd下操作的
連接數據庫
本機:mysql [-h localhost] -u account -p
遠程:mysql [-h remote_ip] -u account -p

顯示當前所有數據庫:show databases;
切換數據庫:use db_name;
顯示當前數據庫下的表:show tables;

授權遠程訪問:

grant privileges on 數據庫.* to [email protected] identified by password(pwd_string);
是授權生效:
重啟mysql服務
flush privileges;
privileges:
SELECT,INSERT,...

實例:授權 grand select on studymysql.* to [email protected] indentified by ‘123456‘

更新權限 flush privileges 或者 重啟mysql set start mysql

退出 mysql:exit
收回訪問權限
revoke privileges on 數據庫.* from [email protected];


-- 用戶管理:
-- 新建用戶
create user user_name identified by ‘password_value‘;
-- 修改用戶
rename user user_name to new_user_name;
set password for user_name = password(‘new_password‘);
-- 刪除用戶
drop user user_name[,user_name2,...];
-- 查看用戶
select user,host from mysql.user;
-- 查看在線用戶
SELECT SUBSTRING_INDEX(host, ‘:‘, 1) AS host_short,
GROUP_CONCAT(DISTINCT user) AS users,
COUNT(*) AS threads
FROM information_schema.processlist
GROUP BY host_short
ORDER BY COUNT(*), host_short;

-- 創建數據庫
create database db_name [default character set utf8 collate utf8_general_ci];

實例:create database school default character set utf8 collate utf8_general_ci;
-- 刪除數據庫
drop database db_name;

實例:drop database school;
-- 備份數據庫
mysqldump -u user_name -p db_name > backupfile
mysqldump -u user_name -p db_name [table_name]> backupfile

實例:mysqldump - u root -p employees > employees.sql
-- 還原數據庫
mysql -u root -p
確定要還原的數據庫是否存在,不存在則創建
切換到要還原的數據庫上
執行還原操作:source backup.sql

實例:1.mysql -u root -p

2.show databases

3.creat databases employees default character set utf8

4.user employees

5.source employees.sql

-- 程序設計

mysql DCL數據控制語言