MySQL - Execute SQL script

Words
107
Reading
1 min
Listen
Play
6y

Many times we need to run a SQL script and we do not have graphical tools such as: phpMyAdmin or Adminer so we need to use the command line and use the mysql shell and follow one of the following methods:

Execute SQL script in direct way

$ mysql -u user -p data-base < script.sql

The -p option means that the mysql shell will ask for the user password.

Authenticate and then run SQL script

  1. $ mysql -u usr -p data-base

  2. source script.sql;

    Or
    . script.sql;

If script.sql file is not in the current directory, then you must specify the absolute path where it is located.

Via

MySQL - Execute SQL script | Ecency