#! /bin/sh ############################### # 2013-11-19 # # author jackluo # # net.webjoy@gmail.com # ############################### serverid=$1 #服务器的id db_name=$2 #数据库名 db_host=$3 #mysql 的主机地址 databases_file_path=/home/wwwroot/cy/application/config/database.php db_user=root #数据库帐号 db_password=admin #数据库密码 db_host=localhost #数据库ip db_template_path=/home/jackluo/platform.sql #要导入的模板数据库 if [ -z "${serverid}" ] || [ -z "${db_name}" ] || [ -z "${db_host}" ];then echo "参数不够 共3个参数第一个是服务器的id 第二个是数据名, 第三个是mysql的主机地址" exit fi echo "/***************appgame ${serverid}************/ $db['${serverid}']['gamedb']['hostname'] = 'localhost'; $db['${serverid}']['gamedb']['username'] = 'jack'; $db['${serverid}']['gamedb']['password'] = '****'; $db['${serverid}']['gamedb']['database'] = '${db_name}'; $db['${serverid}']['gamedb']['dbdriver'] = 'mysql'; $db['${serverid}']['gamedb']['dbprefix'] = ''; $db['${serverid}']['gamedb']['pconnect'] = FALSE; $db['${serverid}']['gamedb']['db_debug'] = TRUE; $db['${serverid}']['gamedb']['cache_on'] = FALSE; $db['${serverid}']['gamedb']['cachedir'] = ''; $db['${serverid}']['gamedb']['char_set'] = 'utf8'; $db['${serverid}']['gamedb']['dbcollat'] = 'utf8_general_ci'; $db['${serverid}']['gamedb']['swap_pre'] = ''; $db['${serverid}']['gamedb']['autoinit'] = TRUE; $db['${serverid}']['gamedb']['stricton'] = FALSE; $db['${serverid}']['remotedb']['hostname'] = '${db_host}'; $db['${serverid}']['remotedb']['username'] = 'luo'; $db['${serverid}']['remotedb']['password'] = '***'; $db['${serverid}']['remotedb']['database'] = '${db_name}'; $db['${serverid}']['remotedb']['dbdriver'] = 'mysql'; $db['${serverid}']['remotedb']['dbprefix'] = ''; $db['${serverid}']['remotedb']['pconnect'] = FALSE; $db['${serverid}']['remotedb']['db_debug'] = TRUE; $db['${serverid}']['remotedb']['cache_on'] = FALSE; $db['${serverid}']['remotedb']['cachedir'] = ''; $db['${serverid}']['remotedb']['char_set'] = 'utf8'; $db['${serverid}']['remotedb']['dbcollat'] = 'utf8_general_ci'; $db['${serverid}']['remotedb']['swap_pre'] = ''; $db['${serverid}']['remotedb']['autoinit'] = TRUE; $db['${serverid}']['remotedb']['stricton'] = FALSE; /***************appgame ${serverid}********************/ " >> ${databases_file_path} #写入数据库 sed -i 's/\r//' ${databases_file_path} #替换^M 这样的东西 #创建数据库 mysql -u${db_user} -p${db_password} -h${db_host} <<EOF set names utf8; create database ${db_name}; use ${db_name}; source ${db_template_path}; EOF