Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grant CREATE TABLE permission to MySQL User

I have a database that is shared between some users, and I want to manage their permissions on this.

I want to give permission for creating a new table, and accessing (select, insert, update, delete) to that table of course, to a user that doesn't have full permission on the database (only he has SELECT access to some tables).

So, I executed this query:

GRANT CREATE ON eh1 TO user1

Then, when I logged in with that user and tried to create a new table, I got this error:

1142 - CREATE command denied to user 'user1'@'localhost' for table 'folan'

What is the problem here? How can I do that?

UPDATE

The problem solved partially by changing the command to this:

GRANT CREATE ON eh1.* TO user1

Now there is another problem, that the user1 cannot select or insert into the newly created table. The reason is understandable, but is there a way to solve this?

Thanks

like image 604
Ahmad Avatar asked Sep 02 '15 12:09

Ahmad


People also ask

How do I grant permission to run a user in MySQL?

The syntax for granting EXECUTE privileges on a function/procedure in MySQL is: GRANT EXECUTE ON [ PROCEDURE | FUNCTION ] object TO user; EXECUTE. The ability to execute the function or procedure.

How do I grant permission to select a table in MySQL?

Select the statements for only the tables you would like to grant access to and run those queries. For example, if we only wanted to grant access to the Users and Visitors table we would run: GRANT SELECT, SHOW VIEW ON mydatabase. `Users` to 'myuser'@`myhost`; GRANT SELECT, SHOW VIEW ON mydatabase.

How do I grant access to a table?

Right-click a table and then choose Properties. Click the Permissions tab and configure the permissions for the table: Click Grant.

How do I grant creating table privileges to user in MySQL?

To GRANT ALL privileges to a user , allowing that user full control over a specific database , use the following syntax: mysql> GRANT ALL PRIVILEGES ON database_name. * TO 'username'@'localhost';


1 Answers

use as per below-

GRANT CREATE ON eh1.* TO user1@'%' IDENTIFIED BY 'user1_password';

Note: '%' will provide access from all ips, so we should provide rights to specific ip instead of all ips, so change '%' with any ip like '191.161.3.1'

If user need select/insert/update/delete/create rights then syntax will be -

GRANT SELECT, INSERT, UPDATE, DELETE, CREATE ON eh1.* TO user1@'%' IDENTIFIED BY 'user1_password';

Update as per user requirement:

GRANT CREATE ON eh1.* TO user1@'%' IDENTIFIED BY 'user1_password';
GRANT SELECT, INSERT, UPDATE ON eh1.table1 TO user1@'%';
GRANT SELECT, INSERT, UPDATE ON eh1.table2 TO user1@'%';
like image 123
Zafar Malik Avatar answered Oct 08 '22 06:10

Zafar Malik