Setting a Specific External Port for MySQL in Lando
Lando sets an external MySQL port dynamically by default. This means every time you (re)start a lando app it gets (potentially) a different external MySQL port. This is an annoyance as you have to change your port in TablePlus, SequelPro, or whatever MySQL GUI you’re using.
There is a simple fix: use a local lando file to override the forwarded MySQL port. These steps assume you already have a working .lando.yml file.
Step 1: Create a local lando file: .lando.local.yml
1 2 3 |
services: database: portforward: 3307 <-- Specify an available port here |
Step 2: Run lando rebuild if you’ve already started the site in the past
Step 3: Verify the settings by running lando info
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
adam@acmbp sandbox % lando info [ { service: 'appserver', urls: [ 'https://localhost:50126', 'http://localhost:50127', 'http://sandbox.lndo.site/', 'https://sandbox.lndo.site/' ], type: 'php', healthy: true, via: 'apache', webroot: '.', config: {}, version: '7.3', meUser: 'www-data', hasCerts: true, hostnames: [ 'appserver.sandbox.internal' ] }, { service: 'database', urls: [], type: 'mysql', healthy: true, internal_connection: { host: 'database', port: '3306' }, external_connection: { host: '127.0.0.1', port: '3307' }, healthcheck: 'bash -c "[ -f /bitnami/mysql/.mysql_initialized ]"', creds: { database: 'main_db', password: 'main_pass', user: 'main_user' }, config: {}, version: '5.7', meUser: 'www-data', hasCerts: false, hostnames: [ 'database.sandbox.internal' ] } ] |
Step 4: Add .lando.local.yml to your .gitignore file
This site will always get the port you specified if it’s available when you start the app. You can use this port in your MySQL gui, scripts, etc.