实战-Mysql5.6.36脚本编译安装及初始化
概述
本文为centos7.3自动化编译安装mysql5.3.6的脚本及后续初始化操作,话不多少,直接上脚本。
安装脚本install.py如下:
#coding=utf-8
#!/usr/bin/python
import os,commands
#定义变量
install_dir = '/data/mysql'
data_dir = '/data/mysql/data'
package_dir = '/data/mysql'
log_dir = '/data/mysql/logs'
current_dir = os.getcwd()
cmake = 'cmake -DCMAKE_INSTALL_PREFIX=%s -DMYSQL_UNIX_ADDR=%s/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_DATADIR=%s -DMYSQL_TCP_PORT=3306' % (install_dir, install_dir, data_dir)
#安装依赖包
os.system('yum install gcc gcc-c++ gcc-g77 autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* make cmake perl -y')
#安装函数
def install_mysql():
if os.system('groupadd mysql') == 0:
print 'group mysql add success!'
else:
exit('group mysql add failed!')
if os.system('useradd -r -g mysql -s /bin/false mysql') == 0:
print 'user mysql add success!'
else:
exit('user mysql add failed!')
if not os.path.exists(install_dir):
os.system('mkdir -p %s' % install_dir)
if not os.path.exists(data_dir):
os.system('mkdir -p %s' % data_dir)
if not os.path.exists(package_dir):
os.system('mkdir -p %s' % package_dir)
if not os.path.exists(log_dir):
os.system('mkdir -p %s' % log_dir)
if os.system('tar zxvf mysql-5.6.36.tar.gz') == 0:
print 'uncompress v success!'
else:
exit('uncompress mysql-5.6.36.tar.gz failed!')
os.chdir('mysql-5.6.36')
if os.system(cmake) == 0:
print '编译成功'
else:
exit('编译mysql失败')
if os.system('make && make install') == 0:
print '编译安装mysql成功'
else:
exit('编译安装mysql失败')
if os.system('chown -R mysql:mysql %s' % install_dir) == 0:
print '安装目录权限配置成功'
else:
exit()
os.system('chown -R mysql:mysql %s' % data_dir)
os.system('cd %s && touch mysql-error.log' % log_dir)
os.system('chown -R mysql:mysql %s' % log_dir)
os.chdir(install_dir)
if os.system('./scripts/mysql_install_db --user=mysql --datadir=%s' % data_dir) == 0:
print 'mysql初始化成功'
else:
exit('mysql初始化失败')
os.system('cp support-files/mysql.server /etc/init.d/mysqld')
os.system('mv /etc/my.cnf /etc/my.cnf.bak')
os.chdir(current_dir)
os.system('cp my.cnf /etc/my.cnf')
os.system('service mysqld start')
os.system('chkconfig mysqld on')
install_mysql()
if os.path.exists('/etc/profile'):
os.system('cp /etc/profile /etc/profile.bak')
if os.system('echo "PATH=%s/bin:%s/lib:$PATH" >> /etc/profile' % (install_dir, install_dir)) == 0:
print '修改/etc/profile成功'
else:
exit()
if os.system('echo "export PATH" >> /etc/profile') == 0:
print '修改/etc/profile文件成功'
else:
exit()
配置文件my.cnf
[mysqld]
basedir = /data/mysql
datadir = /data/mysql/data
tmpdir = /data/mysql
socket = /data/mysql/mysql.sock
skip-external-locking
skip-name-resolve
lower_case_table_names=1
auto_increment_offset = 1
auto_increment_increment = 2
#server-id
########## binlog ##########
log_bin = /data/mysql/logs/mysql-bin
binlog_format = row
binlog_cache_size = 2M
expire-logs-days = 7
########## error log ##########
log_error = /data/mysql/logs/mysql-error.log
########## slow log ##########
slow_query_log = 1
slow_query_log_file = /data/mysql/logs/mysql-slow.log
long_query_time = 5
########## per_thread_buffers ##########
max_connections = 1024
max_connect_errors = 1000
key_buffer_size = 64M
max_allowed_packet = 128M
table_open_cache = 6144
table_definition_cache = 4096
sort_buffer_size = 512K
read_buffer_size = 512K
join_buffer_size = 512K
tmp_table_size = 64M
max_heap_table_size = 64M
thread_cache_size = 64
thread_concurrency = 32
bulk_insert_buffer_size = 64M
########innodb########
innodb_buffer_pool_size = 45G
innodb_log_file_size = 500M
innodb_log_buffer_size = 64M
innodb_flush_log_at_trx_commit = 2
innodb_file_per_table = 1
innodb_file_io_threads = 4
innodb_flush_method = O_DIRECT
innodb_thread_concurrency = 0
innodb_additional_mem_pool_size = 16M
[mysqlhotcopy]
interactive-timeout
[mysqld_safe]
open_files_limit = 65535
使用方法:
1.操作系统需要配置yum源
2.操作系统版本:centos7.3
3.将install.py my.cnf 和mysql安装包放一个文件夹
mysql安装包下载地址:http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.36.tar.gz
初始化
-- 初始化数据
use mysql;
update user set password=PASSWORD("Abcd123") where user='root';
grant all privileges on *.* to weihu@"%" identified by "Abcd123";
delete from mysql.user where user = '';
FLUSH PRIVILEGES;
-- 创建demo数据库
CREATE DATABASE `demo` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
show databases;
实战-Mysql5.6.36脚本编译安装及初始化的更多相关文章
- 年终福利,PHP7+Apache2.4+MySQL5.6 源码编译安装,环境配置,搭建你自己的LAMP环境
PHP7 都出来了,你还在玩PHP5吗? MySQL5.6 早都出来了,你还在玩MySql5.2吗? Apache2.4 早都出来了,你还在玩Apache2.2吗? 笔者不才,愿意亲自搭建环境,供搭建 ...
- MySQL5.5多实例编译安装——多配置文件
一.什么是MySQL多实例?MySQL多实例简单的说就是在一台服务器上安装一套MySQL程序,通过不同的端口对外提供访问,多实例不仅节省物理主机成本,还有效提升了单台物理主机的CPU.磁盘I/O使用效 ...
- mysql5.6.36 源码安装过程
参考:http://www.linuxidc.com/Linux/2015-06/119354.htm cmake编译时,提示错误 CMake Error: The source directory ...
- mysql-5.5.20预编译安装
1.MYSQL数据库概念 1)MYSQL是一款关系型数据库系统,数据之间有互相联系,互相的关联和调用的. 2)MYSQL数据用于存储:WEB网站用户名和密码等 3)MYSQL存储数据库是通过二维表格形 ...
- 小D课堂 - 零基础入门SpringBoot2.X到实战_第9节 SpringBoot2.x整合Redis实战_38、源码编译安装Redis4.x
笔记 2.源码编译安装Redis4.x 简介:使用源码安装Redis4.x和配置外网访问 1.快速安装 https://redis.io/download#installation ...
- shell脚本编译安装LAMP环境
#filename lamp.sh#version Centos6.7;apache2.4.23;mariadb-5.5.40;php5.5.38#data 2016/09/28#mail 23853 ...
- 内网服务器离线编译安装mysql5.7并调优
目录 内网服务器离线编译安装mysql5.7并调优 前言 关于MySQL 一.MySQL安装篇 部署环境 前期准备工具 挂载系统ISO镜像,配置yum源 二.MySQL调优篇 1.对MySQL进行安全 ...
- MYSQL5.6源码包编译安装
linux下用cmake编译安装mysql-5.6.35cmake编译安装mysql的方法:#useradd -M mysql -s /sbin/nologin#yum install -y cmak ...
- centos7上编译安装mysql5.6
注意,在做实验室统一关闭防火墙做的,在生产环境需要做防火墙规则的,大家要注意,做的时候尽量都是模仿生产环境的,比如服务一般都在/data/soft下面,尽量避免在/usr/local/下面. 安装编译 ...
随机推荐
- Handler学习
刚开始学习Android的时候,知道异步线程无法更新UI,于是然后找了个东西把更新的动作抛给UI线程,这个东西就是Handler. 一开始就只会在主线程也就是UI线程new一个Handler,之后在各 ...
- Java企业微信开发_Exception_02_java.security.InvalidKeyException: Illegal key size
今天换了重新装了一个jdk,然后运行昨天还好好的企业微信工程,结果启动的时候就给我报了这么个错: java.security.InvalidKeyException: Illegal key size ...
- json格式转化成map
public static Map<String, Object> parseJSON2Map(String jsonStr) { Map<String, Object> ma ...
- angular指令中的preLink函数和postLink函数
指令模板选项有complie和link两个字段,两者之间存在如下关系: 当compile字段存在时,link字段将被忽略,compile函数的返回值将作为link字段. 当compile不存在,lin ...
- Ionic3 一些命令
ionic start --help E:\Projects\ionic>ionic start --help ionic start - Create a new project This c ...
- 伤不起的微信小程序
前段时间不是很忙,刚好公司需要开发一个微信小程序,于是我就入坑了(此坑还是有点深滴,请备好干粮). 我是一名iOS开发工程师,个人觉得入门开发小程序的话,需要基本的web前端知识,比如说:代码的书写格 ...
- #define is unsafe
#define is unsafe Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- 颜色框架Hue相关使用方法
Hue地址 cocoapods安装Hue pod "Hue" 导入框架 import Hue 将十六进制数字变成对应的颜色值 let color = UIColor.init(he ...
- vue初级学习--控制台创建vue项目
一.导语 困困的我,好想睡啊,但还是敲下这边有的没的的笔记吧 二.正文 1.输入 vue list 可查看此环境下,vue能创建的项目模板 没将webpack.vue-route啃精了的话,老实用we ...
- 搭建本地Tomcat
1.下载自己需要的版本我安装的Tomcat8(https://tomcat.apache.org/). 2.根据自己的电脑下载需要的系统版本.我的电脑是Windows64位的操作系统 3.选择一个目录 ...