创建mysql2用户

[root@localhost ~]# useradd mysql2

[root@localhost ~]# su - mysql2

[mysql2@localhost ~]$ ls


安装MySQL需要用到cmake,下载

[mysql2@localhost ~]$ wget http://www.cmake.org/files/v2.8/cmake-2.8.10.1.tar.gz

--2014-11-17 10:13:00--  http://www.cmake.org/files/v2.8/cmake-2.8.10.1.tar.gz

正在解析主机 www.cmake.org... 66.194.253.19

正在连接 www.cmake.org|66.194.253.19|:80... 已连接。

已发出 HTTP 请求,正在等待回应... 200 OK

长度:5767574 (5.5M) [application/x-gzip]

正在保存至: “cmake-2.8.10.1.tar.gz”

[=======================================================================================>   ] 5,625,101   89.4K/s eta(英国中部时98% [========================================================================================>  ] 5,658,681   92.0K/s eta(英国中部时98% [========================================================================================>  ] 5,689,341   93.7K/s eta(英国中部时99% [=========================================================================================> ] 5,723,245   93.6K/s eta(英国中部时99% [=========================================================================================> ] 5,759,421   96.4K/s eta(英国中部时100%[==========================================================================================>] 5,767,574   96.7K/s   in 84s     


2014-11-17 10:14:30 (67.2 KB/s) - 已保存 “cmake-2.8.10.1.tar.gz” [5767574/5767574])


复制下载的MySQL软件,并修改权限

[root@localhost mysql]# cp mysql-5.6.21.tar.gz /home/mysql2/

[root@localhost mysql2]# chown -R mysql2.mysql2 mysql-5.6.21.tar.gz 


安装cmake

[mysql2@localhost ~]$ tar xvfz cmake-2.8.10.1.tar.gz 

cmake-2.8.10.1/.gitattributes

cmake-2.8.10.1/.hooks-config.bash

cmake-2.8.10.1/bootstrap

cmake-2.8.10.1/ChangeLog.manual


[root@localhost mysql2]# cd cmake-2.8.10.1

[root@localhost cmake-2.8.10.1]# ls -l

总用量 2980

-rwxr-xr-x   1 mysql2 mysql2   54084 11月  7 2012 bootstrap

-rw-r--r--   1 mysql2 mysql2  190107 11月  7 2012 ChangeLog.manual

-rw-r--r--   1 mysql2 mysql2 2603523 11月  7 2012 ChangeLog.txt

-rw-r--r--   1 mysql2 mysql2    5395 11月  7 2012 CMakeCPack.cmake

-rw-r--r--   1 mysql2 mysql2    2536 11月  7 2012 CMakeCPackOptions.cmake.in

-rw-r--r--   1 mysql2 mysql2     153 11月  7 2012 CMakeGraphVizOptions.cmake

-rw-r--r--   1 mysql2 mysql2   24542 11月  7 2012 CMakeLists.txt

-rw-r--r--   1 mysql2 mysql2    4481 11月  7 2012 CMakeLogo.gif

-rw-r--r--   1 mysql2 mysql2     796 11月  7 2012 cmake_uninstall.cmake.in

-rw-r--r--   1 mysql2 mysql2    2204 11月  7 2012 CompileFlags.cmake

-rwxr-xr-x   1 mysql2 mysql2      99 11月  7 2012 configure

-rw-r--r--   1 mysql2 mysql2    2637 11月  7 2012 Copyright.txt

-rw-r--r--   1 mysql2 mysql2    1050 11月  7 2012 CTestConfig.cmake

-rw-r--r--   1 mysql2 mysql2    3258 11月  7 2012 CTestCustom.cmake.in

-rw-r--r--   1 mysql2 mysql2     145 11月  7 2012 CTestCustom.ctest.in

-rw-r--r--   1 mysql2 mysql2     809 11月  7 2012 DartConfig.cmake

-rw-r--r--   1 mysql2 mysql2    4144 11月  7 2012 DartLocal.conf.in

drwxrwxr-x   3 mysql2 mysql2    4096 11月 17 10:17 Docs

-rw-r--r--   1 mysql2 mysql2   28046 11月  7 2012 doxygen.config

drwxrwxr-x   4 mysql2 mysql2    4096 11月 17 10:17 Example

drwxrwxr-x   9 mysql2 mysql2   20480 11月 17 10:17 Modules

-rw-r--r--   1 mysql2 mysql2    1946 11月  7 2012 Readme.txt

drwxrwxr-x   7 mysql2 mysql2   32768 11月 17 10:17 Source

drwxrwxr-x   2 mysql2 mysql2    4096 11月 17 10:17 Templates

drwxrwxr-x 150 mysql2 mysql2    4096 11月 17 10:17 Tests

drwxrwxr-x  15 mysql2 mysql2    4096 11月 17 10:17 Utilities

[root@localhost cmake-2.8.10.1]# ./configure && make && make install

---------------------------------------------

CMake 2.8.10.1, Copyright 2000-2012 Kitware, Inc.

Found GNU toolchain

C compiler on this system is: gcc 

C++ compiler on this system is: g++ 

Makefile processor on this system is: gmake

g++ is GNU compiler

g++ has setenv

g++ has unsetenv

g++ does not have environ in stdlib.h

g++ has STL in std:: namespace

g++ has ANSI streams

g++ has streams in std:: namespace



安装MySQL

[mysql2@localhost ~]# mkdir /mysql2

[mysql2@localhost ~]# cd /mysql2

[mysql2@localhost ~]# chown -R mysql2.mysql2 /mysql2

[mysql2@localhost ~]$ cd /mysql2/

[mysql2@localhost mysql2]$ mkdir etc init.d data log tmp binlog

[mysql2@localhost ~]$ tar xvfz mysql-5.6.21.tar.gz 

mysql-5.6.21/

mysql-5.6.21/BUILD/

mysql-5.6.21/BUILD/build_mccge.sh

mysql-5.6.21/BUILD/compile-pentium-gcov

mysql-5.6.21/BUILD/compile-pentium

mysql-5.6.21/BUILD/compile-pentium-debug-max-no-ndb

[mysql2@localhost mysql-5.6.21]$ cmake -DCMAKE_INSTALL_PREFIX=/mysql2 \

> -DSYSCONFDIR=/mysql2/etc \

> -Dmysql_DATADIR=/mysql2/data \

> -Dmysql_TCP_PORT=3307 \

> -DWITH_PARTITION_STORAGE_ENGINE\

> -DWITH_ARCHIVE_STORAGE_ENGINE=1\

> -DWITHOUT_FEDERATED_STORAGE_ENGINE=1\

> -Dmysql_UNIX_ADDR=/mysql2/tmp/mysql2d.sock \

> -Dmysql_USER=mysql2 \

> -DEXTRA_CHARSETS=all \

> -DWITH_READLINE=1 \

> -DWITH_SSL=system \

> -DWITH_EMBEDDED_SERVER=1 \

> -DENABLED_LOCAL_INFILE=1 \

> -DWITH_INNOBASE_STORAGE_ENGINE=1


-- Running cmake version 2.8.10.1

-- The C compiler identification is GNU 4.4.7

-- The CXX compiler identification is GNU 4.4.7

-- Check for working C compiler: /usr/bin/cc

-- Check for working C compiler: /usr/bin/cc -- works

-- Detecting C compiler ABI info

-- Detecting C compiler ABI info - done

-- Check for working CXX compiler: /usr/bin/c++

-- Check for working CXX compiler: /usr/bin/c++ -- works

-- Detecting CXX compiler ABI info

-- Detecting CXX compiler ABI info - done


[mysql2@localhost mysql-5.6.21]$make && make install

Scanning dependencies of target INFO_BIN

[  0%] Built target INFO_BIN

Scanning dependencies of target INFO_SRC

[  0%] Built target INFO_SRC

Scanning dependencies of target abi_check

[  0%] Built target abi_check

Scanning dependencies of target zlib

[  0%] Building C object zlib/CMakeFiles/zlib.dir/adler32.c.o

[  0%] Building C object zlib/CMakeFiles/zlib.dir/compress.c.o

[  0%] Building C object zlib/CMakeFiles/zlib.dir/crc32.c.o

[  0%] Building C object zlib/CMakeFiles/zlib.dir/deflate.c.o

[  0%] Building C object zlib/CMakeFiles/zlib.dir/gzio.c.o

[  0%] Building C object zlib/CMakeFiles/zlib.dir/infback.c.o

[  0%] Building C object zlib/CMakeFiles/zlib.dir/inffast.c.o

[  0%] Building C object zlib/CMakeFiles/zlib.dir/inflate.c.o


[mysql2@localhost mysql-5.6.21]$ cd support-files/

[mysql2@localhost support-files]$ cp my-default.cnf /mysql2/etc/my.cnf

[mysql2@localhost support-files]$ cp mysql.server /mysql2/init.d/mysql

[mysql2@localhost ~]$ cd /mysql2/

[mysql2@localhost mysql2]$ ls

bin      data  etc      init.d          lib  man         README   share      support-files

COPYING  docs  include  INSTALL-BINARY  log  mysql-test  scripts  sql-bench

[mysql2@localhost mysql2]$ chmod 755 scripts/mysql_install_db 

[mysql2@localhost mysql2]$ chmod +x init.d/mysql 


初始化MySQL系统表

[mysql2@localhost mysql2]$ ./scripts/mysql_install_db --user=mysql2 --basedir=/mysql2 --datadir=/mysql2/data

Installing MySQL system tables...2014-11-17 11:04:07 0 [Warning] Ignoring user change to 'mysql2' because the user was set to 'mysql' earlier on the command line

2014-11-17 11:04:07 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2014-11-17 11:04:07 5185 [Note] InnoDB: Using atomics to ref count buffer pool pages

2014-11-17 11:04:07 5185 [Note] InnoDB: The InnoDB memory heap is disabled

2014-11-17 11:04:07 5185 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins

2014-11-17 11:04:07 5185 [Note] InnoDB: Memory barrier is not used

2014-11-17 11:04:07 5185 [Note] InnoDB: Compressed tables use zlib 1.2.3

2014-11-17 11:04:07 5185 [Note] InnoDB: Using Linux native AIO

2014-11-17 11:04:07 5185 [Note] InnoDB: Using CPU crc32 instructions

2014-11-17 11:04:07 5185 [Note] InnoDB: Initializing buffer pool, size = 128.0M

2014-11-17 11:04:07 5185 [Note] InnoDB: Completed initialization of buffer pool

2014-11-17 11:04:08 5185 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!

2014-11-17 11:04:08 5185 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB

2014-11-17 11:04:08 5185 [Note] InnoDB: Database physically writes the file full: wait...

2014-11-17 11:04:08 5185 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB

2014-11-17 11:04:08 5185 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB


编辑/mysql2/ect/my.cnf文件[mysqld]下,添加如下内容:

[mysqld]

pid-file = /mysql2/data/mysql2.pid

log-error = /mysql2/log/error.log

general_log = ON

general_log_file = /mysql2/log/mysql2.log

tmpdir = /tmp

basedir = /mysql2

datadir = /mysql2/data

autocommit=0

port=3307

[mysqld_safe]

socket = /mysql2/tmp/mysql2.sock


启动MySQL:

[mysql2@localhost mysql2]$ ./init.d/mysql start

Starting MySQL SUCCESS! 


查看进程

[mysql2@localhost mysql2]$ ps -ef | grep mysql2

root     20349  8196  0 15:01 pts/2    00:00:00 su - mysql2

mysql2   20350 20349  0 15:01 pts/2    00:00:00 -bash

root     22509  8250  0 17:54 pts/3    00:00:00 su - mysql2

mysql2   22510 22509  0 17:54 pts/3    00:00:00 -bash

mysql2   24443     1  0 18:12 pts/3    00:00:00 /bin/sh /mysql2/bin/mysqld_safe --datadir=/mysql2/data --pid-file=/mysql2/data/mysql2.pid

mysql2   24812 24443  7 18:12 pts/3    00:00:00 /mysql2/bin/mysqld --basedir=/mysql2 --datadir=/mysql2/data --plugin-dir=/mysql2/lib/plugin --log-error=/mysql2/log/error.log --pid-file=/mysql2/data/mysql2.pid --socket=/mysql2/tmp/mysql2.sock --port=3307

mysql2   24836 22510  0 18:12 pts/3    00:00:00 ps -ef

mysql2   24837 22510  0 18:12 pts/3    00:00:00 grep mysql2

[mysql2@localhost mysql2]$ 


查看端口监听:

[mysql2@localhost mysql2]$ netstat -antp | grep 3307

(Not all processes could be identified, non-owned process info

will not be shown, you would have to be root to see it all.)

tcp        0      0 :::3307                     :::*                        LISTEN      24812/mysqld        

[mysql2@localhost mysql2]$ 


登陆MySQL,因为这是一台机器安装的第二个MySQL所以需要指定host和socket。

[mysql2@localhost mysql2]$ ./bin/mysql -u root -p -h localhost --socket=/mysql2/tmp/mysql2.sock

Enter password: 

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.6.21-log Source distribution


Copyright (c) 2000, 2014, 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              |

| performance_schema |

| test               |

+--------------------+

4 rows in set (0.00 sec)


mysql> exit

Bye

[mysql2@localhost mysql2]$