Centos 7.0 安裝 Mysql 5.6.22

mysql 5.6.22版本下載地址:
鏈接: https://pan.baidu.com/s/1r0d8xkde4q-dByKK-67keA
提取碼: 28ep
此壓縮包,不需要編譯,直接解壓到安裝目錄使用即可!

1、解壓縮文件:
解壓出來mysql文件夾、my.cnf、mysqld、pro.sh 三個文件

[root@localhost sumscope]# tar -zxvf mysql5.6.22.tar 
[root@localhost sumscope]# 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 sumscope]# groupadd -r mysql
[root@localhost sumscope]# useradd -r -s /sbin/nologin -M -g mysql mysql

3、修改/opt/sumscope/mysql權限

[root@localhost sumscope]# chown -hR mysql:mysql ./mysql
[root@localhost sumscope]# 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 sumscope]# cd mysql/
[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/opt/sumscope/mysql/data
--datadir 是mysql的數據存放目錄
--如果後續不小心刪除了這個數據目錄或這個目錄下的文件被誤操作刪除了,還可以利用這個命令重新初始化

5、修改/opt/sumscope/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/sumscope/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 sumscope]# vim my.cnf
[root@localhost sumscope]# cp my.cnf /etc/my.cnf 
[root@localhost sumscope]# cp my.cnf ./mysql/my.cnf

7、修改/opt/sumscope/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/sumscope/mysql
  bindir=/opt/sumscope/mysql/bin
  if test -z "$datadir"
  then
    datadir=/opt/sumscope/mysql/data
  fi
  sbindir=/opt/sumscope/mysql/bin
  libexecdir=/opt/sumscope/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 sumscope]# vim mysqld
[root@localhost sumscope]# cp mysqld /etc/rc.d/init.d/mysqld
增加mysqld的可執行權限:
[root@localhost sumscope]# chmod +x /etc/rc.d/init.d/mysqld

9、拷貝服務腳本到init.d目錄,並設置開機啓動

[root@localhost sumscope]# chkconfig --add mysqld
[root@localhost sumscope]# chkconfig mysqld on
[root@localhost sumscope]# echo -e "\nMANPATH /opt/sumscope/mysql/man" >> /etc/man.config

10、添加軟連接到/usr/include/ 下

[root@localhost sumscope]# ln -sv /opt/sumscope/mysql/include /usr/include/mysql
‘/usr/include/mysql’ -> ‘/opt/sumscope/mysql/include’
[root@localhost sumscope]# echo -e "/opt/sumscope/mysql/lib" > /etc/ld.so.conf.d/mysql.conf
[root@localhost sumscope]# ldconfig

11、添加服務

[root@localhost sumscope]# echo "export PATH=$PATH:/opt/sumscope/mysql/bin" > /etc/profile.d/mysql.sh
[root@localhost sumscope]# source /etc/profile.d/mysql.sh 

12、啓動MySQL

[root@localhost sumscope]# service mysqld start
Starting MySQL................. SUCCESS! 

在解壓出的文件中,有一個pro.sh腳本,修改其中的配置參數,可以自動安裝配置mysql:
前提要配置好 my.cnf、mysqld文件

#!/bin/bash
export PATH
PAT=/home/product_user/sumscope/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/sumscope/my.cnf /etc/my.cnf
cp /home/product_user/sumscope/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/sumscope/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

發佈了25 篇原創文章 · 獲贊 3 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章