mysql 用户/密码/权限操作
由于最近使用mysql遇到了修改用户密码的问题,所以一块学习了一下关于用户的相关操作;
1. 创建新账户
CREATE USER 'jeffrey'@'localhost';
2. 账户设置密码
#当前用户设置密码
SET PASSWORD = PASSWORD('mypass'); #给指定账户设置密码
SET PASSWORD FOR 'jeffrey'@'localhost' = PASSWORD('mypass');
3. 给账户赋权限
#赋权限
GRANT ALL ON db1.* TO 'jeffrey'@'localhost'; #刷新权限
flush privileges;
刷新权限的方式有多种,如上只是其中的一种方式。详情点击 或 如下:

可赋值的权限如下表:
Table 13.3 Permissible Privileges for GRANT and REVOKE
| Privilege | Meaning and Grantable Levels |
|---|---|
ALL [PRIVILEGES] |
Grant all privileges at specified access level except GRANT OPTION and PROXY. |
ALTER |
Enable use of ALTER TABLE. Levels: Global, database, table. |
ALTER ROUTINE |
Enable stored routines to be altered or dropped. Levels: Global, database, procedure. |
CREATE |
Enable database and table creation. Levels: Global, database, table. |
CREATE ROUTINE |
Enable stored routine creation. Levels: Global, database. |
CREATE TABLESPACE |
Enable tablespaces and log file groups to be created, altered, or dropped. Level: Global. |
CREATE TEMPORARY TABLES |
Enable use of CREATE TEMPORARY TABLE. Levels: Global, database. |
CREATE USER |
Enable use of CREATE USER, DROP USER, RENAME USER, and REVOKE ALL PRIVILEGES. Level: Global. |
CREATE VIEW |
Enable views to be created or altered. Levels: Global, database, table. |
DELETE |
Enable use of DELETE. Level: Global, database, table. |
DROP |
Enable databases, tables, and views to be dropped. Levels: Global, database, table. |
EVENT |
Enable use of events for the Event Scheduler. Levels: Global, database. |
EXECUTE |
Enable the user to execute stored routines. Levels: Global, database, table. |
FILE |
Enable the user to cause the server to read or write files. Level: Global. |
GRANT OPTION |
Enable privileges to be granted to or removed from other accounts. Levels: Global, database, table, procedure, proxy. |
INDEX |
Enable indexes to be created or dropped. Levels: Global, database, table. |
INSERT |
Enable use of INSERT. Levels: Global, database, table, column. |
LOCK TABLES |
Enable use of LOCK TABLES on tables for which you have the SELECT privilege. Levels: Global, database. |
PROCESS |
Enable the user to see all processes with SHOW PROCESSLIST. Level: Global. |
PROXY |
Enable user proxying. Level: From user to user. |
REFERENCES |
Enable foreign key creation. Levels: Global, database, table, column. |
RELOAD |
Enable use of FLUSH operations. Level: Global. |
REPLICATION CLIENT |
Enable the user to ask where master or slave servers are. Level: Global. |
REPLICATION SLAVE |
Enable replication slaves to read binary log events from the master. Level: Global. |
SELECT |
Enable use of SELECT. Levels: Global, database, table, column. |
SHOW DATABASES |
Enable SHOW DATABASES to show all databases. Level: Global. |
SHOW VIEW |
Enable use of SHOW CREATE VIEW. Levels: Global, database, table. |
SHUTDOWN |
Enable use of mysqladmin shutdown. Level: Global. |
SUPER |
Enable use of other administrative operations such as CHANGE MASTER TO, KILL, PURGE BINARY LOGS, SET GLOBAL, and mysqladmin debug command. Level: Global. |
TRIGGER |
Enable trigger operations. Levels: Global, database, table. |
UPDATE |
Enable use of UPDATE. Levels: Global, database, table, column. |
USAGE |
Synonym for “no privileges” |
4. 常用mysql命令
#查看当前用户
select current_user;
select current_user(); #格式化输出结果 字符/G 代表格式化输出
select * from t where t.id = 1/G;
5. 参考链接
1. https://dev.mysql.com/doc/refman/5.6/en/set-password.html
2. https://dev.mysql.com/doc/refman/5.7/en/create-user.html#create-user-previous
3. https://dev.mysql.com/doc/refman/5.6/en/grant.html
4. https://dev.mysql.com/doc/refman/5.7/en/privilege-changes.html
mysql 用户/密码/权限操作的更多相关文章
- MySql 用户 及权限操作
bin/msyql -h host -u user -p bin/mysql -u mysql -p 本地登录 如无密码按回车直接进入mySql bin/mysqladmin -u roo ...
- mysql用户与权限操作
本文所有操作均在mysql8.1下验证,mysql5.x部分语句不适用. 1.创建用户 '; # 创建用户test,密码123456,%表示允许在所有主机登陆 用户表为mysql库小的user表,Ho ...
- Mysql 用户,权限管理的几点理解。
前两天项目数据库要移植到mysql,为此临时抓了几天很久没用的mysql. 公司的数据库比较简单,从oracle迁移到mysql很简单,但是,中间的权限管理让我感觉既简单又复杂..简单是因为网上关于m ...
- mysql 用户及权限管理 小结
MySQL 默认有个root用户,但是这个用户权限太大,一般只在管理数据库时候才用.如果在项目中要连接 MySQL 数据库,则建议新建一个权限较小的用户来连接. 在 MySQL 命令行模式下输入如下命 ...
- 如何给mysql用户分配权限+增、删、改、查mysql用户
在mysql中用户权限是一个很重析 参数,因为台mysql服务器中会有大量的用户,每个用户的权限需要不一样的,下面我来介绍如何给mysql用户分配权限吧,有需要了解的朋友可参考. 1,Mysql下创建 ...
- 入门MySQL——用户与权限
前言: 前面几篇文章为大家介绍了各种SQL语法的使用,本篇文章将主要介绍MySQL用户及权限相关知识,如果你不是DBA的话可能平时用的不多,但是了解下也是好处多多. 1.创建用户 官方推荐创建语法为 ...
- MySQL Study之--MySQL用户及权限管理
MySQL Study之--MySQL用户及权限管理 MySQLserver通过MySQL权限表来控制用户对数据库的訪问.MySQL权限表存放在mysql数据库里.由mysql_install ...
- linux中重置服务器的mysql用户密码
本文章前提条件是自己经把mysql登录密码给忘记了,这个时间我们解决方法有很多,重新安装mysql数据库一切重来,另一种是通过下面文章重新设置root密码,下面我们一起来看看方法二吧. 最 近 ...
- SQL语句修改MySQL用户密码
SQL语句修改MySQL用户密码 前言 上数据库安全实验课,用命令行和DataGrip试图修改用户密码,一直语法报错.最后用Navicat才修改成功,预览Navicat的SQL语句,发现语句和网上都不 ...
随机推荐
- Maven入门---修改tomcat版本及端口及访问路径(四)
Maven中通过添加插件修改tomcat版本及端口及访问路径 --------------------------------------------------------------------- ...
- Linux的7个运行级别
0:关机 1:单用户(找回丢失密码)此模式下所有用户不需要密码即可登录,可用于重置密码 2:多用户状态没有网络服务 3:多用户状态有网络服务 ★ 4:系统未使用保留给用户 5:图形界面 ★ 6:系统重 ...
- SpringBoot整合Druid(阿里巴巴)数据源
(1).添加相关依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId ...
- error: Apache shutdown unexpectedly.
本地前端xmapp apache突然不能启动了, 报错 15:36:48 [Apache] Error: Apache shutdown unexpectedly.15:36:48 [Apache] ...
- dup,dup2函数【转】
转自:http://eriol.iteye.com/blog/1180624 转自:http://www.cnblogs.com/jht/archive/2006/04/04/366086.html ...
- 基于Apache的阿里云部署Node.js服务器(Windows环境)
1 前言 由于nodejs项目对方开放了多个端口,而且阿里云上的Apache服务器(windows)已经挂载了网站,此时需要把此项目也挂上去,网上查询资料,方法略少,基本是基于nginx版本的. 2 ...
- python3内存存储几种数据类型对差异
列表,元组,集合,字典几种数据类型差异 列表: list=[0,1,'a'] 元组:list=(0,1,'a') 集合 :list=[0,1,'a'] 字典:list={name:'tom',age: ...
- PYTHON-网络通信 TCP
网络编程: 学习网络编程 为什么?目的: 服务端特点: 网络通讯(通信) 什么是网络通讯? 为什么?目的:网络建立的目的是为数据交互(通信) 如何实现通讯(通信)? 互联网协议 互联网=物理连接介质+ ...
- 使用Springboot快速搭建SSM框架
Spring Boot设计目的是用来简化Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置. 一.环境准备 Idea 2017 或 201 ...
- 一个简单 JDK 动态代理的实例
动态代理的步骤: 创建一个实现了 InvocationHandler 接口的类,必须重写接口里的 invoke()方法. 创建被代理的类和接口 通过 Proxy 的静态方法 newProxyInsat ...