MySQL source installation script share _linux Shell

Source: Internet
Author: User

Copy Code code as follows:

#!/bin/bash
Path=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
Export PATH
Clear
Sysname= ""
Sysbit= ""
Cpunum= ""
Ramtotal= ""
Ramswap= ""
Filemax= ""
mysqlversion= "percona-server-5.6.15-rel63.0"
Mysqlline= "Http://www.percona.com/downloads/Percona-Server-5.6/LATEST/source"
Mysqlpath= "/usr/local/mysql"
Mysqldatapath= "$MysqlPath/data"
Mysqllogpath= "/var/log/mysql"
Mysqlconfigpath= "$MysqlPath/conf"
Mysqlpass= "Test123"
System_check () {
[[$ (id-u)!= ' 0 ']] && echo ' [Error] Please use the root to install PUPPET. ' && exit;
Egrep-i "CentOS"/etc/issue && sysname= ' CentOS ';
Egrep-i "Ubuntu"/etc/issue && sysname= ' Ubuntu ';
[[' $SysName ' = = ']] && echo ' [Error] Your system is isn't supported this script ' && exit;
sysbit= ' && [' getconf word_bit ' = ' = '] && [' getconf long_bit ' = ']] && sysbit= ' 64 ';
cpunum= ' Cat/proc/cpuinfo |grep ' processor ' |wc-l ';
Ramtotal= ' Free-m | grep ' Mem ' | awk ' {print $} ';
Ramswap= ' Free-m | grep ' Swap ' | awk ' {print $} ';
filemax= ' Cat/proc/sys/fs/file-max '
}
Install_base_packages ()
{
System_check
If ["$SysName" = = ' CentOS ']; Then
Echo ' [Yum-fastestmirror installing] ************************************************** >> ';
Yum-y install yum-fastestmirror;
Cp/etc/yum.conf/etc/yum.conf.lnmp
Sed-i ' S:exclude=.*:exclude=:g '/etc/yum.conf
For packages in gcc gcc-c++ openssl-devel ncurses-devel wget crontabs iptables bison cmake automake make Readline-devel lo Grotate OpenSSL; Todo
echo "[${packages} Installing] ************************************************** >>";
Yum-y install $packages;
Done
Mv-f/etc/yum.conf.lnmp/etc/yum.conf;
Else
Apt-get remove-y mysql-client mysql-server Mysql-common;
Apt-get Update;
For packages in GCC g++ cmake make NTP logrotate cron Bison libncurses5-dev libncurses5 libssl-dev OpenSSL; curl; Todo
echo "[${packages} Installing] ************************************************** >>";
Apt-get install-y $packages--force-yes;apt-get-fy install;apt-get-y autoremove;
Done
Fi
}
Install_mysql () {
Install_base_packages
cd/tmp/
echo "[${mysqlversion} Installing] ************************************************** >>";
[!-F ${mysqlversion}.tar.gz] && wget-c ${mysqlline}/${mysqlversion}.tar.gz
tar-zxf/tmp/$MysqlVersion. tar.gz;
cd/tmp/$MysqlVersion;
Groupadd MySQL;
Useradd-s/sbin/nologin-g MySQL MySQL;
cmake-dcmake_install_prefix= $MysqlPath-ddefault_charset=utf8-ddefault_collation=utf8_general_ci-dwith_extra_ Charsets=complex-dwith_readline=on-denabled_local_infile=on-dwith_innodb_memcached=on-dwith_unit_tests=off;
Make-j $Cpunum;
make install;
For path in $MysqlLogPath $MysqlPath $MysqlConfigPath/conf.d $MysqlDataPath;d o
[!-D $path] && mkdir-p $path
chmod 740 $path;
Chown-r Mysql:mysql $path;
Done
# EOF **********************************
Cat > $MysqlConfigPath/my.cnf<<eof;
[Mysqld]
user = MySQL
Server-id = 1
Pid-file =/var/run/mysqld.pid
Socket =/var/run/mysqld.sock
Port = 3306
Basedir = $MysqlPath
DataDir = $MysqlDataPath
Bind-address = 0.0.0.0
Skip-name-resolve
Skip-external-locking
thread_concurrency = ' expr $CpuNum \* 2 '
max_connections = ' expr $FileMax \* $CpuNum \* 2/$RamTotal '
Max_connect_errors = 30
Table_open_cache = ' expr $RamTotal + $RamSwap '
Max_allowed_packet = ' expr $RamTotal \* 2/1000 ' M
Binlog_cache_size = 4M
Max_heap_table_size = ' expr $RamTotal/100 ' M
Sort_buffer_size = ' expr $RamTotal \* 2/1000 ' M
Join_buffer_size = ' expr $RamTotal \* 2/1000 ' M
Query_cache_size = ' expr $RamTotal/100 ' M
Thread_cache_size = 30
thread_concurrency = ' expr $CpuNum \* 4 '
connect_timeout = 1200
wait_timeout = 1200
General_log = 1
General_log_file = $MysqlLogPath/mysql.log
Log_error = $MysqlLogPath/mysql-err.log
Slow_query_log = 1
Slow_query_log_file = $MysqlLogPath/mysql-slow.log
Long_query_time = 3
Log_bin = $MysqlLogPath/mysql-bin
Log_bin_index = $MysqlLogPath/mysql-bin.index
Expire_logs_days = 7
Max_binlog_size = ' Expr $ (df-m $MysqlLogPath |awk ' nr==2{printf "%s\n", $} ')/10000 ' m
Default_storage_engine = InnoDB
Innodb_buffer_pool_size = ' expr $RamTotal/100 ' M
Innodb_log_buffer_size = 8M
innodb_file_per_table = 1
Innodb_open_files = ' expr $FileMax \* $CpuNum/$RamTotal '
innodb_io_capacity = ' expr $FileMax \* $CpuNum/$RamTotal '
Innodb_flush_method = O_direct

!includedir $ $MysqlConfigPath/CONF.D
[Mysqld_safe]
Open_files_limit = ' expr $FileMax/$CpuNum/100 '
[Isamchk]
Key_buffer = 16M
[Mysqldump]
Quick
Quote-names
Max_allowed_packet = 16M
Eof
# **************************************
$MysqlPath/scripts/mysql_install_db--user=mysql--defaults-file= $MysqlConfigPath/my.cnf--basedir= $MysqlPath- Datadir= $MysqlDataPath;
# EOF **********************************
Cat >/etc/ld.so.conf.d/mysql.conf<<eof
/usr/local/mysql/lib/mysql
/usr/local/lib
Eof
# **************************************
Ldconfig;
If ["$SysBit" = = ' 64 ']; Then
Ln-s $MysqlPath/lib/mysql/usr/lib64/mysql;
Else
Ln-s $MysqlPath/lib/mysql/usr/lib/mysql;
Fi
CP $MysqlPath/support-files/mysql.server/etc/init.d/mysqld;
chmod 775/etc/init.d/mysqld;
/etc/init.d/mysqld start;
Ln-s $MysqlPath/bin/mysql/usr/bin/mysql;
Ln-s $MysqlPath/bin/mysqladmin/usr/bin/mysqladmin;
$MysqlPath/bin/mysqladmin password $MysqlPass;
RM-RF $MysqlDataPath/test;
# EOF **********************************
Mysql-hlocalhost-uroot-p$mysqlpass <<eof
Use MySQL;
DELETE from user WHERE user= ';
UPDATE user Set Password=password (' $MysqlPass ') WHERE user= ' root ';
DELETE from the user WHERE not (user= ' root ');
DROP USER ' @ '%;
FLUSH privileges;
Eof
# **************************************
echo "[OK] ${mysqlversion} install completed.";
}
Install_mysql

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.