Lando ships with a helper
db-import script that is available in all our
LEMP based recipes. Used in the recipe context it should import a database dump into the recipe-provided database by default.
You can also import databases into other hosts and databases. It will currently handle uncompressed, gzipped or zipped dump files.
This command will wipe out the target database before it runs the import unless you use the
Postgres import not yet supported
Lando will only handle
mariadb compatible files at this time.
lando db-import somedumpfile.sql.gz
DB dump must reside within app directory
Due to restrictions in how Docker handles file sharing your database dump MUST exist somewhere inside of your app directory. This means that IT IS A VERY GOOD IDEA to make sure you add SQL dumps to your
# Import a file into the recipe-provided db lando db-import dump.sql # Import a file into an auxiliary second database called 'db2' # with a db called `dataz` lando db-import dump.zip --host db2 --database dataz # Import without destroying the target database lando db-import dump.zip --no-wipe # Pipe stdout into db-import # NOTE: this is a bit finicky right now cat dump.sql | lando db-import
Options: --host, -h The database host --user, -u The database user [default: "root"] --database, -d The database name --password, -p The database password --port, -P The database port [default: 3306] --no-wipe Do not destroy the existing database before an import
If you are not using one of our
php-y recipes you can add the
db-import command and default options to your
.lando.yml as follows.
# The name of the app name: mysql-import # Give me http://mysql-import.lndo.site and https://mysql-import.lndo.site proxy: nginx: - mysql-import.lndo.site # Set up my services services: # Set up a basic webserver running the latest nginx with ssl turned on appserver: via: nginx type: php:7.1 ssl: true webroot: www # These environmental variables will set the default host/user/port/name/password options for # db-import overrides: services: environment: DB_HOST: db DB_USER: mysql DB_PASSWORD: mysql DB_NAME: data1 DB_PORT: 3306 # Spin up a mariadb container called "database" # NOTE: "database" is arbitrary, you could just as well call this "db" or "kanye" db: # Use the latest version of mysql type: mysql # Optionally forward out our port so we can access it at `localhost:someport`. # This port will change every time you restart this app # # You can also set this to a static port you want to use `portforward:3311`. # You will need to make sure the port is open and avialable portforward: 5309 # Optionally change the default db credentials creds: user: mysql password: mysql database: data1 # Optionally load in all the mysql config files in the config directory # This is relative to the app root # config: # confd: config tooling: mysql: service: appserver description: Drop into a mysql shell for the import target needs: - db cmd: mysql -h db -u mysql -pmysql data1 'db-import ': service: appserver needs: - db description: Import into database cmd: /helpers/mysql-import.sh options: host: description: The database host alias: - h user: description: The database user default: root alias: - u database: description: The database name alias: - d password: description: The database password alias: - p port: description: The database port default: 3306 alias: - P
You will need to rebuild your app with
lando rebuild to apply the changes to this file. You can check out the full code for this example over here.