mysql DCL数据控制语言
-- 維護(hù)性操作 ? 都是在cmd下操作的
連接數(shù)據(jù)庫:
? ? ? ? 本機(jī):mysql [-h localhost] -u account -p
? ? ? ? 遠(yuǎn)程:mysql [-h remote_ip] -u account -p
? ? 顯示當(dāng)前所有數(shù)據(jù)庫:show databases;
? ? 切換數(shù)據(jù)庫:use db_name;
? ? 顯示當(dāng)前數(shù)據(jù)庫下的表:show tables;
授權(quán)遠(yuǎn)程訪問:用戶名@登陸主機(jī)創(chuàng)建用戶時,已被綁定,登陸主機(jī)是別人的ip地址。登錄主機(jī)可以是%。%是任何主機(jī)可以訪問。
? ? grant privileges on 數(shù)據(jù)庫.* to 用戶名@登錄主機(jī) identified by password(pwd_string);
? ? 是授權(quán)生效:
? ? 重啟mysql服。
? ? flush privileges;
? ? privileges:
? ? SELECT,INSERT,...
? ? 實(shí)例:授權(quán) grand select on studymysql.* to root@'172.19.105.5' indentified by '123456'
? ? ? 更新權(quán)限 ?flush privileges 或者 重啟mysql set start mysql
? ? ? ? ? ? 退出 ?mysql:exit
收回訪問權(quán)限:
? ? ?revoke privileges on 數(shù)據(jù)庫.* from 用戶名@登錄主機(jī);
-- 用戶管理:
? ? -- 新建用戶
? ? ? ? create user user_name identified by 'password_value';
? ? 實(shí)例: ?create user 'zhangsan'@'localhost' identified by 'wlshzx';
? ? 添加用戶權(quán)限
? ? ? ?運(yùn)行以下命令賦予"myuser"用戶特定權(quán)限。
mysql> GRANT <privileges> ON <database>.<table> TO 'myuser'@'localhost';以上命令中,<privileges> 代表著用逗號分隔的權(quán)限列表。如果你想要將權(quán)限賦予任意數(shù)據(jù)庫(或表),那么使用星號(*)來代替數(shù)據(jù)庫(或表)的名字。
例如,為所有數(shù)據(jù)庫/表賦予 CREATE 和 INSERT 權(quán)限:
mysql> GRANT CREATE, INSERT ON *.* TO 'myuser'@'localhost';
? ? -- 修改用戶
? ? ? ? rename user user_name to new_user_name;
? ? ? ? set password for user_name = password('new_password');
? ? ? ?實(shí)例:rename user 'zhangsan'@'localhost' to 'lisi'@'localhost';
? ? ? ? ? ? ? ?set password for 'lisi'@'localhost'='wlshzx';
? ? -- 刪除用戶
? ? ? ? drop user user_name[,user_name2,...];
? ? ? ?實(shí)例: drop user 'lisi'@'localhost';
? ? -- 查看用戶
? ? ? ? select user,host from mysql.user;
? ? ? ?實(shí)例: ?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;
-- 創(chuàng)建數(shù)據(jù)庫
? ? ? ? create database db_name [default character set utf8 ];collate utf8_general_ci可加可不加。
? ? ? 實(shí)例:create database school default character set utf8 collate utf8_general_ci;
-- 刪除數(shù)據(jù)庫
? ? ? ? drop database db_name;
? ? ? 實(shí)例:drop database school;
-- 備份數(shù)據(jù)庫
? ? ? ? mysqldump -u user_name -p db_name > backupfile
? ? ? ? mysqldump -u user_name -p db_name [table_name]> backupfile
? ? ? 實(shí)例:mysqldump - u root -p employees > employees.sql
-- 還原數(shù)據(jù)庫
? ? ? ? mysql -u root -p
? ? ? ? 確定要還原的數(shù)據(jù)庫是否存在,不存在則創(chuàng)建
? ? ? ? 切換到要還原的數(shù)據(jù)庫上
? ? ? ? 執(zhí)行還原操作:source backup.sql
? ? ? 實(shí)例:1.mysql -u root -p
? ? ? ? ? ? ? 2.show databases
? ? ? ? ? ? ? 3.creat databases employees default character set utf8
? ? ? ? ? ? ? 4.user employees
? ? ? ? ? ? ? 5.source employees.sql
-- 程序設(shè)計
?
轉(zhuǎn)載于:https://www.cnblogs.com/wanglisong/p/6908553.html
總結(jié)
以上是生活随笔為你收集整理的mysql DCL数据控制语言的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: wcf rest系列文章
- 下一篇: Oracle SQL精妙SQL语句讲解(