Creating mysql users

8:41 PM

Work in Progress

The SQL statement for creating users is of the following form:
GRANT (rights) ON (database).(table) TO (user)@(host) IDENTIFIED BY (password);
  • rights = one or more of SELECT, INSERT, UPDATE, DELETE (see *note below)
  • database = the database name
  • table = the tables th euser is allowed to use or * for all tables
  • user = the username the user will connect with
  • host = the hostname the user will be allowed to connect from, or % for all hosts
  • password = the password the user must supply to connect
examples:
GRANT SELECT,INSERT,UPDATE,DELETE ON projectX.* TO 'joeuser'@'%' IDENTIFIED BY 'supersecretpassword';
In this instance, the user joeuser will be allowed to connect from any host. joeuser will be able to execute SELECT, INSERT, UPDATE and DELETE statements against any table in the projectX database.
GRANT SELECT ON accounting.users TO 'receptionist'@'frontdesk.company.com' IDENTIFIED BY 'goodmorning';
The receptionist user may connect only from the computer frontdesk.company.com. Additionally, receptionist may only execute SELECT statements against the users table in the accounting database. Any attempts to change data (through INSERT, UPDATE or DELETE statements) or to access any other table in the accounting database will result in an access denied error message.
*Note about rights:
MySQL has a number of rights that can be granted to users. Chief among them are
  • SELECT (query data)
  • INSERT (add data)
  • UPDATE (change data)
  • DELETE (remove data)
  • CREATE (create tables)
  • ALTER (change tables)
  • DROP (remove tables)
  • INDEX (create or remove indexes)
Additional rights are available for specific needs (creating and using stored procedures, replication, loading and unloading data, shutting down the database, etc.) and should be avoided.

You Might Also Like

0 comments

Contact Form

Name

Email *

Message *

Translate

Wikipedia

Search results