Home > Database > Mysql Tutorial > body text

【Mysql】shell运行mysql的sql语句_MySQL

WBOY
Release: 2016-06-01 13:29:31
Original
1447 people have browsed it

bitsCN.com

【Mysql】shell运行mysql的sql语句

 

    shell本身是一种脚本语言,所以不能像java一样通过api去连接数据库。shell还是要借助mysql本身的一些运行脚本才能去执行sql语句。说到这很明白了,首先必须在机器上安装mysql。

   可以通过mysql/bin/mysql这个脚本来运行sql语句,格式是mysql -hhost -Pport -uusername -ppassword database -e"sql",下面是shell的代码

[plain] #!/bin/sh  bin=/usr/local/mysql/bin  username=root  password=    mysql=$bin/mysql  hostname=localhost  port=3306  database=loongdisk  table=userio    if [ "$password" == "" ]; then      inputpwd=""  else      inputpwd=-p$password  fi  #year  head=$database.${table}_month  echo $head  sql="alter table $head add column login int(10) unsigned not null default 0"  $mysql -h$hostname -P$port -u$username $inputpwd $database -e"$sql"  
Copy after login

 


bitsCN.com
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!