标签:
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 = 3306 socket = /tmp/mysql.sock [mysqld] #base port = 3306 user = mysql socket = /tmp/mysql.sock pid-file = /tmp/mysql.pid basedir = /usr/local/mysql datadir = /data/mysqldb tmpdir = /opt/mysqltmp open_files_limit = 10240 explicit_defaults_for_timestamp sql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES federated server_id = 706 #replicate-do-db = posp #replicate-ignore-db = mysql #log-slave-updates = 1 event_scheduler=1 max_connections = 2000 max_connect_errors = 10000 interactive_timeout = 600 wait_timeout = 600 skip-name-resolve sync_binlog=0 log_bin_trust_function_creators = 1 character-set-server = utf8 default_storage_engine = InnoDB #log log-bin = /data/mysqldb/binlog/mysql-bin binlog_cache_size = 32m max_binlog_cache_size = 10g binlog_stmt_cache_size = 32m table_open_cache = 2048 max_binlog_size = 1024m binlog_format = mixed log_output = FILE log-error = /data/mysqldb/log/mysql-error.log slow_query_log = 1 slow_query_log_file = /data/mysqldb/log/mysql-slow_query.log general_log = 0 general_log_file = /data/mysqldb/log/mysql-general-query.log expire-logs-days = 30 relay-log = /data/mysqldb/binlog/relay-bin relay-log-index= /data/mysqldb/binlog/relay-bin.index #buffer sort_buffer_size = 2m read_buffer_size = 2m read_rnd_buffer_size = 2m join_buffer_size = 2m net_buffer_length = 16k max_allowed_packet = 512m bulk_insert_buffer_size = 32m max_heap_table_size = 512m tmp_table_size = 512m thread_cache_size = 100 query_cache_size = 256m query_cache_limit = 10m query_cache_min_res_unit = 4k key_buffer_size = 16m myisam_sort_buffer_size = 64m myisam_max_sort_file_size = 10g myisam_repair_threads = 1 #innodb innodb_file_per_table = 1 innodb_data_file_path = ibdata1:2048M:autoextend innodb_log_file_size = 128m innodb_log_files_in_group = 3 innodb_buffer_pool_size = 1g innodb_buffer_pool_instances = -1 innodb_max_dirty_pages_pct = 70 #innodb_thread_concurrency = 8 innodb_flush_method = O_DIRECT innodb_log_buffer_size = 16m innodb_flush_log_at_trx_commit = 2 [mysql] no-auto-rehash prompt = (\u@\h) [\d]\_ default-character-set = utf8
标签:
原文地址:http://www.cnblogs.com/losbyday/p/5836116.html