1

I am migrating to a docker MariaDB setup and all my users were created w/ "Localhost". From what I read and tested ironically '%' excludes localhost. I want to copy my existing users adding a second entry utilizing '%' as the hostname. Any suggestions?

asked May 5, 2020 at 4:15
2
  • which mariadb version? Commented May 5, 2020 at 5:59
  • Why did you remove the mariadb tag? Commented May 5, 2020 at 8:46

2 Answers 2

2

You have to call SHOW CREATE USER 'username'@'localhost' and SHOW GRANTS FOR 'username'@'localhost' for all the users fetched by

SELECT user, host 
 FROM mysql.user
 WHERE host = 'localhost'

and to replace all 'localhost' entries by '%' in the returned statements.

answered May 5, 2020 at 7:51
2
  • @FreeSoftwareServers It's not a problem to update an user already having grants. But if you want to copy some user you have to copy his grants too. The easiest way to do that is to fetch SHOW CREATE USER and SHOW GRANTS FOR then substitute hostname by desired value and then run that statements. There is no native tool to do that at once. Commented May 5, 2020 at 8:51
  • You might find my SQL User Backer tool of use. It will extract all of the users and grants and all you'd have to do is change localhost to % and load the modified files. Commented May 5, 2020 at 10:56
0

You can use mariadb-dump (previously called mysqldump) to dump all the users and their grants to an SQL file:

mariadb-dump --system=users > /tmp/users.sql

If you really want to copy all localhost users to % users, then use the search-and-replace feature in your favourite GUI editor. Or, in a Unix-like environment you can do something like:

 sed -i 's/localhost/%/g' /tmp/users.sql
answered Aug 25, 2024 at 17:57

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.