此脚本只是为了自己方便而写的,可能有的地方写得不是很到位。还望各位朋友们多多指点。
- #!/bin/bash
-
echo 'n
- e
- n
-
+5G
-
t
-
5
-
8e
-
w'| fdisk /dev/sda &> /dev/null
-
partprobe /dev/sda
-
[ -d /mydata ] || mkdir /mydata
-
pvcreate /dev/sda5
-
vgcreate myvg /dev/sda5
-
lvcreate -L 2G -n mydata myvg
-
mke2fs -j /dev/myvg/mydata
-
mount /dev/myvg/mydata /mydata
-
[ -d /mydata/data ] || mkdir /mydata/data
-
id mysql &> /dev/null
-
I=$?
-
if [ $I -ne 0 ]; then
-
groupadd -g 3306 mysql
-
useradd -u 3306 -g mysql -M -s /sbin/nologin mysql
-
fi
-
chown -R mysql:mysql /mydata
-
cd /usr/local
-
tar xf mysql-5.1.45-linux-i686-glibc23.tar.gz
-
ln -sv mysql-5.1.45-linux-i686-glibc23 ./mysql
-
cd mysql
-
chown -R mysql:mysql ./
-
scripts/mysql_install_db --user=mysql --datadir=/mydata/data
-
chown -R root ./
-
scripts/mysql_install_db --user=mysql --datadir=/mydata/data
-
chown -R root ./
-
[ -f /etc/init.d/mysqld ] || cp support-files/mysql.server /etc/init.d/mysqld
-
chkconfig --add mysqld
-
chkconfig mysqld on
-
if [ -f /etc/my.cnf ];then
-
rm -rf /etc/my.cnf
-
fi
-
cp support-files/my-medium.cnf /etc/my.cnf
-
sed -i '/\[mysqld\]/adatadir = /mydata/data' /etc/my.cnf
-
cat > /etc/ld.so.conf.d/mysql.conf << EOF
-
/usr/local/mysql/lib
-
EOF
-
ldconfig
-
ln -sv /usr/local/mysql/include /usr/include/mysql
- service mysqld start