I have a fairly well defined list of 50 or so users in a mysql database. All their entires in the user table look something like this:
mysql> select user,host,password from user where host = '1.2.3.4';
+--------+---------+----------+
| user | host | password |
+--------+---------+----------+
| user1 | 1.2.3.4 | *XXX... |
| user2 | 1.2.3.4 | *YYY... |
| user3 | 1.2.3.4 | *ZZZ... |
etc.
What I would like to do is add a second entry for each user so that they can also connect from 10.% using the same password and granting full access from 10.%, but leaving the existing grants in place.
Is there a way I could do this all from within mysql (for automation purposes) or would I have to write a script that dumps the users & password hashes out then issues new grant statements for the 10.% host?
MySQL handles this by enabling you to distinguish users on different hosts that happen to have the same name: You can grant one set of privileges for connections by joe from office.example.com , and a different set of privileges for connections by joe from home.example.com .
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';
INSERT INTO user (user, host, password)
SELECT U.user, '10.x' AS NHost, U.password FROM user AS U
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With