Shell 操做mysql

1. which mysql : 查看mysql执行命令的位置

2. -e 执行命令
 [nsns@localhost ~]$ /usr/bin/mysql -uroot -proot -e  "show tables from mysql";  

实例:
#!/bin/bash
#shell operate mysql

mysql="/usr/bin/mysql -uroot -proot"  #登陆mysql命令

sql="show databases"     #命令语句

$mysql -e "$sql"         #执行

实例二: shell 建立 mysql 表
#!/bin/bash
#shell operate mysql

mysql="/usr/bin/mysql -uroot -proot"

sql="create table test.user(

	id int unsigned auto_increment primary key,
	name varchar(58),
	passwod varchar(58)
)"

$mysql -e "$sql"
相关文章
相关标签/搜索