cat conf_mysql.sh
#!/bin/sh
function config_mysql_testDB()
{
echo -e "\nconfig mysql testDB..."
local dbname="testDB"
local username="testDB"
local password="rootmp"
local tmpconf=tmp_sql_init.sql
create database if not exists $dbname default character set utf8 COLLATE utf8_general_ci;
create user $username identified by '$password';
grant all privileges on *.* to $username;
grant all privileges on *.* to $username@localhost identified by '$password';
flush privileges;
EOF
cat <<EOF >testDB_tmp_sql_init_2.sql
create database if not exists $dbname default character set utf8 COLLATE utf8_general_ci;
EOF
local tmpUser="root_db_name"
local tmpPwd="root_db_name"
mysql -u$tmpUser -p$tmpPwd <testDB_tmp_sql_init_2.sql
mysql -u$tmpUser -p$tmpPwd $dbname <testDB.sql
rm -rf testDB_tmp_sql_init_2.sql
rm -rf $tmpconf
}
config_mysql_testDB
#!/bin/sh
function config_mysql_testDB()
{
echo -e "\nconfig mysql testDB..."
local dbname="testDB"
local username="testDB"
local password="rootmp"
local tmpconf=tmp_sql_init.sql
#创建临时文件,文件中包括操作mysql的语句
create database if not exists $dbname default character set utf8 COLLATE utf8_general_ci;
create user $username identified by '$password';
grant all privileges on *.* to $username;
grant all privileges on *.* to $username@localhost identified by '$password';
flush privileges;
EOF
cat <<EOF >testDB_tmp_sql_init_2.sql
create database if not exists $dbname default character set utf8 COLLATE utf8_general_ci;
EOF
local tmpUser="root_db_name"
local tmpPwd="root_db_name"
mysql -u$tmpUser -p$tmpPwd <testDB_tmp_sql_init_2.sql
mysql -u$tmpUser -p$tmpPwd $dbname <testDB.sql
rm -rf testDB_tmp_sql_init_2.sql
rm -rf $tmpconf
}
config_mysql_testDB