业精于勤荒于嬉,行成于思毁于随。

mysql执行sql脚本文件

上一篇 / 下一篇  2008-09-02 17:30:03 / 个人分类:点点滴滴

什么是sql文件?

在回答这个问题前先用记事本打开这种文件,发现一条条的sql语句,这就和dos中的bat批处理文件很相似,把若干命令集成到一个文件中,这样省去了重复输入的繁琐。sql文件sql语句批处理文件。

如何执行它呢?(仅限于在mysql中)

(以下内容转载http://blog.chinaunix.net/u1/44502/showart_370157.html

建立hi.sql文件:
create table hi(name char(10),id char(4));
用root用户登陆数据库:
E:\mysql\bin>mysql -u root -p123
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 26
Server version: 5.0.37-community-nt MySQL Community Edition (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
更改数据库:
mysql> use mysql;
Database changed
运行该脚本文件:
mysql> source hi.sql
Query OK, 0 rows affected (0.08 sec)
查看hi表的结构:
mysql> desc hi;
+-------+----------+------+-----+---------+-------+
| Field | Type     | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| name  | char(10) | YES  |     | NULL    |       |
| id    | char(4)  | YES  |     | NULL    |       |
+-------+----------+------+-----+---------+-------+
2 rows in set (0.02 sec)

TAG: 点点滴滴

 

评分:0

我来说两句

Open Toolbar