Use an Environment Variable to Store Your YSQL Password

The YugabyteDB SQL shell ysqlsh provides a CLI for interacting with YugabyteDB using YSQL.

There is not a flag available on the command line to specify a password for a user.

So you’ll have to enter the password when prompted.

Example:

				
					yugabyte=# CREATE USER josh WITH PASSWORD 'password';
CREATE ROLE

yugabyte=# \q

[yugabyte@ip-10-38-2-166 bin]$ ./ysqlsh -h 10.38.2.166 -U josh
Password for user josh:
ysqlsh (11.2-YB-2.16.0.1-b0)
Type "help" for help.

yugabyte=>
				
			

However, you can define the Linux environment variable PGPASSWORD to avoid having to type the password!

Example:

				
					[yugabyte@ip-10-38-2-166 bin]$ export PGPASSWORD="password"

[yugabyte@ip-10-38-2-166 bin]$ ./ysqlsh -h 10.38.2.166 -U josh
ysqlsh (11.2-YB-2.16.0.1-b0)
Type "help" for help.

yugabyte=>
				
			

Have Fun!

Palm Trees in the Morning