Create New User and Grant Permissions in MySQL

by | 13 Aug 2015 | Database, MySQL, Server, Technology | 0 comments

MySQL is an open source relational database management software. It helps to store, organise and retrieve data. MySQL has a feature for you to create users to manage different databases or tables with certain permissions.

MySQL Permissions

The different types of permissions available in MySQL are as follows.

[su_table]

Permission Description
ALL PRIVILEGES allows user to perform all the following permissions on tables or databases
CREATE allows user to create tables or databases
DROP allows user to delete tables or databases
DELETE allows user to delete rows from tables
INSERT allows user to insert rows to tables
SELECT allows user to retrieve rows to tables
UPDATE allows user to update rows to tables
GRANT OPTION allows user to grant or remove other users’ privileges

[/su_table]

How to create a new user

Before being able to run any of these commands, you will have to login to your MySQL first, which usually we will use root to login at command line.

mysql -u root -p

It should prompt you to enter your root password for MySQL. After that, you will be logged into your MySQL.

Command to create a new user

CREATE USER 'new_username'@'localhost' IDENTIFIED BY 'password';
  • new_username – username of user
  • localhost – location in terms of ip address of MySQL to create user at
  • password – password for user to login to MySQL

After creating a new user in MySQL, we need to give the user permissions in order for the user to do anything.

GRANT ALL PRIVILEGES ON * . * TO 'new_username'@'localhost';
  • new_username – username of user created previously
  • localhost – location in terms of ip address of MySQL where user was created at previously

Once you are done with the two commands above, you need to reload the permissions for MySQL.

FLUSH PRIVILEGES;

 

That’s it! You are all set.

Feel free to drop me an email at [email protected] if you have any questions.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Related Posts

Amazon Web Services (AWS)ApacheCentOSDatabaseLinuxMySQLOSProgrammingServerTechnology
8 Simple Steps to Setup a Web Server with Apache Virtual Hosts & MySQL in Centos

8 Simple Steps to Setup a Web Server with Apache Virtual Hosts & MySQL in Centos

This tutorial will be guiding you in setting up a web server with pre-installed Centos. In summary, you will be installing Apache and MySQL, and learning how to configure virtual hosts in Apache. Note: before proceeding with this tutorial. Make sure you figure out...

AppleiOSMobile PhonesObjective-CProgrammingSwiftTechnology
How to install Cocoapods for Objective-C/Swift development on Mac OS?

How to install Cocoapods for Objective-C/Swift development on Mac OS?

Steps to install Cocoapods Cocoapods is used in Xcode IDE for development from iOS apps using Objective-C/Swift. Cocoapods helps developers add external libraries to their iOS project easily. The following tutorial guides you on the steps to install Cocoapods on...

AndroidAndroidAppleiOSJavaMobile PhonesObjective-CProgramming
iPhone Camera
Complete overview of the mobile app development process (Infographic)

Complete overview of the mobile app development process (Infographic)

Clients always have the misperception that developing a mobile app is as easy as developing a mobile application would be a walk in a park without much effort involved. The following infographic pretty much sums up the total cost and effort for mobile app...