#linux mysql自动安装程序
#运行例子:sh install-mysql.sh /usr/local
#定义本程序的当前目录
base_path=$(pwd)
ntpdate time.windows
#处理外部参数
mysql_install_path=$1
if [ ! $mysql_install_path ] ; then
echo 'error command!!! you must input mysql '
echo 'for example: sh install-mysql.sh /usr/local'
exit
fi
#建立临时安装目录
echo 'preparing '
install_path='/install'
if [ ! -d $install_path ]; then
mkdir -m 777 $install_path
fi
yum -y install gcc libc6-dev gcc-c++ make rsync
#安装cmake
if [ ! -d $mysql_install_path/cmake ]; then
echo 'installing cmake 2.'
if [ ! -f $base_path/cmake-2.8. ]; then
echo 'cmake-2.8. is not exists, system will going to '
wget -O $base_path/cmake-2.8. /files/v2.8/cmake-2.8. || exit
echo 'download cmake-2.8.'
fi
tar zxvf $base_path/cmake-2.8. -C $install_path || exit
cd $install_path/cmake-2.8.11
./bootstrap --prefix=$mysql_install_path/cmake && make && make install || exit
cp $mysql_install_path/cmake/bin/* /usr/bin/
fi
#安装ncurses
yum -y install ncurses-devel perl || apt-get -y install libncurses5-dev || exit
#添加mysql用户
user=$(id -nu mysql)
if [ ! $user ]; then
user='mysql'
group='mysql'
/usr/sbin/groupadd -f $group
/usr/sbin/useradd -g $group $user
fi
#建立数据目录
mysql_data_path=$mysql_install_path/mysql/data
mkdir -p $mysql_data_path
#赋予数据存放目录权限
sql -R $mysql_data_path || exit
#安装mysql
echo ''
mysql='mysql-5.6.12'
if [ ! -d $install_path/$mysql ]; then
if [ ! -f $base_path/$ ]; then
echo $mysql'. is not exists, system will going to '
wget -O $base_path/$ sql/Downloads/MySQL-5.6/$ || exit
echo 'download '$mysql' '
fi
tar zxvf $base_path/$ -C $install_path || exit
fi
cd $install_path/$mysql
#删除编译缓存
rm -rf $install_path/$
cmake . -DCMAKE_INSTALL_PREFIX=$mysql_install_path/mysql -DMYSQL_UNIX_ADDR=$mysql_data_path/mysql.sock -DSYSCONFDIR=/etc -DDEFAULT
_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk,gb2312 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=$mysql_data_path -DMYSQL_USER=mysql || exit
make || exit
make install || exit
#复制配置文件
echo "[client]
port = 3306
socket = "$mysql_install_path"/mysql/data/mysql.sock
[mysqld]
port = 3306
socket = "$mysql_install_path"/mysql/data/mysql.sock
#skip-grant-tables
skip-external-locking
key_buffer_size = 100M
max_allowed_packet = 2M
table_open_cache = 64
sort_buffer_size = 1M
net_buffer_length = 8K
read_buffer_size = 4M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 1M
thread_concurrency = "$(cat /proc/cpuinfo | grep name | cut -f3 -d: | uniq -c | cut -b 7)"
max_connections = 10000
join_buffer_size = 2M
thread_cache_size = 1024
linux安装数据库server-id = 1
innodb_buffer_pool_size = 1M
innodb_log_file_size = 0M
innodb_log_buffer_size = 0M
innodb_flush_log_at_trx_commit = 0
innodb_lock_wait_timeout = 50
key_buffer_size = 2M
sort_buffer_size = 2M
sql-mode=\"NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION\"
long_query_time = 2
#log-slow-queries = "$mysql_install_path"/mysql/data/slowquery.log
#log-slow-admin-statements
#log-queries-not-using-indexes
[mysqldump]
quick
max_allowed_packet = 2M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 2M
sort_buffer_size = 4M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout" > /etc/myf || exit
cp $mysql_install_path/mysql/support-files/mysql.server /etc/init.d/mysqld || exit
chmod 755 /etc/init.d/mysqld
#初始化数据库
$mysql_install_path/mysql/scripts/mysql_install_db --user=mysql --basedir=$mysql_install_path/mysql --datadir=$mysql_data_path
#启动mysql服务
/etc/init.d/mysqld start
cp $mysql_install_path/mysql/bin/* /usr/bin/
#修改root密码
mysqladmin -u root password root
#开机自启动
echo '' >> /etc/rc.d/rc.local
echo 'service mysqld start' >> /etc/rc.d/rc.local
source /etc/rc.d/rc.local
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论