首页 > 代码库 > Mysql安装脚本

Mysql安装脚本

Mysql

#/bin/bash #--------变量#num=`expr $RANDOM % 5 + 1`now_lujing=`pwd`#-------------------------配置用户文件函数function user_file_config(){#-----------------------------------添加组,用户    groupadd mysql    &>/dev/null    useradd mysql -g mysql -s /sbin/nologin    #-----------------------------------建立必要文件#Mysql的安装目录    mkdir -p /usr/local/mysql #Mysql数据目录    mkdir -p /data/mysqldb  #创建BINLOG日志目录    mkdir -p /data/mysqldb/binlog #创建MYSQL 日常LOG目录    mkdir -p /data/mysqldb/log   #数据库临时目录    mkdir /opt/mysqltmp        #解压编译mysql源码    make_mysql;#给Mysql安装目录进行授权    chown  mysql:mysql /usr/local/mysql -R#---------------------------------更改权限    chown mysql:mysql /opt/mysqltmp#-给Mysql数据存储目录进行授权    chown  mysql:mysql /data/mysqldb -R#-给Mysl日志目录进行授权    chown mysql:mysql /data/mysqldb/binlog/    chown mysql:mysql /data/mysqldb/log/#开始初始化#复制配置文件    echo y|cp $now_lujing/my.cnf /etc/my.cnf#指定使用者,user,运行目录/usr/local/mysql 制定数据存放文件 /data/mysqldb     /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysqldb#拷贝命令到init.d文件里面去        cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld    chmod 755 /etc/init.d/mysqld#启动服务和设置环境变量#:vim /etc/profile#文件的最后面。echo -e "MYSQL=/usr/local/mysql/bin \nPATH=\$PATH:\$MYSQL\nexport PATH" >>/etc/profile#生效    source /etc/profile }function make_mysql(){    if [ ! -d mysql-5.6.31 ]    then        tar -xvf mysql-5.6.31.tar.gz    fi    cd mysql-5.6.31    cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql     -DMYSQL_UNIX_ADDR=/tmp/mysql.sock     -DSYSCONFDIR=/etc     -DDEFAULT_CHARSET=gbk     -DDEFAULT_COLLATION=gbk_chinese_ci     -DWITH_INNOBASE_STORAGE_ENGINE=1     -DWITH_ARCHIVE_STORAGE_ENGINE=1     -DWITH_BLACKHOLE_STORAGE_ENGINE=1     -DWITH_FEDERATED_STORAGE_ENGINE=1     -DWITH_PARTITION_STORAGE_ENGINE=1     -DMYSQL_DATADIR=/data/mysqldb     -DMYSQL_TCP_PORT=3306    make && make install }#-------检查yum源有没有配置成功function check_yum(){    yum clean all &>/dev/null    yum repolist &> /tmp/repolist.los    rpm_num=`cat /tmp/repolist.los|grep repolist|awk {print $2}`#    echo $rpm_num    if [ "$rpm_num" == "0" ]    then        echo error:`date +%F-%R`yum源没有配置好  >>mysql_log    else            echo error:`date +%F-%R`yum源配置好了  >>mysql_log            yum install gcc gcc-c++ ncurses-devel perl camke bison  cmake -y         [ $? -eq 0 ] && echo -e succed:"`date +%F-%R`\tmysql所需要的依赖包已经成功安装 >>mysql_log"    || echo -e filed:"`date +%F-%R`\tmysql所需要的依赖包没有安装成功 >>mysql_log"    fi}function main(){    check_yum;    user_file_config#启动服务    /etc/init.d/mysqld start     }main;

 



 

my.cnf

[client]port = 3306socket = /tmp/mysql.sock[mysqld]#baseport = 3306user = mysqlsocket = /tmp/mysql.sockpid-file = /tmp/mysql.pidbasedir = /usr/local/mysqldatadir = /data/mysqldbtmpdir = /opt/mysqltmpopen_files_limit = 10240explicit_defaults_for_timestampsql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLESfederated server_id = 706#replicate-do-db = posp#replicate-ignore-db = mysql#log-slave-updates = 1event_scheduler=1 max_connections = 2000max_connect_errors = 10000interactive_timeout = 600wait_timeout = 600skip-name-resolvesync_binlog=0log_bin_trust_function_creators = 1character-set-server = utf8default_storage_engine = InnoDB#loglog-bin = /data/mysqldb/binlog/mysql-binbinlog_cache_size = 32mmax_binlog_cache_size = 10gbinlog_stmt_cache_size = 32mtable_open_cache = 2048max_binlog_size = 1024mbinlog_format = mixedlog_output = FILElog-error = /data/mysqldb/log/mysql-error.logslow_query_log = 1slow_query_log_file = /data/mysqldb/log/mysql-slow_query.loggeneral_log = 0general_log_file = /data/mysqldb/log/mysql-general-query.logexpire-logs-days = 30relay-log = /data/mysqldb/binlog/relay-binrelay-log-index= /data/mysqldb/binlog/relay-bin.index#buffersort_buffer_size = 2m read_buffer_size = 2mread_rnd_buffer_size = 2mjoin_buffer_size = 2mnet_buffer_length = 16kmax_allowed_packet = 512mbulk_insert_buffer_size = 32mmax_heap_table_size = 512mtmp_table_size = 512mthread_cache_size = 100query_cache_size = 256mquery_cache_limit = 10mquery_cache_min_res_unit = 4kkey_buffer_size = 16mmyisam_sort_buffer_size = 64mmyisam_max_sort_file_size = 10gmyisam_repair_threads = 1#innodbinnodb_file_per_table = 1innodb_data_file_path = ibdata1:2048M:autoextendinnodb_log_file_size = 128minnodb_log_files_in_group = 3innodb_buffer_pool_size = 1ginnodb_buffer_pool_instances = -1innodb_max_dirty_pages_pct = 70#innodb_thread_concurrency = 8innodb_flush_method = O_DIRECTinnodb_log_buffer_size = 16minnodb_flush_log_at_trx_commit = 2[mysql]no-auto-rehashprompt = (\u@\h) [\d]\_default-character-set = utf8

 

Mysql安装脚本