#!/bin/bash
mysql_install_dir=
/usr/local/mysql
mysql_data_dir=
/data/mysql
mysql_6_version=5.6.26
dbrootpwd=root
Mem=`
free
-m |
awk
'/Mem:/{print $2}'
`
Swap=`
free
-m |
awk
'/Swap:/{print $2}'
`
Install_MySQL-5-6()
{
yum -y
install
make
gcc
-c++ cmake bison-devel ncurses-devel
wget http:
//mirrors
.sohu.com
/mysql/MySQL-5
.6
/mysql-
${mysql_6_version}.
tar
.gz
id
-u mysql >
/dev/null
2>&1
[ $? -
ne
0 ] &&
useradd
-M -s
/sbin/nologin
mysql
mkdir
-p $mysql_data_dir;
chown
mysql.mysql -R $mysql_data_dir
tar
zxf mysql-${mysql_6_version}.
tar
.gz
cd
mysql-$mysql_6_version
make
clean
[ ! -d
"$mysql_install_dir"
] &&
mkdir
-p $mysql_install_dir
cmake . -DCMAKE_INSTALL_PREFIX=$mysql_install_dir \
-DMYSQL_DATADIR=$mysql_data_dir \
-DSYSCONFDIR=
/etc
\
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DENABLE_DTRACE=0 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DWITH_EMBEDDED_SERVER=1 \
make
-j `
grep
processor
/proc/cpuinfo
|
wc
-l`
make
install
if
[ -d
"$mysql_install_dir/support-files"
];
then
echo
"${CSUCCESS}MySQL install successfully! ${CEND}"
cd
..
rm
-rf mysql-$mysql_6_version
else
rm
-rf $mysql_install_dir
echo
"${CFAILURE}MySQL install failed, Please contact the author! ${CEND}"
kill
-9 $$
fi
/bin/cp
$mysql_install_dir
/support-files/mysql
.server
/etc/init
.d
/mysqld
chmod
+x
/etc/init
.d
/mysqld
chkconfig mysqld on
cd
..
[ -d
"/etc/mysql"
] &&
/bin/mv
/etc/mysql
{,_bk}
$mysql_install_dir
/scripts/mysql_install_db
--user=mysql --basedir=$mysql_install_dir --datadir=$mysql_data_dir
chown
mysql.mysql -R $mysql_data_dir
service mysqld start
[ -z
"`grep ^'export PATH=' /etc/profile`"
] &&
echo
"export PATH=$mysql_install_dir/bin:\$PATH"
>>
/etc/profile
[ -n
"`grep ^'export PATH=' /etc/profile`"
-a -z
"`grep $mysql_install_dir /etc/profile`"
] &&
sed
-i
"s@^export PATH=\(.*\)@export PATH=$mysql_install_dir/bin:\1@"
/etc/profile
.
/etc/profile
$mysql_install_dir
/bin/mysql
-e
"grant all privileges on *.* to root@'127.0.0.1' identified by \"$dbrootpwd\" with grant option;"
$mysql_install_dir
/bin/mysql
-e
"grant all privileges on *.* to root@'localhost' identified by \"$dbrootpwd\" with grant option;"
$mysql_install_dir
/bin/mysql
-uroot -p$dbrootpwd -e
"delete from mysql.user where Password='';"
$mysql_install_dir
/bin/mysql
-uroot -p$dbrootpwd -e
"delete from mysql.db where User='';"
$mysql_install_dir
/bin/mysql
-uroot -p$dbrootpwd -e
"delete from mysql.proxies_priv where Host!='localhost';"
$mysql_install_dir
/bin/mysql
-uroot -p$dbrootpwd -e
"drop database test;"
$mysql_install_dir
/bin/mysql
-uroot -p$dbrootpwd -e
"reset master;"
rm
-rf
/etc/ld
.so.conf.d/{mysql,mariadb,percona}*.conf
echo
"$mysql_install_dir/lib"
> mysql.conf
/sbin/ldconfig
service mysqld stop
}
Install_MySQL-5-6
本文出自 “一只菜的不能再菜的小菜鸟” 博客,转载请与作者联系!