Using PHPMyAdmin to create users

As MySQL is used on a server many different people will need to access it. This does not mean that every user who accesses MySQL needs their own account. When you come to use PHP to access MySQL you will probably use one user account for everyone. Examples of user accounts:

Using root to create another account

All MySQL servers have a "root" account which is all-powerful. It can create and delete user accounts, delete databases and more. Other users may not have permission to create more users. If you cannot create users then ignore the rest of this page and use the one user account which has been set up for you.

Load the PHPMyAdmin front page and type in the "root" as user and type in your password (XAMPP doesn't have one by default so leave it blank). The root password will have been set during installation of the server on most systems. Check the relevant support information.

Once you are in you should see something like this:

PHPMyAdmin main screen

On the left is a list of the databases on this server. As this is the root account this includes all databases. Most of the databases in this screen shot are for individual users and when they log on they see only their database and one other.

In the main section is information about the server and a section to create a new database. At the top are some tabs which access other areas of administration.

To create a user go to the Permissions tab and underneath a list of the existing users is an Add a New User link. Click it!

The top section asks you to put in a username and password (twice). In the middle section you can ask PHPMyAdmin to create a database for this user. That is how hosting companies provide their users with their own database. For now leave it.

The bottom of the page allows you to grant privileges (permissions) to administer all databases (global priviledges). As this new user is you you could grant all privileges but don't as that lets you break things! Press Go, log off as root and back in as you. You should now create your own databases without using the root account. If you ever need to create new user accounts just temporarily log in as root.

Log in as the new user and note that you cannot create new users or new databases so you are stuck!

Create another user - typically you will create one user for each Web site you have (even though they are all you) but this time create a database for the new user. The user names and passwords will be used on your PHP pages to set up a connection to the MySQL server. If you create a different user (with their own database) for each site you create then if that site is compromised (password becomes known) no other databases will be risked.

This site assumes that you have a user called "test" with the password "test" as well. If you create a user for these pages that would save you having to amend the code you copy and test.

Once you have played with creating users you could delete some of them (carefully!) on the Privileges tab. Leave at least one test user to use from now on.

submit to reddit Delicious Tweet