can't import existing sql file to an empty database: db_name.table_name doesn't exist

Viewed 176

I'm trying to import existing database file into an empty SQL database with the following command:

mysql -u username -p'password' db_name < dbfile.sql

but I get following Error:

ERROR 1146 (42S02) at line 1: Table 'db_name.oc_address' doesn't exist

I know that oc_address is a table name inside the SQL file, but I don't know what to do to import it correctly, I searched the web and also stack-overflow, found nothing on this error.

2 Answers

To export an entire database and then load it into another server, your best bet is to use the mysqldump command line utility. Its export files contain the data definition language (tables, views, all that) for the database as well as the data.

You can also get it to export just the definitions.

mysqldump --no-data -u username -p'password' db_name > opencartddl.sql

Then you can import that file first, then your data file.

Or, you may be able to stand up a new, empty, Opencart instance and use its UI to import your data.

It's probably wise to avoid trying to write replacement DDL yourself if you can get a tool like mysqldump to do it.

Related