How To Create a New User and Grant Permissions in MySQL
How to Create a New User
Let’s start by making a new user within the MySQL shell:
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
Sadly, at this point newuser has no permissions to do anything with the databases. In fact, if newuser even tries to login (with the password, password), they will not be able to reach the MySQL shell.
Therefore, the first thing to do is to provide the user with access to the information they will need.
GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';
The asterisks in this command refer to the database and table (respectively) that they can access—this specific command allows to the user to read, edit, execute and perform all tasks across all the databases and tables.
Once you have finalized the permissions that you want to set up for your new users, always be sure to reload all the privileges.
FLUSH PRIVILEGES;
Your changes will now be in effect.
How To Grant Different User Permissions
Here is a short list of other common possible permissions that users can enjoy.
- ALL PRIVILEGES- as we saw previously, this would allow a MySQL user all access to a designated database (or if no database is selected, across the system)
- CREATE- allows them to create new tables or databases
- DROP- allows them to them to delete tables or databases
- DELETE- allows them to delete rows from tables
- INSERT- allows them to insert rows into tables
- SELECT- allows them to use the Select command to read through databases
- UPDATE- allow them to update table rows
- GRANT OPTION- allows them to grant or remove other users' privileges
To provide a specific user with a permission, you can use this framework:
GRANT [type of permission] ON [database name].[table name] TO ‘[username]’@'localhost’;
If you want to give them access to any database or to any table, make sure to put an asterisk (*) in the place of the database name or table name.
Each time you update or change a permission be sure to use the Flush Privileges command.
If you need to revoke a permission, the structure is almost identical to granting it:
REVOKE [type of permission] ON [database name].[table name] FROM ‘[username]’@‘localhost’;
Just as you can delete databases with DROP, you can use DROP to delete a user altogether:
DROP USER ‘demo’@‘localhost’;
To test out your new user, log out by typing
quit
and log back in with this command in terminal:
mysql -u [username]-p
How To Create a New User and Grant Permissions in MySQL的更多相关文章
- 【转】How to create a new user and grant permissions in MySQL
MySQL is one of the most popular database management systems. In this tutorial we will cover the ste ...
- [SQL] 简单新建(create)删除(drop\delete)权限(grant/revoke)修改(set\update)
一.前言 说起来 数据库(Structured Query Language),本站写过很多类似文章. 如: Mysql创建.删除用户 phpMyAdmin 登陆需要密码 记一次裸迁 MySQL 经历 ...
- How to create/restore a slave using GTID replication in MySQL 5.6
MySQL 5.6 is GA! Now we have new things to play with and in my personal opinion the most interesting ...
- Can't create a new thread (errno 11) 解决办法 mysql无法连接
问题的现象: 错误信息: ERROR 1135 (00000): Can't create a new thread (errno 11); if you are not out of availab ...
- 转载:Create a Flash Login System Using PHP and MySQL
本文共两部分: 1. http://dev.tutsplus.com/tutorials/create-a-flash-login-system-using-php-and-mysql-part-1- ...
- [Windows Azure] Getting Started with Windows Azure SQL Database
In this tutorial you will learn the fundamentals of Windows Azure SQL Database administration using ...
- LinuxCentos7下安装Mysql8.x以及密码修改
LinuxCentos7下安装Mysql以及密码修改 引言: 之前都是用Docker或者yum自动安装,这次主要是下载压缩包解压安装,中间也有些小波折,记录如下,以供参考: 1.删除旧的MySQL 检 ...
- oracle 创建create user 及授权grant 查看登陆的用户
show user; select sys_context('userenv','session_user') from dual; select user from dual; 查看所有登录的用户必 ...
- 基于Apache+php+mysql的许愿墙网站的搭建create database xyq; //创建xyq数据库
1.准备CentOS7与CentOS5的基础配置 2.在两台虚拟机中配置yum. 3.在CentOS7中安装httpd与php与php-mysql PS:截图时已安装 CentOS7 关闭防火墙与se ...
随机推荐
- windows Server 2008 -必须使用“角色管理工具”安装或配置Microsoft .Net Framework 3.5
在windows Server 2008上安装 .Net Framework 3.5的时候,报错:必须使用“角色管理工具”安装或配置Microsoft .Net Framework 3.5. Solu ...
- SQL 优化,全
性能不理想的系统中除了一部分是因为应用程序的负载确实超过了服务器的实际处理能力外,更多的是因为系统存在大量的SQL语句需要优化. 为了获得稳定的执行性能,SQL语句越简单越好.对复杂的SQL语句,要设 ...
- [总结]RTMP流媒体技术零基础学习方法
本文主要总结一些我在学习RTMP流媒体技术过程中积累的经验.也为后来学习RTMP流媒体技术的人们一个参考.本文力图从简到难,循序渐进的介绍RTMP流媒体技术的方方面面,先从应用说起,逐步深化剖析相关工 ...
- 效果类似于label从下往上滑(采用uiTableView实现)
首先附上效果图 进行描述一下:效果就是类似于是一个竖直方向的滚动视图 并且方向是从下往上 并且能够一直这样循环下去. 代码“ // // ViewController.m // demo滚动视图上下 ...
- javascript基础学习(九)
javascript之基本包装类型 学习要点: 基本包装类型概述 Boolean类型 Number类型 String类型 一.基本包装类型概述 为了便于操作基本类型值,提供了3种特殊的引用类型:Boo ...
- Linux数据写操作改进
Linux的IO操作中数据的写函数int nwrite = write(int fd,void* buf ,int len)表示向fd文件描述符写入len个字节长度的数据报文,但是这并不能保证真正向内 ...
- 330. Patching Array--Avota
问题描述: Given a sorted positive integer array nums and an integer n, add/patch elements to the array s ...
- Unity3d脚本的生命周期
接下来,做出一下讲解:最先执行的方法是Awake,这是生命周期的开始,用于进行激活时的初始化代码,一般可以在这个地方将当前脚本禁用:this.enable=false,如果这样做了,则会直接跳转到On ...
- Http和Socket连接的区别
Http和Socket连接区别 相信不少初学手机联网开发的朋友都想知道Http与Socket连接究竟有什么区别,希望通过自己的浅显理解能对初学者有所帮助. 1.TCP连接 要想明白Socket连接,先 ...
- 关于asp.net core部署到iis中出现 HTTP Error 502.5 - Process Failure的问题
环境是windows Server2008R2 出现这个问题搞了一下午都没解决,最后又加班才算搞定,由于英文不太好,官方的文档看了好几遍,也按照文档做的,但还是出现这个问题,百度google搜了很多解 ...