CentOS6.4+MySQL-5.6.12 安装详解

大纲
一、安装方式分类
二、具体安装方式详解

相关阅读:

MySQL 5.5 三大安装方式:【二进制、源代码编译 和 RPM 包】 安装步骤及优缺点比较 

  • 源码安装

  • 通用二进制包安装

  • RPM包安装

一、Mysql安装方式分类
1.源码包安装
从MySQL5.5开始就要用cmake安装了,已不能用./configure编译安装,我们查看一下mysql5.6.12的安装目录,从下面的安装目录我们可以看到,里面根本没有configure文件,下面我们来说说cmake,

[root@mysql mysql-5.6.12]# ls
BUILD          config.h.cmake      extra              libmysqld    packaging  sql-bench      unittest
BUILD-CMAKE    configure.cmake      include            libservices  plugin    sql-common    VERSION
client          COPYING              INSTALL-SOURCE      man          README    storage        vio
cmake          dbug                INSTALL-WIN-SOURCE  mysql-test  regex      strings        win
CMakeLists.txt  Docs                libevent            mysys        scripts    support-files  zlib
cmd-line-utils  Doxyfile-perfschema  libmysql            mysys_ssl    sql        tests

cmake的重要特性之一是其独立于源码(out-of-source)的编译功能,即编译工作可以在另一个指定的目录中而非源码目录中进行,这可以保证源码目录不受任何一次编译的影响,因此在同一个源码树上可以进行多次不同的编译,如针对于不同平台编译。

2.通用二进制包安装

通用二进制包安装说明软件包已经编译好,不需要我们重新编译,我们只要解压一下,进行简单配置便可以运行使用!

3.RPM包安装
这个安装我们不过多说明,大家应该都知道!好了,下面我们就来具体说明这三种安装!

二、具体安装方式详解

  • 源码安装

  • 通用二进制包安装

  • RPM包安装

源码包安装
1.安装cmake(最新的cmake-2.8.11.2)
123456789101112131415161718 [root@mysql src]# tar xf cmake-2.8.11.2.tar.gz
[root@mysql src]# cd cmake-2.8.11.2
[root@mysql cmake-2.8.11.2]# ls
bootstrap                  CTestCustom.cmake.in
ChangeLog.manual            CTestCustom.ctest.in
ChangeLog.txt              DartConfig.cmake
CMakeCPack.cmake            DartLocal.conf.in
CMakeCPackOptions.cmake.in  Docs
CMakeGraphVizOptions.cmake  doxygen.config
CMakeLists.txt              Example
CMakeLogo.gif              Modules
cmake_uninstall.cmake.in    Readme.txt
CompileFlags.cmake          Source
configure                  Templates
Copyright.txt              Tests
CTestConfig.cmake          Utilities
[root@mysql cmake-2.8.11.2]# ./bootstrap
[root@mysql cmake-2.8.11.2]# make && make install

2.安装编译MySQL-5.6.12
说明:cmake指定编译选项的方式不同于make,其实现方式对比如下
./configure 对应的是 cmake .
./configure --help 对应的是 cmake . -LH 或者是 ccmake .
3.创建mysql的用户与组
12 [root@mysql ~]# groupadd -r mysql
[root@mysql ~]# useradd -g mysql -r  -s /sbin/nologin mysql

4.创建mysql的数据目录(创建逻辑卷存放数据)

[root@mysql ~]# fdisk /dev/sda #创建一个新分区类型为8e
Command (m for help): p
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0000a0a2
  Device Boot      Start        End      Blocks  Id  System
/dev/sda1  *          1          26      204800  83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              26        1301    10240000  83  Linux
/dev/sda3            1301        1938    5120000  83  Linux
/dev/sda4            1938        2611    5405696    5  Extended
/dev/sda5            1939        2066    1024000  82  Linux swap / Solaris
/dev/sda6            1938        1938        1129+  83  Linux
/dev/sda7            2066        2327    2099724  8e  Linux LVM
[root@mysql ~]# partx -a /dev/sda #让内核重新读取一下分区
BLKPG: Device or resource busy
error adding partition 1
BLKPG: Device or resource busy
error adding partition 2
BLKPG: Device or resource busy
error adding partition 3
BLKPG: Device or resource busy
error adding partition 4
BLKPG: Device or resource busy
error adding partition 5
[root@mysql ~]# fdisk -l #查看新建的分区
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0000a0a2
  Device Boot      Start        End      Blocks  Id  System
/dev/sda1  *          1          26      204800  83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              26        1301    10240000  83  Linux
/dev/sda3            1301        1938    5120000  83  Linux
/dev/sda4            1938        2611    5405696    5  Extended
/dev/sda5            1939        2066    1024000  82  Linux swap / Solaris
/dev/sda6            1938        1938        1129+  83  Linux
/dev/sda7            2066        2327    2099724  8e  Linux LVM
Partition table entries are not in disk order
[root@mysql ~]# yum install -y lvm2 #安装lvm
[root@mysql ~]# pvcreate /dev/sda7 #创建物理卷
  Physical volume "/dev/sda7" successfully created
[root@mysql ~]# vgcreate myvg /dev/sda7 #创建卷组
  Volume group "myvg" successfully created
[root@mysql ~]# lvcreate -L 1G -n mydata myvg #创建逻辑卷
  Logical volume "mydata" created
[root@mysql ~]# lvs #查看逻辑卷
  LV    VG  Attr      LSize Pool Origin Data%  Move Log Cpy%Sync Convert
  mydata myvg -wi-a---- 1.00g                                     
[root@mysql ~]# mkfs.ext4 /dev/myvg/mydata #格式化
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe  blocks
65536 inodes, 262144 blocks
13107 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376
正在写入inode表: 完成                     
Creating journal (8192 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 33 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

5.挂载设置

[root@mysql ~]# mkdir /mydata #创建挂载目录
[root@mysql ~]# vim /etc/fstab  #修改挂载配置文件
#新增一行
/dev/myvg/mydata        /mydata        ext3    defaults        0 0
[root@mysql ~]# mount -a #挂载
[root@mysql ~]# mount #查看所有挂载
/dev/sda2 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda1 on /boot type ext4 (rw)
/dev/sda3 on /data type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/mapper/myvg-mydata on /mydata type ext4 (rw)

6.数据目录配置

[root@mysql ~]# cd /mydata/
[root@mysql mydata]# mkdir data
[root@mysql mydata]# chown -R mysql.mysql data
[root@mysql mydata]# ll
总用量 20
drwxr-xr-x 2 mysql mysql  4096 7月  18 13:16 data
drwx------ 2 root  root  16384 7月  18 13:10 lost+found

7.编译安装


[root@mysql mysql-5.6.12]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/mydata/data \
-DSYSCONFDIR=/etc \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DWITH_SSL:STRING=bundled \
-DWITH_ZLIB:STRING=bundled \
-DWITH_LIBWRAP=0 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci

报错,

[root@mysql mysql-5.6.12]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/mydata/data -DSYSCONFDIR=/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DWITH_SSL=bundled -DWITH_ZLIB=bundled -DWITH_LIBWRAP=0 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
-- Running cmake version 2.8.11.2
-- MySQL 5.6.12
-- Packaging as: mysql-5.6.12-Linux-x86_64
-- HAVE_VISIBILITY_HIDDEN
CMake Error at cmake/ssl.cmake:164 (FILE):
  file STRINGS file  "/root/src/mysql-5.6.12/OPENSSL_INCLUDE_DIR-NOTFOUND/openssl/opensslv.h"
  cannot be read.
Call Stack (most recent call first):
  CMakeLists.txt:323 (MYSQL_CHECK_SSL)
-- OPENSSL_INCLUDE_DIR = OPENSSL_INCLUDE_DIR-NOTFOUND
-- OPENSSL_LIBRARY = OPENSSL_LIBRARY-NOTFOUND
-- CRYPTO_LIBRARY = CRYPTO_LIBRARY-NOTFOUND
-- OPENSSL_MAJOR_VERSION =
CMake Error at cmake/ssl.cmake:231 (MESSAGE):
  Cannot find appropriate system libraries for SSL.  Use WITH_SSL=bundled to
  enable SSL support
Call Stack (most recent call first):
  CMakeLists.txt:323 (MYSQL_CHECK_SSL)
-- HAVE_VISIBILITY_HIDDEN
-- HAVE_VISIBILITY_HIDDEN
-- Could NOT find Curses (missing:  CURSES_LIBRARY CURSES_INCLUDE_PATH)
CMake Error at cmake/readline.cmake:85 (MESSAGE):  Curses library not found.  Please install appropriate package,
remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on RedHat and derivates it is ncurses-devel.
Call Stack (most recent call first):
  cmake/readline.cmake:128 (FIND_CURSES)
  cmake/readline.cmake:202 (MYSQL_USE_BUNDLED_EDITLINE)
  CMakeLists.txt:325 (MYSQL_CHECK_EDITLINE)
-- Configuring incomplete, errors occurred!

从上面的错误中我们可以很清楚的看到缺少两个依赖包,我们用yum安装一下即可!

[root@mysql mysql-5.6.12]# yum install �y openssl openssl-devel ncurses ncurses-devel

下面我们再次编译一下,可能还会报同样的错误,不要着急,遇到错误,应该是很欣慰,现在知道了,以后就有把握自己处理,不必再百度,谷歌,满世界询问了,嘿嘿!

[root@mysql mysql-5.6.12]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/mydata/data -DSYSCONFDIR=/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DWITH_SSL=bundled -DWITH_ZLIB=bundled -DWITH_LIBWRAP=0 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
-- Running cmake version 2.8.11.2
-- MySQL 5.6.12
-- Packaging as: mysql-5.6.12-Linux-x86_64
-- HAVE_VISIBILITY_HIDDEN
CMake Error at cmake/ssl.cmake:164 (FILE):
  file STRINGS file  "/root/src/mysql-5.6.12/OPENSSL_INCLUDE_DIR-NOTFOUND/openssl/opensslv.h"
  cannot be read.
Call Stack (most recent call first):
  CMakeLists.txt:323 (MYSQL_CHECK_SSL)
-- OPENSSL_INCLUDE_DIR = OPENSSL_INCLUDE_DIR-NOTFOUND
-- OPENSSL_LIBRARY = OPENSSL_LIBRARY-NOTFOUND
-- CRYPTO_LIBRARY = CRYPTO_LIBRARY-NOTFOUND
-- OPENSSL_MAJOR_VERSION =
CMake Error at cmake/ssl.cmake:231 (MESSAGE):
  Cannot find appropriate system libraries for SSL.  Use WITH_SSL=bundled to
  enable SSL support
Call Stack (most recent call first):
  CMakeLists.txt:323 (MYSQL_CHECK_SSL)
-- HAVE_VISIBILITY_HIDDEN
-- HAVE_VISIBILITY_HIDDEN
-- Could NOT find Curses (missing:  CURSES_LIBRARY CURSES_INCLUDE_PATH)
CMake Error at cmake/readline.cmake:85 (MESSAGE):  Curses library not found.  Please install appropriate package,
remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
Call Stack (most recent call first):
  cmake/readline.cmake:128 (FIND_CURSES)
  cmake/readline.cmake:202 (MYSQL_USE_BUNDLED_EDITLINE)
  CMakeLists.txt:325 (MYSQL_CHECK_EDITLINE)
-- Configuring incomplete, errors occurred!

这里是因为,我们在多次运行cmake有个文件我们需要删除,删除当前目录下CMakeCache.txt文件并重新编译,再次运行cmake命令就会正常!

[root@mysql mysql-5.6.12]# rm  -rf CMakeCache.txt
[root@mysql mysql-5.6.12]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/mydata/data -DSYSCONFDIR=/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DWITH_SSL=bundled -DWITH_ZLIB=bundled -DWITH_LIBWRAP=0 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci

这下我们就可以顺利编译!

[root@mysql mysql-5.6.12]# make && make install


8.编译选项说明
指定安装文件的安装路径时常用的选项
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql    ----指定残可安装路径(默认的就是/usr/local/mysql)
-DMYSQL_DATADIR=/data/mysql          ----mysql的数据文件路径
-DSYSCONFDIR=/etc                ----配置文件路径

编译过程中启用其他存储引擎时指令介绍
123 -DWITH_INNOBASE_STORAGE_ENGINE=1        ----使用INNOBASE存储引擎
-DWITH_ARCHIVE_STORAGE_ENGINE=1            ----常应用于日志记录和聚合分析,不支持索引
-DWITH_BLACKHOLE_STORAGE_ENGINE=1      ----黑洞存储引擎

编译过程中取消一些存储引擎指令介绍
-DWITHOUT_<ENGINE>_STORAGE_ENGINE=1
示例如下:
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1
-DWITHOUT_FEDERATED_STORAGE_ENGINE=1
-DWITHOUT_PARTITION_STORAGE_ENGINE=1

编译进过程中功能启用的指令介绍
-DWITH_READLINE=1      ----支持批量导入mysql数据
-DWITH_SSL=system      ----mysql支持ssl会话,实现基于ssl的数据复
-DWITH_ZLIB=system      ----压缩库
-DWITH_LIBWRAP=0        ----是否可以基于WRAP实现访问控制

其他功能指令
-DMYSQL_TCP_PORT=3306                  ----默认端口
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock      ----默认套接字文件路径
-DENABLED_LOCAL_INFILE=1                ----是否启用LOCAL_INFILE功能
-DEXTRA_CHARSETS=all  ----是否支持额外的字符集
-DDEFAULT_CHARSET=utf8                  ----默认编码机制
-DDEFAULT_COLLATION=utf8_general_ci    ----设定默认语言的排序规则
-DWITH_DEBUG=0                          ----DEBUG功能设置
-DENABLE_PROFILING=1                    ----性能分析功能是否启用

9.mysql服务脚本
[root@mysql mysql-5.6.12]# cp support-files/mysql.server /etc/init.d/mysqld #复制脚本
[root@mysql mysql-5.6.12]# chmod +x /etc/init.d/mysqld #增加可执行权限
[root@mysql ~]# chkconfig --add mysqld #增加至sysV服务
[root@mysql ~]# chkconfig mysqld on  #开机自启动

10.初始化mysql
[root@mysql ~]# /usr/local/mysql/scripts/mysql_install_db --datadir=/mydata/data --user=mysql
FATAL ERROR: Could not find ./bin/my_print_defaults
If you compiled from source, you need to run 'make install' to
copy the software into the correct location ready for operation.
If you are using a binary release, you must either be at the top
level of the extracted archive, or pass the --basedir option
pointing to that location.

出错!解决方法如下,
[root@mysql data]# /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/mydata/data --user=mysql #mysql初始化

说明初始化时得,增加 --basedir选项
[root@mysql data]# ls #查看生成的文件
ibdata1  ib_logfile0  ib_logfile1  mysql  performance_schema  test
[root@mysql data]# cd /usr/local/mysql/
[root@mysql mysql]# ls
bin      data  include        lib  my.cnf      README  share      support-files
COPYING  docs  INSTALL-BINARY  man  mysql-test  scripts  sql-bench

#在/usr/local/mysql目录下自动生成my.cnf的配置文件
1234567891011121314151617181920212223 [root@mysql mysql]# cat my.cnf #查看一下配置文件
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
[mysqld]
# 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
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

11.修改mysql配置文件
[root@mysql mysql]# vim my.cnf   
#增加如下内容
binlog-format=ROW
log-bin=master-bin.log
log-slave-updates=true
gtid-mode=on
enforce-gtid-consistency=true
master-info-repository=TABLE
relay-log-info-repository=TABLE
sync-master-info=1
slave-parallel-workers=2
binlog-checksum=CRC32
master-verify-checksum=1
slave-sql-verify-checksum=1
binlog-rows-query-log_events=1
server-id=1
report-port=3306
port=3306
datadir=/mydata/data
socket=/tmp/mysql.sock
report-host=master.magedu.com

12.启动mysql

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


13.mysql命令添加到环境变量中
root@mysql mysql]# vim /etc/profile.d/mysql.sh
exportPATH=$PATH:/usr/local/mysql/bin
[root@mysql mysql]# source /etc/profile #重新读取环境变量

14.输出mysql的man手册到man命令的查找路径

[root@mysql mysql]# vim /etc/man.config
#新增一行
MANPATH /usr/local/mysql/man

15.输出mysql的库文件
[root@mysql mysql]# vim /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib/
[root@mysql mysql]# ldconfig -v
/usr/local/mysql/lib:
        libmysqlclient.so.18 -> libmysqlclient_r.so.18.0.0

16.输出mysql的头文件到系统头文件

[root@mysql mysql]# ln -sv /usr/local/mysql/include/ /usr/include/mysql
"/usr/include/mysql" -> "/usr/local/mysql/include/"
[root@mysql mysql]# cd /usr/include/mysql/
[root@mysql mysql]# ls
big_endian.h                m_string.h      my_global.h        mysql_embed.h      plugin_validate_password.h
byte_order_generic.h        my_alloc.h      my_list.h          mysql.h            sql_common.h
byte_order_generic_x86_64.h  my_attribute.h  my_net.h            mysql_time.h      sql_state.h
byte_order_generic_x86.h    my_byteorder.h  my_pthread.h        mysql_version.h    sslopt-case.h
decimal.h                    my_compiler.h  mysql              my_sys.h          sslopt-longopts.h
errmsg.h                    my_config.h    mysql_com.h        my_xml.h          sslopt-vars.h
keycache.h                  my_dbug.h      mysql_com_server.h  plugin_audit.h    typelib.h
little_endian.h              my_dir.h        mysqld_ername.h    plugin_ftparser.h
m_ctype.h                    my_getopt.h    mysqld_error.h      plugin.h

好了到这里mysql的源码安装的配置过程全部完成,下面我们测试一下!

17.测试
1).查看端口
[root@mysql mysql]# netstat -ntulp | grep :3306
tcp        0      0 :::3306                    :::*                        LISTEN      41347/mysqld

2).登录mysql
[root@mysql mysql]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.12-log Source distribution
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database          |
+--------------------+
| information_schema |

测试全部完成,下面我们继续说,mysql的通用二进制安装!


通用二进制包安装
1. 准备数据存放的文件系统
说明:新建一个逻辑卷,并将其挂载至特定目录即可。这里假设其逻辑卷的挂载目录为/mydata,而后需要创建/mydata/data目录做为mysql数据的存放目录。
(1). 先确认下系统里是否有LVM工具,默认没有安装
[root@web httpd]# rpm -qa | grep lvm
[root@web httpd]# yum install -y lvm2

(2). 查看一下磁盘
[root@web httpd]# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/Osize (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0000a0a2
Device Boot Start End Blocks Id System
/dev/sda1* 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda226 1301 10240000 83 Linux
/dev/sda31301 1938 5120000 83 Linux
/dev/sda41938 2611 5405696 5 Extended
/dev/sda51939 2066 1024000 82 Linux swap / Solaris
[root@web httpd]#

(3). 创建逻辑分区
[root@web ~]# fdisk /dev/sda
/dev/sda72066 2327 2099724 8e Linux LVM #我这里是测试环境就创建了一个2G分区
[root@web ~]# partx -a /dev/sda #告诉内核有关存在和磁盘上的分区的编号
[root@web ~]# pvcreate /dev/sda7 #创建物理卷
Physical volume "/dev/sda7"successfully created
[root@web ~]# vgcreate myvg /dev/sda7 #创建卷组
Volume group "myvg"successfully created
[root@web ~]#
[root@web ~]# lvcreate -n mydata -L 1G myvg #创建一个1G的逻辑卷
Logical volume "mydata"created
[root@web ~]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
mydata myvg -wi-a---- 1.00g
[root@web ~]#
[root@web ~]# mkfs.ext4 /dev/myvg/mydata #格式化
[root@web ~]# mkdir /mydata #创建挂载目录
[root@web ~]# mount /dev/myvg/mydata /mydata/ #挂载
[root@web ~]# vim /etc/fstab
/dev/myvg/mydata/mydataext4 defaults 0 0 #增加这一行
[root@web ~]# mount �a #测试挂载是否成功
[root@web ~]# mount
/dev/sda2on / typeext4 (rw)
proc on /proctypeproc (rw)
sysfs on /systypesysfs (rw)
devpts on /dev/ptstypedevpts (rw,gid=5,mode=620)
tmpfs on /dev/shmtypetmpfs (rw)
/dev/sda1on /boottypeext4 (rw)
/dev/sda3on /datatypeext4 (rw)
none on /proc/sys/fs/binfmt_misctypebinfmt_misc (rw)
/dev/mapper/myvg-mydataon /mydatatypeext4 (rw)
[root@web ~]#

(4). 为了便于管理在/mydata目录下再创建个子目录data用于存放数据
[root@web ~]# mkdir /mydata/data
[root@web ~]# ls /mydata/
data lost+found

2. 新建用户以安全方式运行进程

[root@web ~]# groupadd -r mysql
[root@web ~]# useradd -g mysql -r -s /sbin/nologin -M -d /mydata/data mysql
[root@web ~]# chown -R mysql:mysql /mydata/data

3. 安装并初始化mysql5.6.12
(1). 通用二进制包安装
[root@web src]# tar -xf mysql-5.6.12-linux-glibc2.5-x86_64.tar.gz -C /usr/local/ #-C指定解压目录
[root@web local]# ln -sv mysql-5.6.12-linux-glibc2.5-x86_64/ mysql #创建软链接
`mysql' -> `mysql-5.6.12-linux-glibc2.5-x86_64/'
[root@web local]# cd mysql
[root@web mysql]# ls
bin data include lib mysql-testscripts sql-bench
COPYING docs INSTALL-BINARY manREADME share support-files
[root@web mysql]#
[root@web mysql]# chown -R mysql:mysql . #更改属主属组
[root@web mysql]# ll
total 76
drwxr-xr-x 2 mysql mysql 4096 Jun 29 21:12 bin
-rw-r--r-- 1 mysql mysql 17987 May 21 23:18 COPYING
drwxr-xr-x 3 mysql mysql 4096 Jun 29 21:12 data
drwxr-xr-x 2 mysql mysql 4096 Jun 29 21:12 docs
drwxr-xr-x 3 mysql mysql 4096 Jun 29 21:12 include
-rw-r--r-- 1 mysql mysql 7469 May 21 23:18 INSTALL-BINARY
drwxr-xr-x 3 mysql mysql 4096 Jun 29 21:12 lib
drwxr-xr-x 4 mysql mysql 4096 Jun 29 21:12 man
drwxr-xr-x 10 mysql mysql 4096 Jun 29 21:12 mysql-test
-rw-r--r-- 1 mysql mysql 2496 May 21 23:18 README
drwxr-xr-x 2 mysql mysql 4096 Jun 29 21:12 scripts
drwxr-xr-x 28 mysql mysql 4096 Jun 29 21:12 share
drwxr-xr-x 4 mysql mysql 4096 Jun 29 21:12 sql-bench
drwxr-xr-x 3 mysql mysql 4096 Jun 29 21:12 support-files

(2). 执行mysql 初始化的data存放位置的准备
[root@web mysql]# scripts/mysql_install_db --user=mysql --datadir=/mydata/data #执行mysql 初始化的data存放位置的准备
Installing MySQL system tables..../bin/mysqld: error whileloading shared libraries: libaio.so.1: cannot openshared object file: No such fileor directory
#初始化时报错说缺少libaio.so我们安装一下
[root@web mysql]# yum install libaio
[root@web mysql]# scripts/mysql_install_db --user=mysql --datadir=/mydata/data #再次执行mysql 初始化的data存放位置的准备
To start mysqld at boot timeyou have to copy
support-files/mysql.server to the right place foryour system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To doso, start the server, thenissue the following commands:
./bin/mysqladmin-u root password 'new-password'
./bin/mysqladmin-u root -h web.test.com password 'new-password'
Alternatively you can run:
./bin/mysql_secure_installation
whichwill also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended forproduction servers.
See the manual formoreinstructions.
You can start the MySQL daemon with:
cd. ; ./bin/mysqld_safe&
You can testthe MySQL daemon with mysql-test-run.pl
cdmysql-test; perl mysql-test-run.pl
Please report any problems with the ./bin/mysqlbugscript!
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licensesat http://shop.mysql.com
WARNING: Found existing config file./my.cnf on the system.
Because this filemight be inuse, it was not replaced,
but was used inbootstrap (unless you used --defaults-file)
and when you later start the server.
The new default config filewas created as ./my-new.cnf,
please compare it with your fileand take the changes you need.
WARNING: Default config file/etc/my.cnf exists on the system
This filewill be readby default by the MySQL server
If you donot want to use this, either remove it, or use the
--defaults-fileargument to mysqld_safe when starting the server
[root@web mysql]#
[root@web mysql]# ls /mydata/data/ #查看 data 目录有文件说明初始化成功
ibdata1 ib_logfile0 ib_logfile1 mysql performance_schema test

(3). 初始化完成后mysql中目录文件的属主应改回成root,以免被别人攻破mysql用户密码而带来数据破坏等
[root@web mysql]# cd /usr/local/mysql/
[root@web mysql]# chown root /usr/local/mysql/* -R
[root@web mysql]# ll
total 84
drwxr-xr-x 2 root mysql 4096 Jun 29 21:12 bin
-rw-r--r-- 1 root mysql 17987 May 21 23:18 COPYING
drwxr-xr-x 3 root mysql 4096 Jun 29 21:12 data
drwxr-xr-x 2 root mysql 4096 Jun 29 21:12 docs
drwxr-xr-x 3 root mysql 4096 Jun 29 21:12 include
-rw-r--r-- 1 root mysql 7469 May 21 23:18 INSTALL-BINARY
drwxr-xr-x 3 root mysql 4096 Jun 29 21:12 lib
drwxr-xr-x 4 root mysql 4096 Jun 29 21:12 man
-rw-r--r-- 1 root root 943 Jun 29 21:18 my.cnf
-rw-r--r-- 1 root root 943 Jun 29 21:23 my-new.cnf
drwxr-xr-x 10 root mysql 4096 Jun 29 21:12 mysql-test
-rw-r--r-- 1 root mysql 2496 May 21 23:18 README
drwxr-xr-x 2 root mysql 4096 Jun 29 21:12 scripts
drwxr-xr-x 28 root mysql 4096 Jun 29 21:12 share
drwxr-xr-x 4 root mysql 4096 Jun 29 21:12 sql-bench
drwxr-xr-x 3 root mysql 4096 Jun 29 21:12 support-files
[root@web mysql]#

4. 为mysql提供主配置文件
初始化后会自动在当前目录下创建一个my.cnf配置文件,直接修改就可以(在mysql 5.6 以后配置文件自动生成,不需要我们再进行复制)
(1).  查看配置文件
[root@web mysql]# ll
total 84
drwxr-xr-x  2 root mysql  4096 Jun 29 21:12 bin
-rw-r--r--  1 root mysql 17987 May 21 23:18 COPYING
drwxr-xr-x  3 root mysql  4096 Jun 29 21:12 data
drwxr-xr-x  2 root mysql  4096 Jun 29 21:12 docs
drwxr-xr-x  3 root mysql  4096 Jun 29 21:12 include
-rw-r--r--  1 root mysql  7469 May 21 23:18 INSTALL-BINARY
drwxr-xr-x  3 root mysql  4096 Jun 29 21:12 lib
drwxr-xr-x  4 root mysql  4096 Jun 29 21:12 man
-rw-r--r--  1 root root    943 Jun 29 21:18 my.cnf
-rw-r--r--  1 root root    943 Jun 29 21:23 my-new.cnf
drwxr-xr-x 10 root mysql  4096 Jun 29 21:12 mysql-test
-rw-r--r--  1 root mysql  2496 May 21 23:18 README
drwxr-xr-x  2 root mysql  4096 Jun 29 21:12 scripts
drwxr-xr-x 28 root mysql  4096 Jun 29 21:12 share
drwxr-xr-x  4 root mysql  4096 Jun 29 21:12 sql-bench
drwxr-xr-x  3 root mysql  4096 Jun 29 21:12 support-files
[root@web mysql]#
[root@web mysql]# cat my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
[mysqld]
# 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
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[root@web mysql]#

大家可以看到生成的配置文件很简单,我们得添加一些内容!
(2).  修改配置文件
[root@web mysql]# vim my.cnf
添加内容是:
binlog-format=ROW
log-bin=master-bin.log
log-slave-updates=true
gtid-mode=on
enforce-gtid-consistency=true
master-info-repository=TABLE
relay-log-info-repository=TABLE
sync-master-info=1
slave-parallel-workers=2
binlog-checksum=CRC32
master-verify-checksum=1
slave-sql-verify-checksum=1
binlog-rows-query-log_events=1
server-id=1
report-port=3306
port=3306
datadir=/mydata/data
socket=/tmp/mysql.sock
report-host=master.test.com

5. 为mysql提供sysv服务脚本并启动服务
[root@web mysql]# cp support-files/mysql.server /etc/init.d/mysqld #复制sysv脚本
[root@web mysql]# chkconfig --add mysqld
[root@web mysql]# chkconfig mysqld on #开机自启动
[root@web mysql]# chkconfig mysqld --list
mysqld          0:off  1:off  2:on    3:on    4:on    5:on    6:off
[root@web mysql]# service mysqld start
Starting MySQL.... SUCCESS!
[root@web mysql]# netstat -ntulp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address              Foreign Address            State      PID/Programname
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                  LISTEN      990/sshd
tcp        0      0 127.0.0.1:25                0.0.0.0:*                  LISTEN      1066/master
tcp        0      0 :::80                      :::*                        LISTEN      37120/httpd
tcp        0      0 :::22                      :::*                        LISTEN      990/sshd
tcp        0      0 ::1:25                      :::*                        LISTEN      1066/master
tcp        0      0 :::3306                    :::*                        LISTEN      37924/mysqld#mysql启动成功
udp        0      0 0.0.0.0:68                  0.0.0.0:*                              890/dhclient

6. 输出mysql的man手册至man命令的查找路径
[root@web mysql]# vim /etc/man.config
MANPATH /usr/local/mysql/man#增加这一行

7. 输出mysql的头文件至系统头文件路径/usr/include
[root@web mysql]# ln -sv /usr/local/mysql/include/ /usr/include/mysql #输出mysql的头文件至系统头文件
`/usr/include/mysql' -> `/usr/local/mysql/include/'
[root@web mysql]# cd /usr/include/mysql/

8. 输出mysql的库文件给系统库查找路径
[root@web mysql]# vim /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
#直接新建编辑/etc/ld.so.conf.d/mysql.conf文件,把mysql的库文件路径添加进去就可以了
[root@web mysql]# ldconfig �v# 让系统重新读取库文件
/usr/local/mysql/lib:
libtcmalloc_minimal.so.0 -> libtcmalloc_minimal.so (changed)
libmysqlclient.so.18 -> libmysqlclient_r.so.18.0.0
/usr/lib64/mysql:
libmysqlclient.so.16 -> libmysqlclient.so.16.0.0
libmysqlclient_r.so.16 -> libmysqlclient_r.so.16.0

9. 修改PATH环境变量,让系统可以直接使用mysql的相关命令
[root@web mysql]# vim /etc/profile.d/mysql.sh  #添加环境变量(与添加httpd是一样的)
exportPATH=$PATH:/usr/local/mysql/bin
[root@web mysql]# source /etc/profile #重新读取一下环境变量

10. 测试并连接mysql
[root@web mysql]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection idis 1
Server version: 5.6.12-log MySQL Community Server (GPL)
Copyright (c) 2000, 2013, Oracle and/orits affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/orits
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;'or '\h'forhelp. Type '\c'to clearthe current input statement.
mysql> SHOW DATABASES;
+--------------------+
| Database          |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test|
+--------------------+
4 rows inset(0.02 sec)
mysql>
| mysql              |
| performance_schema |
| test              |
+--------------------+
4 rows in set (0.03 sec)

mysql>
说明,大家可以看到通用二进制包的安装与配置和源码包的安装配置有很多是相同的,但我这边还是全部写出来了,保证博文的完整性!通用二进制包安装并测试完成,下面我们简单说一下RPM包的安装!
RPM包安装
说明,RPM包安装我想大家都会我在这里就不过多说明,到这里mysql安装讲解全部结束!


你可能感兴趣的:(二进制,源代码,include,优缺点,通用)