Skip to main content

Adding New User Accounts to MySQL

Step 1 - Create new MySQL user


MySQL create user

Nowadays security is more and more important even in case of smaller websites. As a lot of site uses some database so this is one point where we can make some improvements.

In this article we will work with MySQL on our goal is to create a new user in the database.

There are more ways how you can do this.

  • Using CREATE USER and/or GRANT commands
  • Inserting a new record into the mysql.user table

First let's see how to use the CREATE USER command. Here I have to mention that thi s command is available only in MySQL 5 (5.0.2) and newer releases. The syntax is the following:

 CREATE USER user [IDENTIFIED BY [PASSWORD] 'password']

Here is an example:

Code:
  1. CREATE USER 'user1'@'localhost' IDENTIFIED BY 'pass1';

Now if you check the mysql.user table you can find a new record in it. Notice that all priviliges are set to No so this user can do nothing in the DB. To add some preiviliges we can use the GRANT command as follows:

Code:
  1. GRANT SELECT,INSERT,UPDATE,DELETE ON *.* TO 'user1'@'localhost';

Here we have added only the most important priviliges to the user. With the setting above this user is good to run a CMS or a blog, however with such settings this user is not able to install them as it can not create tables.

To add all priviliges to the user you don't have to list all of them but you can use the ALL shortcut as follows:

Code:
  1. GRANT ALL ON *.* TO 'user1'@'localhost';

You can create a new MySQL user in one step as well using again the GRANT command with a small extension as here:

Code:
  1. GRANT ALL ON *.* TO 'user2'@'localhost' IDENTIFIED BY 'pass1';

The above examples used dedicated commands, but sumtimes you maybe want to add a new MySQL user via directly editing the mysql.user table. In this case you just inserts a new record into the table with a normal INSERT command:

Code:
  1. INSERT INTO user (Host,User,Password)
  2. VALUES('localhost','user3',PASSWORD('pass3'));

Or you can add some priviliges as well in a form like this:

Code:
  1. INSERT INTO user (Host,User,Password,Select_priv,Insert_priv)
  2. VALUES('localhost','user4',PASSWORD('pass3'),'Y','Y');

That's it!

Comments

Popular posts from this blog

How to Use Chisanbop (Korean Finger Math) for Basic Addition and Counting | eHow.com

How to Use Chisanbop (Korean Finger Math) for Basic Addition and Counting eHow.com Difficulty: Easy Instructions Step 1 In Chisanbop you'll be using your two hands and ten fingers to represent numbers from 0 to 99. Start out with your hands out in front of you with closed fists. This represents 0. Each finger (not thumb) on your right hand represents 1. To represent 3, just press down three right hand fingers. Your right thumb represents 5. To represent 7, press down your right thumb and 2 right hand fingers. Think of your right hand as the ones or units place (column). Step 2 Your left hand represents the tens place (column). Each finger on your left hand is worth 10. For example, to represent 30, press down three left hand fingers. To represent 38, do the same, but also use your right hand to represent 8 as described above. Your left thumb represents 50. To represent 86, press down your left thumb and three left hand fingers for the 80, and your right thumb and one righ

How to load the sample database into the MariaDB server.

1. Download  the Sample Database  (Source :  https://www.mariadbtutorial.com/getting-started/mariadb-sample-database/  ) 2. unzip the file to a directory e.g.,  c:\mariadb\nation.sql 2.   connect to the MariaDB server  with the  root  user account, type the password and press the   Enter  keyboard. sudo mysql -u root -p Enter password: ******** 3.  Load the database by using the source command: mysql>source c:\mariadb\nation.sql 4.  select the   nation   database and display tables of the database: mysql> use nation; Database changed mysql> show tables ;