# Non-default MariaDB port with lima/trellis-cli

**URL:** https://discourse.roots.io/t/non-default-mariadb-port-with-lima-trellis-cli/26847
**Category:** trellis
**Tags:** lima, trellis-cli
**Created:** 2024-03-12T22:45:11Z
**Posts:** 3

## Post 1 by @mrbberra — 2024-03-12T22:45:11Z

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
```

---

## Post 2 by @strarsis — 2024-03-15T12:59:34Z

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](https://stackoverflow.com/a/60715827/4150808).

---

## Post 3 by @mrbberra — 2024-03-21T19:18:38Z

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.
