#!/bin/sh
#define the strcture of table
TABLE="(username char(50) not null,password char(20) not null,uid char(10) not null,gid char(10) not null,maildir char(100) not null,domain char(20) not null,active char(1) default "1");"
#create database and table
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
for type in database table;do
printf "Please input the $type name you would like to create:[postfix]"
while read data;do
if [ ! -z ${data} ]; then
if [ "$type" = "database" ];then
database=$data
elif [ "$type" = "table" ];then
table=$data
fi
break
fi
printf "Please input the database name you would like to create:[postfix]"
done
done
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#input the data per user
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
for ((i=1;;i++));do
printf "Do you want to input the data per user:[yes,no]"
while read yes_no;do
if [ "$yes_no" != "yes" ];then break 2;fi
echo "Please input the data of NO.$i user:"
for col in username password uid gid maildir domain active;do
printf "$col of NO.$i :" && read ${col}[${i}]
done
break
done
done
#output the data you input
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
echo ""
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echo "Please make sure the data you input:"
echo "Database: $database"
echo "Table : $table"
echo ""
echo "Show the recodes you input:"
echo "username password uid gid maildir domain active"
for ((n=1;n<i;n++));do
echo "${username[$n]} ${password[$n]} ${uid[$n]} ${gid[$n]} ${maildir[$n]} ${domain[$n]} ${active[$n]}"
done
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#execute the sql to input data to mysql
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
echo ""
echo "Executing the SQL to input data to mysql......"
printf "Creating database $database...... " &&
mysql -u root -h www.linuxidc.com --password=RedHat -e "create database if not exists ${database}" &&
echo -e " 33[32mOK 33[m"
printf "Creating table $table...... " &&
mysql -u root -h www.linuxidc.com --password=redhat $database -e "create table if not exists ${table}$TABLE" &&
echo -e " 33[32mOK 33[m"
#insert recode to mysql
for ((n=1;n<i;n++));do
printf "Insert NO.$n recode...... " &&
mysql -u root -h www.linuxidc.com --password=redhat $database -e "insert into $table values ("${username[$n]}",encrypt("${password[$n]}"),"${uid[$n]}","${gid[$n]}","${maildir[$n]}","${domain[$n]}","${active[$n]}")" &&
echo -e " 33[32mOK 33[m"
done
#show all the recode
echo ""
echo "Show all the recods in the mysql:"
mysql -u root -h www.linuxidc.com --password=redhat $database -e "select * from $table"如何用PHP向MySQL中添加汉字数据Linux启动过程中跳过MySQL Server启动的方法相关资讯 MySQL教程
- 30分钟带你快速入门MySQL教程 (02月03日)
- MySQL教程:关于I/O内存方面的一些 (01月24日)
- CentOS上开启MySQL远程访问权限 (01/29/2013 10:58:40)
| - MySQL教程:关于checkpoint机制 (01月24日)
- MySQL::Sandbox (04/14/2013 08:03:38)
- 生产环境MySQL 5.5.x单机多实例配 (11/02/2012 21:02:36)
|
本文评论 查看全部评论 (0)