DiscoPosse – Using the chicken to measure IT
Technology, Cycling, Music and Madness


Technology

August 6, 2011

MySQL – Create database, user and privileges

More articles by »
Written by: Eric
Tags:

MySQL

This is a tip for the new MySQL users out there. A common and dangerous practice used by many new developers and admins is to use the root account to access databases. While this certainly gives you the access you need to manage your databases and data from your applications it also elevates privileges far beyond what you really want.

Let’s assume that you are creating a database called mycontent for an application. You will also want to create a user that has access to just that database so that it isolates the rights to only the content you want to affect.

Decide on a good name for a user. For this example I will use the classic format of databasename_user so our user will be mycontent_user which is what we will use for our application.

Make sure you choose a complex password as well. It is always best to combine upper and lower case as well as numbers. Be careful with special characters because using some characters like /\%* can cause issues with systems when they pass the characters to a command. We are going to use 7U2JkyGg9TwbNnQ as our example password.

Launch MySQL from the command line as a user who has privileges to create databases and manage security.

mysql -u myadminusername -p

 

Type in your password at the ‘Enter password:’ prompt

Now we create the database:

create database mycontent;

Next we create your database user. I am assuming that your database server is also your web server so we will use the @localhost to define the user.

grant usage on *.* to mycontent_user@localhost identified by ’7U2JkyGg9TwbNnQ’;

Next step is to apply permissions to the database for your new user:

grant all privileges on mycontent.* to mycontent_user@localhost;

And finally we check our user is able to log in and access the database. Exit from your MySQL command line and log in again using the new account:

mysql -u mycontent_user -p’7U2JkyGg9TwbNnQ mycontent 

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.5.15 MySQL Community Server (GPL)

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

Success!

Now you can use this account/password combination in your application and it will have all of the privileges necessary to manage the database, tables, indexes and content with much less chance of compromising your other databases in your system.

 



About the Author

Eric





 
 

 
tovmug

Toronto VMUG: May 23rd, 2013 Event Recap and Private Cloud Presentation

It was a beautiful sunny morning in Toronto and a great day for a VMUG meeting! May 23rd brought the first VMUG meeting of the spring here and the audience showed that they were ready to show some community love today. There we...
by Eric
0

 
 
newfeature

VMware Hybrid Cloud Launch Day – Why this is important, and What is New

So today is a big announcement day for VMware. Not a total surprise of course, because they have teased this offering for a while, and they have actually had the system in customer beta testing for a while. I know, because I wa...
by Eric
0

 
 
mongodb

DiscoPosse Review: MongoDB Applied Design Patterns

That sound you hear is my mind being blown. Rick Copeland and the folks at O’Reilly have really put together a great book here. Admittedly, it was outside of my usual comfort zone because of the depth of the content, but ...
by Eric
0

 

 
coupling

Loose coupling – Winning strategy for hardware, software and processes

With all of the SDDC (Software Defined Data Center) and SDN (Software Defined Networking) coming into the fore these days, it is good to take a look at exactly why it is getting serious focus, and what particular qualities make...
by Eric
0

 
 
No, not radio controlled plane!

SDS? SDN? Understanding the Control Plane versus the Data Plane

In a Software Defined world, we are facing lots of new challenges with bringing people up to speed with the intricacies of what makes any of our core components “Software Defined”. With EMC bringing out their new Vi...
by Eric
0

 

 
vmworld2013

VMworld 2013 Session Voting is Open!

It’s that time of year again! VMworld 2013 is open for registration, and most importantly, the session content has been submitted and is open for voting. Thanks to Viewers Like You! There is an important theme here. The c...
by Eric
0

 



Join Zipcar and get $50 in free driving Join Zipcar and get $50 in free driving Join Zipcar and get $50 in free driving

0 Comments


Be the first to comment!


Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>