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的更多相关文章

  1. 【转】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 ...

  2. [SQL] 简单新建(create)删除(drop\delete)权限(grant/revoke)修改(set\update)

    一.前言 说起来 数据库(Structured Query Language),本站写过很多类似文章. 如: Mysql创建.删除用户 phpMyAdmin 登陆需要密码 记一次裸迁 MySQL 经历 ...

  3. 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 ...

  4. 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 ...

  5. 转载: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- ...

  6. [Windows Azure] Getting Started with Windows Azure SQL Database

    In this tutorial you will learn the fundamentals of Windows Azure SQL Database administration using ...

  7. LinuxCentos7下安装Mysql8.x以及密码修改

    LinuxCentos7下安装Mysql以及密码修改 引言: 之前都是用Docker或者yum自动安装,这次主要是下载压缩包解压安装,中间也有些小波折,记录如下,以供参考: 1.删除旧的MySQL 检 ...

  8. oracle 创建create user 及授权grant 查看登陆的用户

    show user; select sys_context('userenv','session_user') from dual; select user from dual; 查看所有登录的用户必 ...

  9. 基于Apache+php+mysql的许愿墙网站的搭建create database xyq; //创建xyq数据库

    1.准备CentOS7与CentOS5的基础配置 2.在两台虚拟机中配置yum. 3.在CentOS7中安装httpd与php与php-mysql PS:截图时已安装 CentOS7 关闭防火墙与se ...

随机推荐

  1. Android开发需要注意的地方

          1.理解运用商场概略 开发者对商场状况的理解与APP的胜利紧密相连,往常,AppStore和GooglePlay能够说是挪动运用最为丰厚的运用生态,像苹果的下载计算表单会记载抢手运用的下载 ...

  2. Android开发--推送

    需要的知识点:Notification.Service 第三方开源框架 : android-async-http-master 推送的来源:android项目中,有时会有这样一种需求:客户每隔一段时间 ...

  3. Hash - a javascript dictionary object.

    Hash,in wikipedia, may relevant to many stuffs. In javascript, hash is a group of name/value pairs w ...

  4. oracle-绑定变量学习笔记(未完待续)

    --定义变量SQL> var a number; --给绑定变量赋值SQL> exec :a :=123; PL/SQL procedure successfully completed. ...

  5. IOS-UI-UILable

    //用于文本展示 UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(10, 30, 200, 300)]; //使用测色器自选颜色 ...

  6. ajax使用中发现的问题与深入扩展(for循环中嵌套ajax)

    在学习ajax的过程中,我曾经遇到过这样的一个问题,为了得到一个详情列表,我要先向服务器去请求得到索引表,简单描述就是ajax中的success中的for循环中再次嵌套了ajax,结果第二层succe ...

  7. PHP算法 《树形结构》 之 伸展树(1) - 基本概念

    伸展树的介绍 1.出处:http://dongxicheng.org/structure/splay-tree/ A. 概述 二叉查找树(Binary Search Tree,也叫二叉排序树,即Bin ...

  8. sublime text 几种常用插件

    1.docblockr  //文档注释 使用 /**  +tab 在函数前就可以   2.SublimeLinter 代码校验插件,支持多种语言,这个是主插件,如果想检测特定的文件需要单独下载   3 ...

  9. 完美让IE兼容input placeholder属性的jquery实现

    调用时直接引用jquery与下面的js就行了,相对网上的大多数例子来说,这个是比较完美的方案. /* * 球到西山沟 * http://www.cnzj5u.com * 2014/11/26 12:1 ...

  10. javascript原型模式理解

    传统的面向对象语言中,创建一个对象是通过使用类来创建一个对象的,比如通过类飞行器来创建一个对象,飞机. 而js这种没有类概念的动态设计语言中,创建对象是通过函数来创建的,所以通常也把js称为函数式语言 ...