Home » Categories » Multiple Categories |
How To Create a New User and Grant Permissions in MySQL |
Article Number: 180 | Rating: Unrated | Last Updated: Thu, Dec 26, 2013 at 9:50 PM
|
About MySQLMySQL is an open source database management software that helps users store, organize, and later retrieve data. It has a variety of options to grant specific users nuanced permissions within the tables and databases—this tutorial will give a short overview of a few of the many options.How to Create a New UserIn Part 1 of the MySQL Tutorial, we did all of the editing in MySQL as the root user, with full access to all of the databases. However, in the cases where more restrictions may be required, there are ways to create users with custom permissions.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 PermissionsHere is a short list of other common possible permissions that users can enjoy.
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 quitand log back in with this command in terminal: mysql -u [username]-p |
Attachments
![]()
There are no attachments for this article.
|
How To Create, Remove, & Manage Tables in PostgreSQL on a Cloud Server
Viewed 3402 times since Mon, Dec 30, 2013
How To Use HAProxy to Set Up MySQL Load Balancing
Viewed 8306 times since Thu, Dec 26, 2013
How To Install and Use PostgreSQL on Ubuntu 12.04
Viewed 6357 times since Mon, Dec 30, 2013
How To Install an Upstream Version of Node.js on Ubuntu 12.04
Viewed 2727 times since Sun, Dec 29, 2013
How To Install Linux, Nginx, MySQL, PHP (LEMP) Stack on Debian 7
Viewed 3975 times since Fri, Dec 27, 2013
How To Install Linux, Apache, MySQL, PHP (LAMP) stack on Arch Linux
Viewed 4650 times since Fri, Dec 27, 2013
How To Install Ruby on Rails on Arch Linux with RVM
Viewed 13978 times since Sun, Dec 29, 2013
Geddy.JS: A No-Brainer MVC Node.js Framework
Viewed 3387 times since Sun, Dec 29, 2013
How To Setup a Rails 4 App With Apache and Passenger on CentOS 6
Viewed 3772 times since Thu, Dec 19, 2013
How To Use WP-CLI to Manage your WordPress Site from the Command Line
Viewed 10254 times since Sat, Jan 4, 2014
|