Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Re-assign host access permission to MySQL user

I have several thousand MySQL users all set to allow access from a specific host. The problem is that now I'm going to have two machines (more in the future) which will need to use the same account to access each of their databases.

I'd like a quick and easy (as automated as possible) way to run through and modify the host portion of each user account to fit an internal network wildcard. For example:

'bugsy'@'internalfoo' has access to the 'bugsy' DB.

I want to now allow bugsy access from anywhere on the internal network

'bugsy'@'10.0.0.%' has access to the 'bugsy' DB.

like image 353
Nick Jennings Avatar asked Dec 16 '09 11:12

Nick Jennings


People also ask

How do I change user permissions in MySQL?

You can't currently change a user's privileges in the control panel, so to do so you need to use a command-line MySQL client like mysql . After you create a user in the cluster, connect to the cluster as doadmin or another admin user.

How do I grant permission 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';

What does @% mean for host in MySQL?

'%' mean you can login into database from any host connected to those database. You also define your localhost as host if you want to access database from localhost. to change your password: SET PASSWORD FOR 'me'@'%' = PASSWORD('letmein');


1 Answers

The accepted answer only renamed the user but the privileges were left behind.

I'd recommend using:

RENAME USER 'foo'@'1.2.3.4' TO 'foo'@'1.2.3.5'; 

According to MySQL documentation:

RENAME USER causes the privileges held by the old user to be those held by the new user.

like image 104
Pedro Avatar answered Sep 29 '22 05:09

Pedro