Non-default MariaDB port with lima/trellis-cli

I’m trying to run a trellis project locally with the lima-based cli. I have another SQL server running on my machine, and I’d like to set up the mariadb instance to use 3307 so that my other server can continue using 3307.

Has anyone had success running trellis with a different sql port?

Here’s the changes I have made:
roles/mariadb/templates/my.cnf.j2

# {{ ansible_managed }}

[client]
user=root
password="{{ mysql_root_password }}"
port={{ mysql_port }} # added this line

group_vars/development/main.yml

acme_tiny_challenges_directory: "{{ www_root }}/letsencrypt"
env: development
mysql_root_password: "{{ vault_mysql_root_password }}"
web_user: "{{ ansible_user | default ('vagrant') }}"
mysql_port: 3307 # added this line

But when I run trellis vm start I still get this in the output:

INFO[0015] [hostagent] Forwarding TCP from 127.0.0.1:3306 to 127.0.0.1:3306

As Lima apparently does automatic port forwarding, one can assume that mysqld still uses the default port.

The reason is that you are setting the port in the [client] section of my.cnf (in the Jinja 2 template that you listed), it must be set in the [mysqld] section instead, see How to change port in mysql in cnf file - Stack Overflow.

Ah thank you! This put me on the right track.
I ended up having to actually put it in a different file, similar to how the trellis-provided disable-binary-logging is set up. For future reference, here’s the setup that worked for me:

in trellis/roles/mariadb/defaults/main.yml, added the variable with default

mysql_nonstandard_port_enabled: false

in trellis/group_vars/development/main.yml, added the override

mysql_nonstandard_port_enabled: true

in trellis/roles/mariadb/tasks/main.yml, added this after the “Disable MariaDB binary logging” step

  - name: Use nonstandard MySQL port
    template:
      src: use-other-port.cnf
      dest: /etc/mysql/conf.d
      owner: root
      group: root
      mode: '0644'
    notify: restart mysql server
    when: mysql_nonstandard_port_enabled | bool

created trellis/roles/mariadb/templates/use-other-port.cnf

# {{ ansible_managed }}

[client-server]
port=3307

There’s probably something more sophisticated I could’ve done to make the port number a variable, but this works for my needs.