Import DB through CLI

Hey all, happy to be here.

I want to unzip a DB file and import it via the CLI onto my existing Local database. I can’t figure out how to do it.

If I manually open Sequal Pro and Import the database it merges. But whenever I try to run: $ /Users/chris/WhateverPath/database.sql mysql -u root -p local

I get: $ Permission denied.

Am I missing something?

Hi Chris

I had a similar need for this today and I used the import command suggested here:

Enter myloader -p root -d /app/sql --overwrite-tables --database local … This will load in the SQL files in /app/sql

1 Like

Quick reply! I like it.

Hmm, so if I understand correctly: you created a new instance, deleted the default database generated by LbF and instead added your database than ran this command?

I’m a rookie when it comes to running MySQL commands in the terminal.

Hi Chris

Yes, but that applied to my particular situation, I just referenced the command that did the importing to MySQL. Wish I could help you further, hopefully one of the devs will chime in.

@chrisschwartze,

The myloader command @lkoudal mentioned will automatically overwrite tables so there’s no need to delete the database.

Just a heads up, you’ll need to go to Local’s sidebar and then click “Open Site SSH” before you can run the commands.

Gotcha. Thanks for getting back to me @clay

Just for confirmation, an example command would be:

myloader -p root -d /app/sql --overwrite-tables --database local Users/path/to/mydatabase.sql

Is that correct?

The command will be the following:

myloader -p root -d /app/sql --overwrite-tables --database local

This command assumes that you moved the SQL files into your site’s app/sql folder which can be accessed by right-clicking on the site in Local’s sidebar, going to “Reveal in Finder…” and then navigating to app/sql in the Finder window.

Tried this solution but I’m getting the following error:

root@4ecf392a2749:/# myloader -p root -d /app/sql --overwrite-tables --database local

** (myloader:1949): CRITICAL **: the specified directory is not a mydumper backup

I had to create the sql folder in app as it didn’t exist initially…
Any ideas?

@jglass,

Got it.

Can you provide a screenshot of what’s in your app/sql folder?

45%20PM

Aha, okay.

In that case, try running: mysql -u root -proot local < /app/sql/freeskier.sql

1 Like

That was my next attempt!

1 Like

And it worked. Thanks for the quick help!

No problem, glad to hear!