Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How Do I Create And Run Scripts

Status
Not open for further replies.

ToeShot

Programmer
Sep 8, 2001
400
0
0
US
I have created a script, with notepad, that looks like this

CREATE TABLE LOCATION (
LOCATION_ID SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
LOCATION_NAME VARCHAR(20) NOT NULL,
ADDRESS VARCHAR(60) NOT NULL,
CITY VARCHAR(25) NOT NULL,
STATE CHAR(2),
ZIP MEDIUMINT UNSIGNED NOT NULL,
PHONE INT UNSIGNED,
PRIMARY KEY (LOCATION_ID));


I have named this LOCATION with no extension. The reason only one table in this is cause I am trying to learn MySql and if I have problems I figure one smal script would be easy to debug.

At the MySql shell I have tried

Mysql> < &quot;c:\\LOCATION&quot;
MySql> < c:\\LOCATION
MySql> < c:\LOCATION
MySql> < c:\LOCATION
MySql> < LOCATION
MySql> < &quot;LOCATION&quot;


I have also tried using:
\.
SOURCE
LOAD DATA INFILE


One message I get is
Failed to load file 'c:\\LOCATION'

MySql Doc did not give a very good example as in how to run script files or how to create one and since I am a newbie at this I would appreciate any help.

I am Running WIN95 with the latest Version of MySql 3.23.41

Thanks In Advance

 
i am not certain that mysql has a &quot;read from file X&quot; command, however, you can run MySQL with a file as its input source as follows:

c:\sqldir> c:\mysql\bin\mysql < c:\scripts\myscript.txt

That will open mysql using c:\scripts\myscript.txt for input and mysql will exit at the end of the input file.

Hope it helps
Jim
B-)
 
you can also use a batch file like this...

Create file called batch.bat with this code...

%%%%%%%%Code for batch.bat%%%%%%%%%%%%%%
use yourdatabase

select * from yourtable;

exit
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


at prompt

mysql -u user -p < batch.bat

this then asks for password then runs the script


hope that helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top