To create a user account from a MySQL server instance, we need to make use of a CREATE USER call to the mysql.user table.
First, fire up MySQL in your terminal and login as an administrator account with:
mysql -u root -p
You will be prompted for your root password before being granted access to the MySQL monitor.
Now to grab a list of available user accounts on the system. Running:
SELECT USER,host FROM mysql.USER;
If the user account that you wish to create doesn’t appear in that list, you are good to go. To create a new user account run the following query:
CREATE USER 'new-username'@'localhost' IDENTIFIED BY 'password-for-new-account';
If you omit the @’localhost’ section, the user account will be generated with a host value of ‘%’. If you omit the identified by section, the user account will be created without a password (which is of course quite insecure).
Of course, this user isn’t linked to any databases yet, but this is simple to rectify with a:
GRANT ALL ON mydatabase.* TO useraccount@localhost
that will grant all rights for the user account to everything held in the mydatabase database. (Note that you generally don’t want to assign all rights, so will scale back as necessary in a real world example.)
Simple and nifty.
Related Link: http://dev.mysql.com/doc/refman/5.1/en/create-user.html
You might also enjoy:
-
To delete a user account from a MySQL server instance, we need to make use of a DROP USER call to the mysql.user table. First, fire up MySQL in your ter ...
-
To get a list of user accounts on a MySQL server instance, we need to make a SELECT call to the mysql.user table. First, fire up MySQL in your terminal ...
-
To delete a database from a MySQL server instance, we need to make a DROP DATABASE call against the server. First, fire up MySQL in your terminal and lo ...
-
One of the most important things you need to do when setting up your new MySQL server instance is to set the password for the root user account. By default, ...
-
MySQL gets installed with a default root account under the username "root". Sometimes the system will allow you to install a root account without a password ...