I want to create a new user in MySql. I do not want that new user to do much with my existing databases [I just want to grant Select privilege to him], but he can do anythin
To provide a specific user with a permission, you can use this framework:
GRANT [type of permission] ON [database name].[table name] TO ‘[username]’@'localhost’;
GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';
The asterisks in this command refer to the database and table (respectively) that they can access—this specific command allows to the user to read, edit, execute and perform all tasks across all the databases and tables.
Once you have finalized the permissions that you want to set up for your new users, always be sure to reload all the privileges.
FLUSH PRIVILEGES;
For more about permission you can read this article https://www.digitalocean.com/community/articles/how-to-create-a-new-user-and-grant-permissions-in-mysql
For the list of permissions, see the MySQL Manual page Privileges Provided by MySQL.
Open mysql command prompt.
To create a new user when host is localhost then use this command
CREATE user 'test_user'@'localhost' identified by 'some_password';
for any host use %, like this
CREATE user 'test_user'@'%' identified by 'some_password';
Once the user is created, you need to Grant some access. Use following command for this.
GRANT SELECT,INSERT,UPDATE
ON database_name.table_name
TO 'test_user'@'localhost';
After successful execution of above query, test_user can select, insert and update in table_name (name of table) of database_name (name of database).
grant privilege
is given in data base like this
grant privilege on object to user
object
is any data base table or relation and user
might be the whom the privilege is provided to him.
Example
grant select,insert,update,on object name to user name
grant select on employee to john with grant option;
revoke delete on employee from john.
From the MySQL grant documentation:
CREATE USER 'jeffrey'@'localhost' IDENTIFIED BY 'mypass';
GRANT SELECT ON *.* TO 'jeffrey'@'localhost';
GRANT ALL ON db1.* TO 'jeffrey'@'localhost';
The first command creates the user. The second grants select on all databases and tables. The third command grants all access to all tables in db1.
Is there anything else specific you are looking to do?