0

I am writing a MySQL script defining users and roles, but I don't want to upload the password to the repository. So I was guessing if I can replace those passwords with yaml variables.

USE test;

DROP USER IF EXISTS 'admin'@'127.0.0.1';
CREATE USER IF NOT EXISTS 'admin'@'127.0.0.1' IDENTIFIED BY 'password';

Changing the file to

USE test;

DROP USER IF EXISTS 'admin'@'{admin.host}';
CREATE USER IF NOT EXISTS 'admin'@'{admin.host}' IDENTIFIED BY '{admin.password}';

DROP USER IF EXISTS 'client'@'{client.host}';
CREATE USER IF NOT EXISTS 'client'@'{client.host}' IDENTIFIED BY '{client.password}';
admin:
  host: 127.0.0.1
  password: password
client:
  host: 0.0.0.0
  password: 123456

But I do not know how to implement this in MySQL. I was thinking in making a bash script to manually replace the variables, but not all of the team uses linux, so I would like to know if there is a MySQL way to do this.

2
  • Look at ansible rules rather than implementing your own. Also look at IDENTIFIED AS 'auth_string' where that is a s password hash. ref.
    – danblack
    Commented Jun 30 at 3:58
  • run `mysql -root -p whatever --database test -e " DROP USER IF EXIST ....." and run it in the command shell
    – nbk
    Commented Jun 30 at 10:24

0

Your Answer

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

Browse other questions tagged or ask your own question.