在mysql命令行中使用source

rainbowliuliang 2008-01-04 06:07:00
我写了两行插入语句
存放在了2.sql文件里(放在了桌面)
在mysql命令行中使用source 2.sql 出错
想要执行2.sql该怎么去做
我的是xp系统 还有一种方法是在系统的命令行里 如何去做(这个可以不回 呵~)
多谢高手指教
分少新人 谢谢
...全文
6437 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
hansyang 2009-05-21
  • 打赏
  • 举报
回复
6 楼,以为你的mysql不在系统的环境变量里,你可以通过下面的方法来增加
windows:
右键"我的电脑"-"属性"-"高级"-"环境变量"
Linux:
whereis mysql 查看mysql安装的位置,没有的话需要安装
env 看看系统环境变量
nuby11 2008-10-06
  • 打赏
  • 举报
回复
为什么我从cmd里调不出MySQL啊,怎么调啊,刚学它
lxh_kocy 2008-03-22
  • 打赏
  • 举报
回复
谢谢大侠们~
^-^
rainbowliuliang 2008-01-05
  • 打赏
  • 举报
回复
呵~ 分少 你们两人分吧
懒得去死 2008-01-04
  • 打赏
  • 举报
回复

第一种
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| testtable |
+----------------+
1 row in set (0.00 sec)

mysql> select * from testtable;
+----+-------------------------+
| id | t_str |
+----+-------------------------+
| 1 | test1,test2,test3,test4 |
| 2 | test2,test3,test4 |
| 3 | test3,test4 |
| 4 | test4 |
+----+-------------------------+
4 rows in set (0.00 sec)

mysql> \q
Bye

C:\>mysqldump -uroot -p --add-drop-table --tables test testtable>c:\\testtable.sql
Enter password: ******

C:\>mysql -uroot -p
Enter password: ******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1311
Server version: 5.0.45-community-nt MySQL Community Edition (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> use test
Database changed
mysql> truncate table testtable;
Query OK, 4 rows affected (0.02 sec)

mysql> select * from testtable;
Empty set (0.00 sec)

mysql> source c:\\testtable.sql
Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.03 sec)

Query OK, 0 rows affected (0.02 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 4 rows affected (0.00 sec)
Records: 4 Duplicates: 0 Warnings: 0

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

mysql> select * from testtable;
+----+-------------------------+
| id | t_str |
+----+-------------------------+
| 1 | test1,test2,test3,test4 |
| 2 | test2,test3,test4 |
| 3 | test3,test4 |
| 4 | test4 |
+----+-------------------------+
4 rows in set (0.00 sec)
mysql> truncate table testtable;
Query OK, 4 rows affected (0.02 sec)

第二种

C:\>mysql -uroot -p -b test< c:\\testtable.sql
Enter password: ******

C:\>mysql -uroot -p
Enter password: ******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1314
Server version: 5.0.45-community-nt MySQL Community Edition (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> use test
Database changed
mysql> select * from testtable;
+----+-------------------------+
| id | t_str |
+----+-------------------------+
| 1 | test1,test2,test3,test4 |
| 2 | test2,test3,test4 |
| 3 | test3,test4 |
| 4 | test4 |
+----+-------------------------+
4 rows in set (0.00 sec)

mysql>
XFliangwh 2008-01-04
  • 打赏
  • 举报
回复
搞个桌面的给你

mysql> source C:/Documents and Settings/Administrator/桌面/2.sql;
+----+-------------+--------+
| ID | adStyleName | isUsed |
+----+-------------+--------+
| 1 | 全屏广告 | 1 |
| 2 | 对联广告 | 1 |
+----+-------------+--------+
2 rows in set (0.00 sec)
XFliangwh 2008-01-04
  • 打赏
  • 举报
回复
mysql> use ad;
Database changed
mysql> source C:/2.sql;
+----+-------------+--------+
| ID | adStyleName | isUsed |
+----+-------------+--------+
| 1 | 全屏广告 | 1 |
| 2 | 对联广告 | 1 |
+----+-------------+--------+
2 rows in set (0.00 sec)

可以阿,要完整路径,用'/'这种斜杠

56,678

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧