Skip to content

Execute sql file from terminal

Zhamri Che Ani edited this page Oct 8, 2025 · 4 revisions

🐬 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).

Clone this wiki locally