Database not saving imported sql file in terminal MySQL

I’ve imported an sql file to a new database. Everytime I’ve imported it, these error messages always displays.

mysql> source ./DataWarehouse/3/mysqlsampledatabase.sql
Query OK, 1 row affected, 1 warning (0.01 sec)

Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fails
ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fails
ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fails
ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fails
ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fails
Query OK, 0 rows affected (0.05 sec)

ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fails
Query OK, 0 rows affected (0.05 sec)

ERROR 1050 (42S01): Table 'productlines' already exists
ERROR 1050 (42S01): Table 'products' already exists
ERROR 1050 (42S01): Table 'offices' already exists
ERROR 1050 (42S01): Table 'employees' already exists
ERROR 1050 (42S01): Table 'customers' already exists
Query OK, 0 rows affected (0.10 sec)

ERROR 1050 (42S01): Table 'orders' already exists
Query OK, 0 rows affected (0.09 sec)

ERROR 1062 (23000): Duplicate entry 'Classic Cars' for key 'PRIMARY'
ERROR 1062 (23000): Duplicate entry 'S10_1678' for key 'PRIMARY'
ERROR 1062 (23000): Duplicate entry '1' for key 'PRIMARY'
ERROR 1062 (23000): Duplicate entry '1002' for key 'PRIMARY'
ERROR 1062 (23000): Duplicate entry '103' for key 'PRIMARY'
ERROR 1062 (23000): Duplicate entry '10100' for key 'PRIMARY'
Query OK, 273 rows affected (0.08 sec)
Records: 273  Duplicates: 0  Warnings: 0

Query OK, 2996 rows affected (0.38 sec)
Records: 2996  Duplicates: 0  Warnings: 0

After this, querying database works.

I suspect these warnings show because of already existing tables (duh), yet before I set the source file, querying SHOW TABLES; just displays Empty set (0.01 sec).. I’ve used MSSQL Server and PHPMyAdmin before, but this is my first time using a CLI based server so I’m not very knowledgeable.

It works, but I do not want to import the sql file everytime I open it. Am I supposed to save the database first or is there something I’m missing?

*I’m using Linux Crostini on ChromeOS.

Asked By: NuhUh

||

It turns out the sql file that I imported had a USE query.

I was just supposed to use the database that were set in the sql file, or delete the USE query in said sql file.

Thank you @glenn jackmann for pointing it out!

Answered By: NuhUh
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.