faqts : Computers : Databases : MySQL

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

42 of 50 people (84%) answered Yes
Recently 8 of 10 people (80%) answered Yes

Entry

Database: MySql: Command: File: Source: Read: How to: How to read commands from a file? [batch]

Jul 6th, 2008 13:24
Knud van Eeden, dman,


----------------------------------------------------------------------
--- Knud van Eeden --- 10 April 2005 - 07:04 pm ----------------------

Database: MySql: Command: File: Source: Read: How to: How to read 
commands from a file? [batch]

---

Steps: Overview:

 1. -Create a text file containing your commands
     (you will not see the SQL query text while they are executed)


     e.g.

--- cut here: begin --------------------------------------------------

CREATE DATABASE databaseTest;

USE databaseTest;

CREATE TABLE
 tableCustomer
(
 columnId INT NOT NULL PRIMARY KEY,
 columnName VARCHAR( 50 )
)
;

INSERT INTO
 tableCustomer
(
 columnName
)
VALUES
(
 "Knud"
)
;

--- cut here: end ----------------------------------------------------

 2. -Save this file in the 'bin' directory of MySql

      e.g.

       mysourcefile.txt

 3. -Goto the 'bin' directory of MySql

 4. -Run the program

      mysql.exe

 5. -Type the command

      source <your filename>

      ---

       e.g.

        source mysourcefile.txt;

---
---

Note:

If you create the file after you started
MySql, you will have to restart mysql.exe
(otherwise error
 'Failed to open file '...', error: 2')

---
---

Internet: see also:

---

Database: MySql: Command: Multiple: Execute: How to execute multiple 
commands at once in MySql?
http://www.faqts.com/knowledge_base/view.phtml/aid/36416/fid/52

----------------------------------------------------------------------