I found this solution many years ago, somewhere on the pentaho website and I still use it.
For sharing database connections I use a file named shared.xml in the directory ~/.kettle (in my HOME directory). You have to restart pentaho after writing / changing your file. After that you can select the database connection by name defined in your shared.xml in you transformations.
This is an example with some basic attributes. I use it as a template.
<?xml version="1.0" encoding="UTF-8"?>
<sharedobjects>
<connection>
<name>name</name>
<server>server</server>
<type>type</type>
<access>Native</access>
<database>database</database>
<port>1234</port>
<username>username</username>
<password>Encrypted ....</password>
<servername/>
<data_tablespace/>
<index_tablespace/>
<attributes>
<attribute><code>FORCE_IDENTIFIERS_TO_LOWERCASE</code><attribute>N</attribute></attribute>
<attribute><code>FORCE_IDENTIFIERS_TO_UPPERCASE</code><attribute>N</attribute></attribute>
<attribute><code>IS_CLUSTERED</code><attribute>N</attribute></attribute>
<attribute><code>PORT_NUMBER</code><attribute>3306</attribute></attribute>
<attribute><code>PRESERVE_RESERVED_WORD_CASE</code><attribute>Y</attribute></attribute>
<attribute><code>QUOTE_ALL_FIELDS</code><attribute>N</attribute></attribute>
<attribute><code>STREAM_RESULTS</code><attribute>Y</attribute></attribute>
<attribute><code>SUPPORTS_BOOLEAN_DATA_TYPE</code><attribute>Y</attribute></attribute>
<attribute><code>SUPPORTS_TIMESTAMP_DATA_TYPE</code><attribute>Y</attribute></attribute>
<attribute><code>USE_POOLING</code><attribute>N</attribute></attribute>
</attributes>
</connection> </sharedobjects>
short explanation:
name = choose a name you can identify your database...
server = localhost or IP address or FQDN
type = POSTGRESQL, MYSQL ... database type
database = the real database name used with CREATE ...
username = must be a known user to the database