首页 > 代码库 > mysql 5.6单机单实例源码编译安装配置

mysql 5.6单机单实例源码编译安装配置

--linux 基础配置  指定机器名为sql1

--查看centos内核
uname -a
cat /etc/issue


--修改机器名

1、 echo "192.168.33.190 sql1 localhost.localdomain localhost4 localhost4.localdomain4" >> /etc/hosts

2、 vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=sql1

--修改ip
vi /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE="eth0"
BOOTPROTO="static"
HWADDR="00:0C:29:39:E0:20"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"
UUID="78bfd5ef-0ba2-4fff-aba3-bf8d7839fcb9"
IPADDR="192.168.33.190"
GATEWAY="192.168.33.1"
DNS1=180.76.76.76


--关闭selinux
vi /etc/sysconfig/selinux
SELINUX=disabled

--关闭防火墙
service iptables stop
chkconfig iptables off


--配置本地yum源 卸载 umount /mnt/cdrom
mkdir /mnt/cdrom
mount /dev/cdrom /mnt/cdrom

 

cd /etc/yum.repos.d
其下所有文件,进行重命名;新建CentOS-Media.repo

vi CentOS-Media.repo
[c6-media]
name=CentOS-$releasever - Media
baseurl=file:///mnt/cdrom/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6


yum clean all --清理yum缓存

yum install php --安装php测试

如需要将yum源改为网络,还原/etc/yum.repos.d目录下的四个文件即可


--查看是否已安装
rpm -qa | grep mysql
mysql-libs-5.1.61-4.el6.x86_64


--卸载mysql
rpm -e mysql-libs --直接删除会失败
rpm --nodeps -e mysql-libs

--编译安装需要的包
yum -y install make
yum -y install gcc-c++
yum -y install cmake
yum -y install bison-devel
yum -y install ncurses-devel


--创建mysql用户和组
groupadd mysql
useradd -g mysql mysql

--设置用户的操作系统资源限制
vi /etc/security/limits.conf
mysql soft nproc 2047
mysql hard nproc 16384
mysql soft nofile 1024
mysql hard nofile 65536

 

--安装mysql  前期规划规划

mysql软件安装路径 -DCMAKE_INSTALL_PREFIX=/usr/local/mysql

数据文件 -DMYSQL_DATADIR=/data/sql1

my.cnf配置文件 -DSYSCONFDIR=/etc/mysql

字符集 -DDEFAULT_CHARSET=utf8mb4

排序规则 -DDEFAULT_COLLATION=utf8mb4_general_ci

开启load -DENABLED_LOCAL_INFILE=1

开启分区 -DWITH_PARTITION_STORAGE_ENGINE=1

开启Performance_Schema库 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1

mysql端口 -DMYSQL_TCP_PORT=3306


--源码解压
tar -xvf mysql-5.6.21.tar.gz

cd mysql-5.6.21

cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/sql1/data \
-DSYSCONFDIR=/etc/mysql \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci


make && make install --约10分钟左右


--设置环境变量 mysql命令目录 -DCMAKE_INSTALL_PREFIX/bin
su - mysql
vi /home/mysql/.bash_profile
export PATH=/usr/local/mysql/bin:$PATH

source ~/.bash_profile


--binlog路径/backup路径/临时文件路径 InnoDB不会创建目录,启动服务器之前事先创建
mkdir /etc/mysql
mkdir -p /data/sql1/data
mkdir /data/sql1/backup
mkdir /data/sql1/tmp
mkdir /data/sql1/binlog
mkdir /data/sql1/log

chown -R mysql:mysql /data
chown -R mysql:mysql /usr/local/mysql

chown -R mysql:mysql /etc/mysql

--配置启动参数
su - mysql
vi /etc/mysql/my.cnf
[client]
port = 3306
socket = /data/sql1/data/mysql.sock

[mysqld]
port = 3306
user = mysql
socket = /data/sql1/data/mysql.sock #client and server in same machine ,use localhost connect to server
pid-file = /data/sql1/data/mysql.pid #In multi-instance keep each instance do not startup twice.

basedir = /usr/local/mysql
datadir = /data/sql1/data
tmpdir = /data/sql1/tmp

open_files_limit = 10240

#buffer
max_heap_table_size = 256M
innodb_buffer_pool_size = 128M
sort_buffer_size = 2M
join_buffer_size = 4M
read_buffer_size =2M
read_rnd_buffer_size =2M
max_connections = 5000


#log
log-bin = /data/sql1/binlog/mysql-bin
max_binlog_cache_size = 512M
max_binlog_size = 512M
binlog_format = mixed
log_output = FILE
log-error = /data/sql1/log/mysql-error.log

slow_query_log = 1
slow_query_log_file = /data/sql1/log/slow_query.log
general_log = 0
general_log_file = /data/sql1/log/general_query.log
expire-logs-days = 14

#Innodb
innodb_data_file_path = ibdata1:128M:autoextend
innodb_log_file_size = 256M
innodb_log_files_in_group = 3
innodb_log_group_home_dir = /data/sql1/log
innodb_buffer_pool_size = 512M
innodb_file_per_table = 1

explicit_defaults_for_timestamp=true

 

 

--创建数据库 -DCMAKE_INSTALL_PREFIX 安装报错查看日志 mysql-error.log
su - mysql
/usr/local/mysql/scripts/mysql_install_db --datadir=/data/sql1/data --basedir=/usr/local/mysql

 

--手工启动mysql
su - mysql
mkdir scripts

vi /home/mysql/scripts/mysql_startup.sh
#! /bin/bash
/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/mysql/my.cnf &

 

--关闭mysql
mysqladmin -u root -p shutdown

 

--sudo 添加执行权限 关闭requiretty
chmod 740 /etc/sudoers

vi /etc/sudoers
#Defaults requiretty

chmod 440 /etc/sudoers


--重启自动启动
vi /etc/rc.local

sudo -i -u mysql /home/mysql/scripts/mysql_startup.sh > /tmp/mysql_db_startup.log 2>&1

 

mysql 5.6单机单实例源码编译安装配置