Monday 9 January 2012

MySQL source Command

The source command runs SQL commands from an operating system file. I created the file below:
 
UNIX > cat my_first_script
create database fred;
select database();
use fred;
select database();
create table freds_table
(col1 varchar(10));
desc freds_table;
drop table freds_table;
show tables;
drop database fred;
UNIX >
 
... and it produced the following output when I ran it from within MySQL:
 
mysql> source my_first_script
Query OK, 1 row affected (0.00 sec)
 
+------------+
| database() |
+------------+
| NULL       |
+------------+
1 row in set (0.00 sec)
 
Database changed
+------------+
| database() |
+------------+
| fred       |
+------------+
1 row in set (0.00 sec)
 
Query OK, 0 rows affected (0.01 sec)
 
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| col1  | varchar(10) | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
1 row in set (0.00 sec)
 
Query OK, 0 rows affected (0.00 sec)
 
Empty set (0.00 sec)
 
Query OK, 0 rows affected (0.00 sec)
 
mysql>

No comments: