Centos 执行sql文件

1、管道符

  mysql -u dump1 -p dump1 < ./test.sql

  cat test.sql
  select count(*) from dbname.tableName

2、脚本

  #!/bin/bash
  #Program:
  #       利用sh执行sql文件
  #History
  #       2017/9/22/
  cmd="select count(*) from dbname.tableName"
  cnt=$(mysql -udump1 -pdump1 -s -e "${cmd}")
  echo "Current count is : ${cnt}"
  exit

3、命令

  mysql -uroot -p123456 -e "source /root/temp.sql"

  more temp.sql   
  tee /tmp/temp.log  
  drop database if exists tempdb;  
  create database tempdb;  
  use tempdb  
  create table if not exists tb_tmp(id smallint,val varchar(20));  
  insert into tb_tmp values (1,'jack'),(2,'robin'),(3,'mark');  
  select * from tb_tmp;  
  notee 

 4、mysql命令行中

  mysql> source /scp/mysqldump/test.sql

 

参考:http://www.jb51.net/article/56944.htm

posted on 2017-09-22 15:49  Xiaox-xin  阅读(5990)  评论(1编辑  收藏  举报

导航