Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to GRANT ALL PRIVILEGES to the same user from multiple LAN addresses in a single command?

Tags:

mysql

I'm using the following command

GRANT ALL PRIVILEGES ON *.* TO 'user'@'ip' 
IDENTIFIED BY 'password' 
WITH GRANT OPTION;

To grant all privileges to a user. Is there a way I can make the ip a wildcard like 192.168.1.* so that I don't need to manually add each LAN ip I want give the user access to connect from?

like image 394
user784637 Avatar asked Jan 06 '12 20:01

user784637


People also ask

How do I grant all privileges to user?

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.

How do I grant multiple privileges in MySQL?

In this syntax: First, specify one or more privileges after the GRANT keyword. If you grant multiple privileges, you need to separate privileges by commas. Second, specify the privilege_level that determines the level to which the privileges apply.

How do I grant specific privileges to a user in MySQL?

The GRANT statement allows you to set MySQL access permissions using the following syntax: mysql> GRANT privilege ON privilege_level TO account_name; Type the following to grant `SELECT` and `INSERT` privileges to a local user on the `strongdm` database: mysql> GRANT SELECT, INSERT ON strongdm.

Which SQL statement grants a privilege to all the database users?

You can use the SQL GRANT statement to grant SQL SELECT, UPDATE, INSERT, DELETE, and other privileges on tables or views. The WITH GRANT OPTION clause indicates that JONES can grant to other users any of the SQL privileges you granted for the ORDER_BACKLOG table.


2 Answers

Yes, use % in an address.

GRANT ALL PRIVILEGES ON *.* TO 'user'@'192.168.1.%' 
IDENTIFIED BY 'password' 
WITH GRANT OPTION;

Or you can use less restrictive host name and allow user to connect from everywhere.

GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' 
IDENTIFIED BY 'password' 
WITH GRANT OPTION;
like image 197
Sergio Tulentsev Avatar answered Sep 19 '22 00:09

Sergio Tulentsev


According to your requirement,

Let's start by making a new user called "chaminda" within the MySQL shell:

CREATE USER 'chaminda'@'%' IDENTIFIED BY 'password';

The first thing to do is to provide the user with necessary permission and here I have given all permission to the particular user.

GRANT ALL PRIVILEGES ON * . * TO 'chaminda'@'%' WITH GRANT OPTION;

Reload all the privileges.

FLUSH PRIVILEGES;

Note: Here host Name = % and that means you can access this database server from any host. Giving all privileges to the user is a big risk and that's not a best practice.

like image 44
Chaminda Bandara Avatar answered Sep 21 '22 00:09

Chaminda Bandara