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"
相關文章
相關標籤/搜索