#!/bin/bash
for port in 3306 3307 3308;
do
rundir=/data/mysql/$port
filedir=/tmp
echo “start mysql server on port $port…”
/usr/local/mysql/bin/mysqld_safe –defaults-file=$rundir/my.cnf –port=$port –user=mysql –datadir=$rundir/data/ –pid-file=$filedir/mysql.”$port”.pid –socket=$filedir/mysql.”$port”.sock &
sleep 5
chmod 0777 $filedir/mysql.”$port”.sock
done
呵呵,一看就明白了,直接复制下来就可以使用了,当然要你的rundir和filedir的正确
为了方便补上一个连接mysql的shell脚本
#!/bin/bash
port=$1
user=$2
echo “connect mysql server localhost $port by $user through /tmp/mysql.$port.sock”
mysql -hlocalhost -P$port -u$user -p -S/tmp/mysql.$port.sock
当然了,这个脚本就需要根据自己的需求不同更改喽,要不就和直接用mysql命令没啥不一样了