mysql 5.6.22版本下载地址:
链接: https://pan.baidu.com/s/1r0d8xkde4q-dByKK-67keA
提取码: 28ep
此压缩包,不需要编译,直接解压到安装目录使用即可!
1、解压缩文件:
解压出来mysql文件夹、my.cnf、mysqld、pro.sh 三个文件
[root@localhost donghua]# tar -zxvf mysql5.6.22.tar
[root@localhost donghua]# ll
total 315624
-rw-r--r-- 1 505 wheel 1177 Feb 13 2015 my.cnf
drwxr-xr-x 13 505 wheel 4096 Feb 13 2015 mysql
-rw-r--r-- 1 root root 323172009 Nov 8 14:47 mysql5.6.22.tar
-rwxr-xr-x 1 505 wheel 10982 Feb 13 2015 mysqld
-rw-r--r-- 1 505 wheel 677 Feb 13 2015 pro.sh
2、创建mysql用户,不建立mysql用户家目录(加-M参数),也就是禁用mysql账号登陆系统
[root@localhost donghua]# groupadd -r mysql
[root@localhost donghua]# useradd -r -s /sbin/nologin -M -g mysql mysql
3、修改/opt/donghua/mysql权限
[root@localhost donghua]# chown -hR mysql:mysql ./mysql
[root@localhost donghua]# ll
total 315624
-rw-r--r-- 1 505 wheel 1177 Feb 13 2015 my.cnf
drwxr-xr-x 13 mysql mysql 4096 Feb 13 2015 mysql
-rw-r--r-- 1 root root 323172009 Nov 8 14:47 mysql5.6.22.tar
-rwxr-xr-x 1 505 wheel 10982 Feb 13 2015 mysqld
-rw-r--r-- 1 505 wheel 677 Feb 13 2015 pro.sh
4、执行初始化配置脚本,创建系统自带的数据库和表
[root@localhost donghua]# cd mysql/
[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/opt/donghua/mysql/data
--datadir 是mysql的数据存放目录
--如果后续不小心删除了这个数据目录或这个目录下的文件被误操作删除了,还可以利用这个命令重新初始化
5、修改/opt/donghua/my.cnf文件,配置如下图所示:
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[mysqld]
# [设置从服务器id,必须于主服务器不同]
server-id = 2
# [启动MySQ二进制日志系统]
log-bin=mysql-bin
# [需要同步的数据库名。如果不指明同步哪些库,就去掉这行,表示所有库的同步(除了ignore忽略的库)]
#replicate-do-db = mysql
# [不同步mysql数据库]
#replicate-ignore-db=mysql
# [跳过所有的错误,继续执行复制操作]
slave-skip-errors = all
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
# 数据data存放目录
datadir=/opt/donghua/mysql/data/
skip-name-resolve
character_set_server = utf8
port = 3306
log-bin-trust-function-creators=1
#binlog_format=ROW
expire_logs_days = 10
skip-external-locking
relay-log-recovery=1
log_slave_update=1
#INNODB#
innodb_log_file_size = 512M
innodb_buffer_pool_size = 8G
innodb_buffer_pool_instances = 8
innodb_log_files_in_group = 2
innodb_flush_log_at_trx_commit = 1
innodb_file_per_table = 1
innodb_flush_method = O_DIRECT
innodb_log_buffer_size = 64M
#thread buffer
max_connections = 300
key_buffer_size = 512M
max_allowed_packet = 64M
table_open_cache = 10K
#sql_mode
sql_mode='NO_ENGINE_SUBSTITUTION'
6、把my.cnf文件拷贝到 /etc下,并且同时替换mysql 目录下的my.cnf
[root@localhost donghua]# vim my.cnf
[root@localhost donghua]# cp my.cnf /etc/my.cnf
[root@localhost donghua]# cp my.cnf ./mysql/my.cnf
7、修改/opt/donghua/mysqld 文件(当前目录下的)
主要修改以下内容,修改为mysql 存放的目录
。。。。。。
# The following variables are only set for letting mysql.server find things.
# Set some defaults
mysqld_pid_file_path=
if test -z "$basedir"
then
basedir=/opt/donghua/mysql
bindir=/opt/donghua/mysql/bin
if test -z "$datadir"
then
datadir=/opt/donghua/mysql/data
fi
sbindir=/opt/donghua/mysql/bin
libexecdir=/opt/donghua/mysql/bin
else
bindir="$basedir/bin"
if test -z "$datadir"
then
datadir="$basedir/data"
fi
sbindir="$basedir/sbin"
libexecdir="$basedir/libexec"
fi
。。。。
8、拷贝mysqld文件到 /etc/rc.d/init.d/ 目录下
[root@localhost donghua]# vim mysqld
[root@localhost donghua]# cp mysqld /etc/rc.d/init.d/mysqld
增加mysqld的可执行权限:
[root@localhost donghua]# chmod +x /etc/rc.d/init.d/mysqld
9、拷贝服务脚本到init.d目录,并设置开机启动
[root@localhost donghua]# chkconfig --add mysqld
[root@localhost donghua]# chkconfig mysqld on
[root@localhost donghua]# echo -e "\nMANPATH /opt/donghua/mysql/man" >> /etc/man.config
10、添加软连接到/usr/include/ 下
[root@localhost donghua]# ln -sv /opt/donghua/mysql/include /usr/include/mysql
‘/usr/include/mysql’ -> ‘/opt/donghua/mysql/include’
[root@localhost donghua]# echo -e "/opt/donghua/mysql/lib" > /etc/ld.so.conf.d/mysql.conf
[root@localhost donghua]# ldconfig
11、添加服务
[root@localhost donghua]# echo "export PATH=$PATH:/opt/donghua/mysql/bin" > /etc/profile.d/mysql.sh
[root@localhost donghua]# source /etc/profile.d/mysql.sh
12、启动MySQL
[root@localhost donghua]# service mysqld start
Starting MySQL................. SUCCESS!
在解压出的文件中,有一个pro.sh脚本,修改其中的配置参数,可以自动安装配置mysql:
前提要配置好 my.cnf、mysqld文件
#!/bin/bash
export PATH
PAT=/home/product_user/donghua/mysql
groupadd -r mysql
useradd -r -s /sbin/nologin -M mysql
chown -hR mysql:mysql ./mysql
cd $PAT
scripts/mysql_install_db --user=mysql --datadir=$PAT/data
cp /home/product_user/donghua/my.cnf /etc/my.cnf
cp /home/product_user/donghua/mysqld /etc/rc.d/init.d/mysqld
chmod +x /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
echo -e "\nMANPATH /home/product_user/donghua/mysql/man" >> /etc/man.config
ln -sv $PAT/include /usr/include/mysql
echo -e "$PAT/lib" > /etc/ld.so.conf.d/mysql.conf
ldconfig
echo "export PATH=$PATH:$PAT/bin" > /etc/profile.d/mysql.sh
source /etc/profile.d/mysql.sh
https://www.cnblogs.com/kevingrace/p/6109679.html