mysql的source_mysql中source用法一瞥

1、source语法如下Usage:mysql>. | source 举例mysql>. /usr/local/mysql/aa.sqlQuery OK, 0 rows affected (0.01 sec)2、直接使用source filename或者. filename,怎么去实现?首先查看mysql基目录和数据目录:mysql> show variables like 'basedir';+---------------+------------------+| Variable_name | Value            |+---------------+------------------+| basedir       | /usr/local/mysql |+---------------+------------------+1 row in set (0.01 sec)mysql> show variables like 'datadir';+---------------+------------------+| Variable_name | Value            |+---------------+------------------+| datadir       | /opt/mysql/data/ |+---------------+------------------+1 row in set (0.00 sec)把aa.sql文件分别放在该目录下:mysql> . aa.sqlERROR:Failed to open file 'aa.sql', error: 2查看当前登陆位置:mysql> system pwd;/homemysql>把aa.sql文件放在home目录下,再次执行source指令:mysql> . aa.sqlQuery OK, 0 rows affected (0.02 sec)mysql> show tables;+--------------------+| Tables_in_iloveyou |+--------------------+| emp                |+--------------------+1 row in set (0.00 sec)3、完整示例[root@gflinux3 opt]# mkdir rgf[root@gflinux3 opt]# cd rgf[root@gflinux3 rgf]# cp /home/aa.sql .[root@gflinux3 rgf]# pwd/opt/rgf[root@gflinux3 rgf]# mysql -uroot -pEnter password:Welcome to the MySQL monitor.  Commands end with ; or g.Your MySQL connection id is 250Server version: 5.5.37-log Source distributionCopyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.mysql> use rgf;Database changedmysql> source aa.sql;Query OK, 0 rows affected (0.01 sec)4、注意事项(a)使用source时,文件最后使用;分号和不适用分号语法都正确mysql> source aa.sql;Query OK, 0 rows affected (0.01 sec)mysql> drop table emp;Query OK, 0 rows affected (0.00 sec)mysql> source aa.sqlQuery OK, 0 rows affected (0.01 sec)(b)使用.时,语句结尾不能使用分号;mysql> . aa.sqlQuery OK, 0 rows affected (0.01 sec)mysql> drop table emp;Query OK, 0 rows affected (0.01 sec)mysql> . aa.sql;ERROR:Failed to open file 'aa.sql;', error: 25、小结source执行的当前目录即为启动mysql登陆时所处的位置。如果不想直接输入一大串目录执行sql文件,可以事先在指定位置创建好文件夹,在文件夹中创建脚本,并从文件夹位置登陆mysql。这也是一种处理问题的方法。另外还要注意source和.的语句结尾是否要带分号。有兴趣的伙伴可以试试。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值