Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to tell pgloader to use .my.cnf instead of exporting MYSQL_PWD variable #767

Open
vrtareg opened this issue Mar 20, 2018 · 8 comments
Open
Labels
Contribution Good First Issue This is a good way to contribute to pgloader for the first time WishList

Comments

@vrtareg
Copy link

vrtareg commented Mar 20, 2018

Hi

I am looking to the possibility to use secure file for MySQL password instead of exporting variable.

I can't find it in documentation and also in https://pgloader.readthedocs.io/en/latest/ref/mysql.html#mysql-database-source-specification-from

I don't want to export MYSQL_PWD

Can I use .my.cnf file instead and even sections in it for clientID1 and clientID2 and just export MYSQL_GROUP_SUFFIX?

Regards,
Areg

@vrtareg vrtareg changed the title How ti tell pgloader to use .my.cnf instead of exporting MYSQL_PWD variable How to tell pgloader to use .my.cnf instead of exporting MYSQL_PWD variable Mar 20, 2018
@vrtareg
Copy link
Author

vrtareg commented Mar 21, 2018

I am also interested if it will be possible to use variables in the options file so it could be used for different users in MySQL and PostgreSQL.

@vrtareg
Copy link
Author

vrtareg commented Mar 21, 2018

Found this #555 issue and will try it today.
May be I will pass MySQL password too but would like to hear your opinion too.

@vrtareg
Copy link
Author

vrtareg commented Mar 21, 2018

I have managed to do this in an interesting way:

  • I have created a template file with variables in it.
  • In script files parsing template and replacing it with actual values
  • I have created source file to parse .my.cnf file and export PWD, HOST and PORT variables for MYSQL

So for now I am missing messages in the output about the copy progress.
Is there anything changed so far so they are gone?
Shall I use --debug option?

Regards,
Areg

@dimitri
Copy link
Owner

dimitri commented Mar 22, 2018

Can you link to MySQL documentation about that .my.cnf file? How does it compare with .pgpass that pgloader has support for? It might be best for pgloader to learn how to read .my.cnf?

@vrtareg
Copy link
Author

vrtareg commented Mar 22, 2018

Yes sure.

This is documented in the https://dev.mysql.com/doc/refman/5.6/en/environment-variables.html page and MYSQL_GROUP_SUFFIX is described in https://dev.mysql.com/doc/refman/5.6/en/option-file-options.html#option_general_defaults-group-suffix

Client Password security is described in https://dev.mysql.com/doc/refman/5.6/en/password-security-user.html

So in general it is working in the way if you have .my.cnf in your home mysql client will read it for details like:

[client]
host     = <host>
database = <database>
user     = <user>
password = <password>
port     = <port>

At the same time if you have multiple MySQL servers you can or use --defaults-extra-file=file_name switch to tell which mysql file to read or have single file like

[client_1]
host     = <host_1>
database = <database_1>
user     = <user_1>
password = <password_1>
port     = <port_1>

[client_2]
host     = <host_2>
database = <database_2>
user     = <user_2>
password = <password_2>
port     = <port_2>

and use MYSQL_GROUP_SUFFIX switch to tell mysql to read or _1 or _2 section.

I hope that this will help on implementation and avoiding password variable export.

@vrtareg
Copy link
Author

vrtareg commented Apr 29, 2018

Just wondering if you had a chance to have a look.

@dimitri
Copy link
Owner

dimitri commented May 2, 2018

Not yet no, do you want to have a look at doing it yourself? pgloader already includes a lib that knows how to parse INI files, it should be a nice first patch!

@DarkMukke
Copy link

is there any progress on this ?

@dimitri dimitri added the Good First Issue This is a good way to contribute to pgloader for the first time label Mar 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Contribution Good First Issue This is a good way to contribute to pgloader for the first time WishList
Projects
None yet
Development

No branches or pull requests

3 participants