实战-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/下面. 安装编译 ...
随机推荐
- VPS搭建离线下载服务器——后网盘时代
动机 由于学习的需要,在国外某服务器厂商购买了vps服务(至于是哪个厂商就不说啦).但是呢,就算用作梯子,一个月1T的流量总是用不完.最经觉得自己营养充足,想找点电影看看. 无奈现在百度网盘的速度真的 ...
- T9
T9 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission ...
- Codeforces Round #380 (Div. 2)D. Sea Battle
D. Sea Battle time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- c++学习笔记---05--- C++输出输入小结
C++输出输入小结 题目: 这个程序将向用户提出一个"Y/N"问题,然后把用户输入的值赋值给answer变量. 要求: 针对用户输入'Y'或'y'和'N'或'n'进行过滤: 发掘程 ...
- 单元测试框架 unittest 的运行方法if __name__ == '__main__': unittest.main()
1. if __name__ == '__main__': unittest.main()2. 测试用例实例根据测试的特点分组在一起. unittest为此提供了一个机制:测试套件由unittest' ...
- Python爬虫入门:Cookie的使用
大家好哈,上一节我们研究了一下爬虫的异常处理问题,那么接下来我们一起来看一下Cookie的使用. 为什么要使用Cookie呢? Cookie,指某些网站为了辨别用户身份.进行session跟踪而储存在 ...
- 学习C++ -> 构造函数与析构函数
学习C++ -> 构造函数与析构函数 一.构造函数的介绍 1. 构造函数的作用 构造函数主要用来在创建对象时完成对对象属性的一些初始化等操作, 当创建对象时, 对象会自动调用 ...
- C#中结构体定义并转换字节数组
最近的项目在做socket通信报文解析的时候,用到了结构体与字节数组的转换:由于客户端采用C++开发,服务端采用C#开发,所以双方必须保证各自定义结构体成员类型和长度一致才能保证报文解析的正确性,这一 ...
- Python 解LeetCode:654. Maximum Binary Tree
用一个整型数组构建一个二叉树,根结点是数组中的最大值,左右子树分别是根结点的值在数组中左右两边的部分. 分析,这是二叉树中比较容易想到的问题了,直接使用递归就行了,代码如下: class Soluti ...
- 通过PING命令中的TTL来判断对方操作系统
---恢复内容开始--- 通过PING命令中的TTL来判断对方操作系统简单来说,TTL全程Time to Live,意思就是生存周期.首先要说明ping命令是使用的网络层协议ICMP,所以TTL指的是 ...