It is important to know if the .sql file has code that will create the database if the database does not exit. The .sql file can be opened in Notepad++. If the file contains the commands CREATE DATABASE IF NOT EXISTS, the .sql file does include the commands to create the databases.
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `example` /*!40100 DEFAULT CHARACTER SET latin1 */;
Use this command to import the SQL file.
mysql -u root -p < the_file.sql
On the other hand, if the .sql file appends data to a database that already exists, you need to list the name of the database in Terminal.
mysql -u root -p databasename < the_file.sql
To verify that the data was imported, connect to your MySQL or MariaDB, and use the show databases, use database, show tables and select * from tablename commands.