Execute sql file from terminal - zhamri/MyClass-MySQL GitHub Wiki

🐬 For MySQL / MariaDB

βœ… Option 1: Using MySQL Command Line

mysql -u root -p cmsdb < /Users/zhamri/desktop/cms.sql

cmsdb β†’ your target database name

-u root β†’ username

It will prompt for your password, then execute all the SQL statements inside cms.sql.

If your database doesn’t exist yet:

mysql -u root -p -e "CREATE DATABASE cmsdb;"
mysql -u root -p cmsdb < /Users/zhamri/desktop/cms.sql

βœ… Option 2: Inside MySQL Console

mysql -u root -p

Then inside the MySQL prompt:

USE cmsdb;
SOURCE /Users/zhamri/desktop/cms.sql;

πŸ’‘ Tip: You can check your current path using pwd (in Unix/macOS).