MySQL - Execute SQL script

MySQL

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:

1. Execute SQL script in direct way

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

2. Authenticate and then run SQL script

$ mysql -u usr -p data-base

Then

source script.sql;

Or

. script.sql;

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

Further readings

  • man mysql

Spanish video associated

YouTube video

Serie(s): Administering MySQL from the command line, 9 (14)

The tutorials here on LibreByte are provided under a free software licence. if you like my work you should consider:
Buy a Hosting/VPS or Dedicated Server at MCKHost

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.