mysql数据库基础知识和认识
mysql 创建一个用户 hail,密码 hail,指定一个数据库 haildb 给 hail
mysql -u root -p
password
use mysql;
insert into user(host,user,password) values('localhost','hail',password('hail'));
flush privileges;
create database haildb;
grant all privileges on haildb.* to hail@localhost identified by 'hail';
flush privileges;
如果想指定部分权限给用户
grant select,update on haildb.* to hail@localhost identified by 'hail';
flush privileges;
删除用户
delete from user where user='hail' and host='localhost';
flush privileges;
删除用户数据库
drop database haildb;
修改指定用户密码
update user set password=password('new_password') where user='hail' and host='localhost';
flush privileges;
1.远程登录mysql
mysql -h ip -u root -p 密码
2.创建用户
格式:grant 权限 on 数据库.* to 用户名@登录主机 identified by “密码”;
例1:增加一个test1用户,密码为123456,可以在任何主机上登录,并对所有数据库有查询,增加,修改和删除的功能。需要在mysql的root用户下进行
mysql>grant select,insert,update,delete on *.* to test1@”%” identified by “123456″;
mysql>flush privileges;
例2:增加一个test2用户,密码为123456,只能在192.168.2.12上登录,并对数据库student有查询,增加,修改和删除的功能。需要在mysql的root用户下进行
mysql>grant select,insert,update,delete on student.* to test2@192.168.2.12 identified by “123456″;
mysql>flush privileges;
例3:授权用户test3拥有数据库student的所有权限
mysql>grant all privileges on student.* to test3@localhost identified by ’123456′;
mysql>flush privileges;
3.修改用户密码
mysql>update mysql.user set password=password(’123456′) where User=’test1′ and Host=’localhost’;
mysql>flush privileges;
4.删除用户
mysql>delete from user where user=’test2′ and host=’localhost’;
mysql>flush privileges;
5.删除数据库和删除表
mysql>drop database 数据库名;
mysql>drop table 表名;
6.删除账户及权限
drop user 用户名@’%’
drop user 用户名@localhost
**************************************************************************************
grant 详细解析如下:
**************************************************************************************
MySQL 赋予用户权限命令的简单格式可概括为:
grant 权限 on 数据库对象 to 用户
一、grant 普通数据用户,查询、插入、更新、删除 数据库中所有表数据的权利。
grant select on testdb.* to common_user@’%’
grant insert on testdb.* to common_user@’%’
grant update on testdb.* to common_user@’%’
grant delete on testdb.* to common_user@’%’
或者,用一条 MySQL 命令来替代:
grant select, insert, update, delete on testdb.* to common_user@’%’
二、grant 数据库开发人员,创建表、索引、视图、存储过程、函数。。。等权限。
grant 创建、修改、删除 MySQL 数据表结构权限。
grant create on testdb.* to developer@’192.168.0.%’;
grant alter on testdb.* to developer@’192.168.0.%’;
grant drop on testdb.* to developer@’192.168.0.%’;
grant 操作 MySQL 外键权限。
grant references on testdb.* to developer@’192.168.0.%’;
grant 操作 MySQL 临时表权限。
grant create temporary tables on testdb.* to developer@’192.168.0.%’;
grant 操作 MySQL 索引权限。
grant index on testdb.* to developer@’192.168.0.%’;
grant 操作 MySQL 视图、查看视图源代码 权限。
grant create view on testdb.* to developer@’192.168.0.%’;
grant show view on testdb.* to developer@’192.168.0.%’;
grant 操作 MySQL 存储过程、函数 权限。
grant create routine on testdb.* to developer@’192.168.0.%’; — now, can show procedure status
grant alter routine on testdb.* to developer@’192.168.0.%’; — now, you can drop a procedure
grant execute on testdb.* to developer@’192.168.0.%’;
三、grant 普通 DBA 管理某个 MySQL 数据库的权限。
grant all privileges on testdb to dba@’localhost’
其中,关键字 “privileges” 可以省略。
四、grant 高级 DBA 管理 MySQL 中所有数据库的权限。
grant all on *.* to dba@’localhost’
五、MySQL grant 权限,分别可以作用在多个层次上。
1. grant 作用在整个 MySQL 服务器上:
grant select on *.* to dba@localhost; — dba 可以查询 MySQL 中所有数据库中的表。
grant all on *.* to dba@localhost; — dba 可以管理 MySQL 中的所有数据库
2. grant 作用在单个数据库上:
grant select on testdb.* to dba@localhost; — dba 可以查询 testdb 中的表。
3. grant 作用在单个数据表上:
grant select, insert, update, delete on testdb.orders to dba@localhost;
4. grant 作用在表中的列上:
grant select(id, se, rank) on testdb.apache_log to dba@localhost;
5. grant 作用在存储过程、函数上:
grant execute on procedure testdb.pr_add to ‘dba’@’localhost’
grant execute on function testdb.fn_add to ‘dba’@’localhost’
六、查看 MySQL 用户权限
查看当前用户(自己)权限:
show grants;
查看其他 MySQL 用户权限:
show grants for dba@localhost;
七、撤销已经赋予给 MySQL 用户权限的权限。
revoke 跟 grant 的语法差不多,只需要把关键字 “to” 换成 “from” 即可:
grant all on *.* to dba@localhost;
revoke all on *.* from dba@localhost;
八、MySQL grant、revoke 用户权限注意事项
1. grant, revoke 用户权限后,该用户只有重新连接 MySQL 数据库,权限才能生效。
2. 如果想让授权的用户,也可以将这些权限 grant 给其他用户,需要选项 “grant option“
grant select on testdb.* to dba@localhost with grant option;
这个特性一般用不到。实际中,数据库权限最好由 DBA 来统一管理。
Category: Post
You can follow any responses to this entry via RSS.
Comments are currently closed, but you can trackback from your own site.
=========================================================================
1.创建用户并授权
grant语句的语法:
grant privileges (columns) on what to user identified by “password” with grant option
要使用该句型,需确定字段有:
privileges 权限指定符权限允许的操作
alter 修改表和索引
create 创建数据库和表
delete 删除表中已有的记录
drop 抛弃(删除)数据库和表
index 创建或抛弃索引
insert 向表中插入新行
reference 未用
select 检索表中的记录
update 修改现存表记录
file 读或写服务器上的文件
process 查看服务器中执行的线程信息或杀死线程
reload 重载授权表或清空日志、主机缓存或表缓存。
shutdown 关闭服务器
all 所有;
all privileges同义词
usage 特殊的“无权限”权限
以上权限分三组:
第一组:适用于数据库、表和列如:alter create delete drop index insert select update
第二组:数管理权限 它们允许用户影响服务器的操作 需严格地授权 如:file process reload shut*
第三组:权限特殊 all意味着“所有权限” uasge意味着无权限,即创建用户,但不授予权限
columns
权限运用的列(可选)并且你只能设置列特定的权限。如果命令有多于一个列,应该用逗号分开它们。
what
权限运用的级别。权限可以是全局,定数据库或特定表.
user
权限授予的用户,由一个用户名和主机名组成,许两个同名用户从不同地方连接.缺省:mysql用户password
赋予用户的口令(可选),如果你对用户没有指定identified by子句,该用户口令不变.
用identified by时,口令字符串用改用口令的字面含义,grant将为你编码口令.
注:set password使用password()函数
with grant option
用户可以授予权限通过grant语句授权给其它用户(可选)
实例讲解:
grant all on db_book.* to huaying@koowo.com identified by “yeelion” 只能在本地连接
grant all on db_book.* to huaying@vpn.koowo.com identified by “yeeliong” 允许从此域连接
grant all on db_book.* to huaying@% identified by “yeelion” 允许从任何主机连接 注:”%”字符起通配符作用,与like模式匹配的含义相同。
grant all on db_book.* to huaying@%.koowo.com identified by “yeelion”; 允许huaying从koowo.com域的任何主机连接
grant all on db_book.* to huaying@192.168.1.189 identified by “yeelion”
grant all on db_book.* to huaying@192.168.1.% identified by “yeelion”
grant all on db_book.* to huaying@192.168.1.0/17 identified by “yeelion”
允许从单IP 段IP或一子网IP登陆
注:有时 用户@IP 需用引号 如”huaying@192.168.1.0/17″
grant all on *.* to huaying@localhost identified by “yeelion” with grant option
添加超级用户huaying 可在本地登陆做任何操作.
grant reload on *.* to huaying@localhost identified by “yeelion” 只赋予reload权限
grant all on db_book to huaying@koowo.com indetified by “yeelion” 所有权限
grant select on db_book to huaying@% indetified by “yeelion” 只读权限
grant select,insert,delete,update on db_book to huaying@koowo.com indetified by “yeelion”
只有select,insert,delete,update的权限
grant select on db_book.storybook to huaying@localhost indetified by “yeelion” 只对表
grant update (name) on db_book.storybook to huaying@localhost 只对表的name列 密码不变
grant update (id,name,author) on db_book.storybook to huaying@localhost 只对表的多列
grant all on book.* to “”@koowo.com 允许koowo.com域中的所有用户使用库book
grant all on book.* to huaying@%.koowo.com indetified by “yeelion” with grant option
允许huaying对库book所有表的管理员授权.
2.撤权并删除用户
revoke的语法类似于grant语句
to用from取代,没有indetifed by和with grant option子句. 如下:
revoke privileges (columns) on what from user
user:必须匹配原来grant语句的你想撤权的用户的user部分。
privileges:不需匹配,可以用grant语句授权,然后用revoke语句只撤销部分权限。
revoke语句只删权限不删用户,撤销了所有权限后user表中用户记录保留,用户仍然可以连接服务器.
要完全删除一个用户必须用一条delete语句明确从user表中删除用户记录:
delete from user where user=”huaying”
flush privileges; 重载授权表
注:使用grant和revoke语句时,表自动重载,而你直接修改授权表时不是.
实例:
1.创建数据库
CREATE DATABASE `fypay` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
2.为创建的数据库增加用户fypay
grant create,select,insert,update,delete,drop,alter on fypay.* to fypay@”%” identified by “testfpay”;
3.删除fypay用户
delete from user where user=”fypay”
drop user fypay@localhost
4.刷新数据库
flush privileges;
mysql数据库基础知识和认识的更多相关文章
- MySQL数据库基础知识及优化
MySQL数据库基础知识及优化必会的知识点,你掌握了多少? 推荐阅读: 这些必会的计算机网络知识点你都掌握了吗 关于数据库事务和锁的必会知识点,你掌握了多少? 关于数据库索引,必须掌握的知识点 目录 ...
- 阿里面试官必问的12个MySQL数据库基础知识,哪些你还不知道?
数据库基础知识 1.为什么要使用数据库 (1)数据保存在内存 优点: 存取速度快 缺点: 数据不能永久保存 (2)数据保存在文件 优点: 数据永久保存 缺点: 1)速度比内存操作慢,频繁的IO操作. ...
- Java基础86 MySQL数据库基础知识
本文知识点(目录): 1.MySQL数据库的概述 2.MySQL数据库的管理[对数据库的操作](查询.删除.创建数据库,以及查询和修改数据库的编码模式) 3.表的管理[对数据库 表的操作] ...
- MySQL数据库基础知识复习
现在是2020年寒假,这也是新年写的第一篇博客,用了十几天的时间自学了数据库基础部分,想总结一下得失同时并通过写博客来复习前面学的知识点. 个人: 1.本来是计划一周学完基础部分的178p但没能完成这 ...
- Mysql数据库基础知识
什么是Mysql数据库 MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于 Oracle 旗下公司.MySQL 最流行的关系型数据库管理系统,在 WEB 应用方面MySQ ...
- [mysql]数据库基础知识
数据库管理系统DBMS 软件 bin config db (保存数据) 写程序: 数据库在本地 找到目录 添加数据 数据库在远程 socket连接上远程机器 socket发送命令 需要做的事情 程序 ...
- python week09 Mysql 数据库基础知识
第一篇:初识数据库 注:<基础概念,不再赘述,点开链接查看> 第二篇:库相关操作 一 系统数据库 information_schema: 虚拟库,不占用磁盘空间,存储的是数据库启动后的一些 ...
- Mysql数据库基础知识(全)
前言:本博文为个人笔记,记录了Mysql的一些基本操作,一般掌握本博文就可以了解数据库.表.数据项的增删改查,希望对大家的学习有所帮助. 首先下载PHPSTUDY,将Mysql配置为系统变量. 具体操 ...
- Mysql之基础知识笔记
Mysql数据库基础知识个人笔记 连接本地数据库: mysql -h localhost -u root -p 回车输入数据库密码 数据库的基础操作: 查看当前所有的数据库:show database ...
随机推荐
- 2-AMD
诞生背景1.随着前端逻辑越来越多,项目越来越大,开发大型项目就必须分模块开发2.一切都那么完美,在NodeJs实现后,当人们开始热情的打算把这种实现也用于浏览器时,却发现并不适合.NodeJS应用加载 ...
- JavaScript-dom3 json_str dom元素控制 模拟百度搜索
访问关系-封装代码 html <!DOCTYPE html> <html lang="en"> <head> <meta charset= ...
- Word 为标题设置段前段后间距设置与异常
一.概述 在进行Word文档写作时,常常要求我们对(节)标题设置段前段后间距.例如: (2)按照标题的不同,分别采用不同的段前段后间距: 标题级别 段前段后间距 章标题 30磅 一级节标题 18磅 二 ...
- 【c++ primer, 5e】构造函数 & 拷贝、赋值和析构
[构造函数] 1.构造器就是创建对象时被调用的代码. 2.如果没有自定义构造器,那么编译器将自动合成一个默认的无参构造器. 3.自定义的构造器不允许加const,所创建const的对象只有在构造器代码 ...
- 20145329 《Java程序设计》实验五总结
实验内容: 1.用老师代码编写,实现服务器与客户端. 2.客户端与服务器连接 3.客户端中输入明文,利用DES算法加密,DES的秘钥用RSA公钥密码中服务器的公钥加密,计算明文的Hash函数值,一起传 ...
- linux 下各个头文件的作用[典]
linux 下各个头文件的作用 2.6.30.4的头文件的位置和2.6.25.8的不一样,除去内核源码下的include目录外, 在arch/arm/mach-s3c2410/和arch/arm/ ...
- linux共享内存简单介绍以及编码演示
共享内存的基本概念 共享内存区是最快的IPC形式.一旦这样的内存映射到共享它的进程的地址空间,这些进程间数据传递不再涉及到内核,换句话说是进程不再通过执行进入内核的系统调用来传递彼此的数据. 下图是共 ...
- Java中private、protected、public和default的区别-001
public: 具有最大的访问权限,可以访问任何一个在classpath下的类.接口.异常等.它往往用于对外的情况,也就是对象或类对外的一种接口的形式. protected: 主要的作用就是用来保护子 ...
- Base64编码原理
Base64编码之所以称为Base64,是因为其使用64个字符来对任意数据进行编码,同理有Base32.Base16编码.标准Base64编码使用的64个字符为: 这64个字符是各种字符编码(比如AS ...
- uboot向linux传递输出任何log信息的方法
答案:在bootargs中加入loglevel=8即可(在进入linux的过程中会输出任何log信息)