首页 > 代码库 > mysql 管理脚本

mysql 管理脚本

1.环境文件

-bash-4.1$ more mysql_env.ini#!/bin/sh#set envMYSQL_USER=rootMYSQL_PASS=123456‘#check parameterif [ $# -ne 1 ]then        HOST_PORT=3306else        HOST_PORT=$1fi-bash-4.1$

2.创建启动脚本

-bash-4.1$ more mysql_db_startup.sh#!/bin/shsource /opt/mysql/scripts/mysql_env.iniecho "Startup MySQL Service:localhost_"${HOST_PORT}/opt/mysql/bin/mysqld_safe --defaults-file=/opt/mysql/my.cnf  &-bash-4.1$ 

3.创建关闭脚本

-bash-4.1$ more mysql_db_shutdown.sh#!/bin/shsource /opt/mysql/scripts/mysql_env.iniecho "Shutdown MySQL Service:localhost_"${HOST_PORT}/opt/mysql/bin/mysqladmin --defaults-file=/opt/mysql/my.cnf -u${MYSQL_USER} -p${MYSQL_PASS} -hlocalhost  shutdown-bash-4.1$

4.创建快速登陆脚本

-bash-4.1$ more mysqlplus.sh #!/bin/shsource /opt/mysql/scripts/mysql_env.iniecho "Login MySQL Service:localhost_"${HOST_PORT}/opt/mysql/bin/mysql --defaults-file=/opt/mysql/my.cnf -u${MYSQL_USER} -p${MYSQL_PASS} -h localhost-bash-4.1$ 

5.将上述脚本目录 加入PATH环境变量
   echo "export PATH=/opt/mysql/scripts/:\$PATH" >> ~/.bash_profile

 source ~/.bash_profile

 

mysql 管理脚本