xo / usql

Universal command-line interface for SQL databases
MIT License
8.81k stars 346 forks source link

How to .usqlpass #459

Closed MichalisDBA closed 2 months ago

MichalisDBA commented 2 months ago

Hello.

I think i am missing something.

We have 2 Microsft SQL servers. MS1 and MS2

I create a .usqlpass file and put the following config

mssql:*:*:*:myusername:password1 mssql:*:*:*:myusername:password2

How to specify in the connection string usql mssql:// that when i want to connect to MS2 server i want the credentials of the line with password2?

The username is the same on both servers. Only the password changes.

nineinchnick commented 2 months ago

One of the entries in .usqlpass needs to have a hostname.

nineinchnick commented 2 months ago

Those two wildcard entries read in English like this:

Connect to any MSSQL server as myusername with the password as password1 AND password2

Which doesn't really make sense.

MichalisDBA commented 2 months ago

Thanks for the info but.

I put this in .usqlpass

mssql:*:*:*:myusername:password1
mssql:10.1.0.10:*:*:myusername:password2

and then tried to connect like this

usql mssql://10.1.0.10/DB_NAME

and says login failed and asked for password.

nineinchnick commented 2 months ago

You need to have the more specific entry first, so switch them. They're matched from top to bottom.

MichalisDBA commented 2 months ago

Yes that works. Maybe it has to be better documented. Thank you!

kenshaw commented 2 months ago

Please see the updated README.md, and use \cset and/or the config.yaml for usql. Thanks.