Datareign

There are two basic ways to run MySQL scripts:

From the O/S Command Line

Just pipe the script into your command line, as in…

$> mysql -u root -p targetdatabase <scriptname.sql

The components of this (simplified) line are:

  • -u introduces the user name. The user must have sufficient privileges for all the tables that the script addresses.
  • -p invokes a password prompt. If you want to invoke the session without having to enter a password (as in a 'cron' job) you can use the syntax –password=anystring, but this has security implications, so should be used with care.
  • Replace targetdatabase with the name of the database to run the script against.
  • Replace scriptname.sql with the name of the script to be run.

From within a MySQL session

Use the source command, which will require the complete path to the script to be run…

mysql> source /home/fred/UsersRepeatVisitsDuringPeriod.sql
Last modified: 2009/11/09 09:30