Creating a MySQL user via the command line

Now that you have installed your MySQL 5 server on your Windows server, it is time to start getting into the nuts and bolts of it. In this guide we'll show you the steps needed to create a new MySQL user by using the MySQL command line client. In most instances these days you'll be able to use a GUI manager for MySQL such as phpMyAdmin, but in some instances you may need to do it via the command line. Creating a user is a very easy procedure, so lets get into it.
  • Start the MySQL command line client by selecting the MySQL Command Line Client item from your MySQL program group in your start menu.
  • The MySQL command line client will prompt you for the root password. Enter it and push enter.
  • To create a user simply type in;
CREATE USER 'test'@'localhost' IDENTIFIED BY 'your_password';
  • This will create a user called test on localhost with a password of your_password. Simply replace the name and the password with what you want.
  • Finally, lets verify that the your user has been created. Type in;
SELECT user FROM mysql.user;
  • This will list all the users on your server, and you';ll see our test user listed.
  • Refer to figure 1 below to see an example of the MySQL command line output you would expect to see by running these commands.
Figure 1
All done. Told you there wasn't much to it!
Average rating
(9 votes)


Anonymous's picture


it would be nice to add info about granting privileges :)

Brashquido's picture

Have a look at this guide

Already done. Have a look at this guide for details on granting privileges via the command line.
Dominic Ryan
4 x Microsoft IIS MVP, MCSE, MCSA
IIS Aid owner/webmaster

Anonymous's picture

plz add grant and login cmd

Plz add grant and
How to login with this user instead of root.

Brashquido's picture

Assigning MySQL privileges via the command line

See link in the comment directly above yours for a guide on granting permissions via the command line. I'd also would not advise using the command line interface for anything but the basics (create user/database & assign permissions) for the beginner. I'd recommend using something like phpMyAdmin, or even the MySQL Workbench from the MySQL site.

Dominic Ryan
5 x Microsoft IIS MVP, MCSE, MCSA
IIS Aid owner/webmaster

SoloTech's picture

mySQL commandline


Is it possible to submit a file to the commandline, containing all instructions required to inialise a new mySQL database at application installation?

To explain, we recently converted our Windows based apps from DAO to ADO, using a mySQL database on the local PC, which in turn, talks to a hosted remote mySQL DB.

When we deploy our app to a new customer, we need to minimise user interaction as much as possible, We will supply the mySQL DB, as part of the installation, but need to send the username/password to the database, duing installation.

Can the file based commands work in this case?


Brashquido's picture

Can't see why not..

There are many automation apps out there which do this using various methods. Rather than using a script to interface with the command line though I'd probably suggest doing this via the scripts native API. I'm not sure how you would do this specifically with ADO however.

Dominic Ryan
6 x Microsoft IIS MVP, MCSE, MCSA
IIS Aid owner/webmaster