Q:

Write a mysql statement to create a new user and set password and privileges for an existing database

belongs to collection: MySQL Exercises

0

Write a mysql statement to create a new user and set password and privileges for an existing database

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Solution:

Suppose, there is an existing database name 'Company'. To create a new user and grant access to newly created user, enter this query -

mysql->GRANT USAGE ON Company.* to champ@localhost IDENTIFIED BY 'efw232@d';

This creates new user 'champ' if it doesn't already exist, and sets the password to 'efw232@d'. This statement also permits champ user access to all tables within Company database.

Grant statement privileges to user

The above statement only allows user to log into database. To create, insert new data, the administrator has to grant permission for this.

mysql->GRANT CREATE, INSERT, SELECT, UPDATE 
	->ON Company.*
	->to champ@localhost IDENTIFIED BY 'efw232@d';

The above statement grants only permission to CREATE, INSERT, SELECT, UPDATE data. To grant all possible permission to user, enter this statement -

mysql->GRANT ALL
	->ON Company.*
	->to champ@localhost IDENTIFIED BY 'efw232@d';

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

MySQL Exercises

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write a mysql statement to select data of only CS ... >>
<< Write a mysql statement to get item id, item, pric...