1、关闭防火墙

service iptables stop

chkconfig iptables off

 

setenforce 0

vi /etc/selinux/config

SELINUX=permissive

 

 

 

2、配置sysctl.conf

主要配置shmmax共享内存类参数,最大设置为50%-60%系统物理内存。

3、检查操作系统是否安装了mysql

如果需要删除mysql,可以执行:

rpm -e mysql-libs-5.1.66-2.el6_3.x86_64

如果因为依赖删不掉,则可以用yum来删:

yum remove mysql-libs-5.1.66-2.el6_3.x86_64

 

 

 

再检查一下mysql的安装包是否存在:

 

 

 

4、下载mysql源码包

[root@mysql yum.repos.d]# mkdir /u01

[root@mysql yum.repos.d]# cd /u01

[root@mysql u01]#

配置ftp,上传源码

a、配置源http://blog.csdn.net/kadwf123/article/details/78231694

b、配置ftp服务

yum -y install vsftpd

chkconfig vsftpd on

cd /etc/vsftpd

vi ftpusers

把root用户注释掉

vi user_list

把root用户注释掉

5、添加用户和组

groupadd mysql

创建mysql组

 

创建mysql用户

 

 

设置mysql用户的密码:

 

 

 

6、配置mysql环境变量

su - mysql

vi .bash_profile

修改path变量:

 

 

 

使之生效

 

 

 

7、创建目录及授权

[root@mysql vsftpd]# mkdir -p /u01/my3306/data

[root@mysql vsftpd]# mkdir -p /u01/my3306/log/iblog

[root@mysql vsftpd]# mkdir -p /u01/my3306/log/binlog

[root@mysql vsftpd]# mkdir -p /u01/my3306/run

[root@mysql vsftpd]# mkdir -p /u01/my3306/tmp

[root@mysql vsftpd]# 

 

 

 

授权:

[root@mysql vsftpd]# chown -R mysql:mysql /u01/my3306

[root@mysql vsftpd]# chmod -R 755 /u01/my3306

[root@mysql vsftpd]# 

 

 

 

8、解压mysql5.6

tar -xzvf mysql-5.6.39.tar.gz

 

 

 

9、配置yum源,安装cmake

yum install -y  cmake gcc gcc-c++ ncurses-devel bison zlib libxml openssl openssl-devel ncurses

安装上面的所有的依赖包,确保安装成功。

10、编译并安装

进入mysql源码包的解压目录

 

 

 

执行如下命令:

cmake \

-DCMAKE_INSTALL_PREFIX=/u01/my3306 \

-DINSTALL_DATADIR=/u01/my3306/data  \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DEXTRA_CHARSETS=all \

-DWITH_SSL=yes \

-DWITH_EMBEDDED_SERVER=1 \

-DENABLED_LOCAL_INFILE=1 \

-DWITH_MYISAM_STORAGE_ENGINE=1 \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_ARCHIVE_STORAGE_ENGINE=1 \

-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \

-DWITH_FEDERATED_STORAGE_ENGINE=1 \

-DWITH_PARTITION_STORAGE_ENGINE=1 \

-DMYSQL_UNIX_ADDR=/u01/my3306/run/mysql.sock \

-DMYSQL_TCP_PORT=3306 \

-DENABLED_LOCAL_INFILE=1 \

-DSYSCONFDIR=/etc \

-DWITH_READLINE=on

失败,老是报错:
CMake Error at cmake/ssl.cmake:167 (FILE):
  file STRINGS file
  "/u01/mysql-5.6.39/OPENSSL_INCLUDE_DIR-NOTFOUND/openssl/opensslv.h" cannot
  be read.
Call Stack (most recent call first):
  CMakeLists.txt:446 (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:247 (MESSAGE):
  Cannot find appropriate system libraries for SSL.  Make sure you've
  specified a supported SSL version.  Consult the documentation for WITH_SSL
  alternatives
Call Stack (most recent call first):
  CMakeLists.txt:446 (MYSQL_CHECK_SSL)


-- Using cmake version 2.8.12.2
-- Not building NDB
-- Library mysqlclient depends on OSLIBS -lpthread;m;rt;dl
-- Googletest was not found. gtest-based unit tests will be disabled. You can run cmake . -DENABLE_DOWNLOADS=1 to automatically download and build required components from source.
-- If you are inside a firewall, you may need to use an https proxy: export https_proxy=http://example.com:80
-- Library mysqlserver depends on OSLIBS -lpthread;m;rt;crypt;dl
-- Skipping deb packaging on unsupported platform .
-- CMAKE_BUILD_TYPE: RelWithDebInfo
-- COMPILE_DEFINITIONS: HAVE_CONFIG_H
-- CMAKE_C_FLAGS:  -Wall -Wextra -Wformat-security -Wvla -Wwrite-strings -Wdeclaration-after-statement
-- CMAKE_CXX_FLAGS:  -Wall -Wextra -Wformat-security -Wvla -Woverloaded-virtual -Wno-unused-parameter
-- CMAKE_C_FLAGS_RELWITHDEBINFO: -O3 -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -DDBUG_OFF
-- CMAKE_CXX_FLAGS_RELWITHDEBINFO: -O3 -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -DDBUG_OFF
-- Configuring incomplete, errors occurred!
See also "/u01/mysql-5.6.39/CMakeFiles/CMakeOutput.log".
See also "/u01/mysql-5.6.39/CMakeFiles/CMakeError.log".
[root@mysql mysql-5.6.39]# ll
注意这个地方:

 

怀疑是openssl导致的,但是我的openssl检查却装了。

 

 

 

 

没办法,下一个在装,然后指定:

-DOPENSSL_ROOT_DIR=/usr/local/openssl \

-DOPENSSL_LIBRARIES=/usr/local/openssl/lib \

这两项。完整命令如下:

cmake \

-DCMAKE_INSTALL_PREFIX=/u01/my3306 \

-DMYSQL_DATADIR=/u01/my3306/data  \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DEXTRA_CHARSETS=all \

-DWITH_SSL=yes \

-DWITH_EMBEDDED_SERVER=1 \

-DENABLED_LOCAL_INFILE=1 \

-DWITH_MYISAM_STORAGE_ENGINE=1 \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_ARCHIVE_STORAGE_ENGINE=1 \

-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \

-DWITH_FEDERATED_STORAGE_ENGINE=1 \

-DWITH_PARTITION_STORAGE_ENGINE=1 \

-DMYSQL_UNIX_ADDR=/u01/my3306/run/mysql.sock \

-DMYSQL_TCP_PORT=3306 \

-DENABLED_LOCAL_INFILE=1 \

-DSYSCONFDIR=/etc \

-DOPENSSL_ROOT_DIR=/usr/local/openssl \

-DOPENSSL_LIBRARIES=/usr/local/openssl/lib \

-DWITH_READLINE=on

下面说明使用二进制包安装openssl:

a、下载新版openssl安装包:https://www.openssl.org/source/ 

b、把安装文件openssl-1.0.2n.tar.gz上传到虚拟机。

c、tar -xzvf openssl-1.0.2n.tar.gz

d、cd openssl-1.0.2n

e、执行命令:./config --prefix=/usr/local/openssl -fPIC no-gost no-shared no-zlib

注意,如果不指定 -fPIC 选项,可能会出现如下错误:

Scanning dependencies of target clientlib
[ 82%] Building C object libmysql/CMakeFiles/clientlib.dir/get_password.c.o
[ 83%] Building C object libmysql/CMakeFiles/clientlib.dir/libmysql.c.o
[ 83%] Building C object libmysql/CMakeFiles/clientlib.dir/errmsg.c.o
[ 83%] Building C object libmysql/CMakeFiles/clientlib.dir/__/sql-common/client.c.o
[ 83%] Building C object libmysql/CMakeFiles/clientlib.dir/__/sql-common/my_time.c.o
[ 83%] Building C object libmysql/CMakeFiles/clientlib.dir/__/sql-common/client_plugin.c.o
[ 83%] Building CXX object libmysql/CMakeFiles/clientlib.dir/__/sql-common/client_authentication.cc.o
[ 83%] Building CXX object libmysql/CMakeFiles/clientlib.dir/__/sql/net_serv.cc.o
[ 83%] Building C object libmysql/CMakeFiles/clientlib.dir/__/sql-common/pack.c.o
[ 83%] Building C object libmysql/CMakeFiles/clientlib.dir/__/sql/password.c.o
Linking CXX static library libclientlib.a
[ 83%] Built target clientlib
Scanning dependencies of target libmysql
[ 83%] Building CXX object libmysql/CMakeFiles/libmysql.dir/libmysql_exports_file.cc.o
Linking CXX shared library libmysqlclient.so
/usr/bin/ld: /usr/local/openssl/lib/libssl.a(t1_srvr.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/local/openssl/lib/libssl.a: could not read symbols: Bad value
collect2: ld 返回 1
make[2]: *** [libmysql/libmysqlclient.so.18.1.0] 错误 1
make[1]: *** [libmysql/CMakeFiles/libmysql.dir/all] 错误 2
make: *** [all] 错误 2
[root@mysql mysql-5.6.39]# 

主要注意:

 

f、执行命令:make depend

 

g、执行命令:./config -t

h、执行make,编译openssl。注意执行make要有gcc编译器。

i、执行make install进行安装。

j、执行cd /usr/local

k、执行ldd /usr/local/openssl/bin/openssl

 

l、配置环境变量:PATH=/usr/local/openssl/bin:$PATH:$HOME/bin

m、使环境变量生效source /root/.bash_profile

n、which openssl

 

 

 

o、查看版本:openssl version

 

 

 

然后就可以执行cmake成功了:

 

 

 

多次cmake需要删除CMakeCache.txt 文件

cd /u01/mysql-5.6.39/

rm -f CMakeCache.txt

下面直接进行make编译:

make

这条命令执行的时间比较长,前台一直会输出make的进度:

 

 

 

然后还需要执行make install安装到指定目录/u01/my3306中。

 

 

 

11、mysql参数配置

把my.cnf参数文件直接传到/u01/my3306/目录下面去。

也可以直接建一个my.cnf,内容如下:

[client]
port=3306
socket=/u01/my3306/run/mysql.sock

[mysql]
#pid-file=/u01/my3306/run/mysqld.pid

[mysqld]
autocommit=1
general_log=off
explicit_defaults_for_timestamp=true

# system
basedir=/u01/my3306
datadir=/u01/my3306/data
max_allowed_packet=1g
max_connections=3000
max_user_connections=2800
open_files_limit=65535
pid-file=/u01/my3306/run/mysqld.pid
port=3306
server_id=101
skip_name_resolve=ON
socket=/u01/my3306/run/mysql.sock
tmpdir=/u01/my3306/tmp

#binlog
log_bin=/u01/my3306/log/binlog/binlog
binlog_cache_size=32768
binlog_format=row
expire_logs_days=7
log_slave_updates=ON
max_binlog_cache_size=2147483648
max_binlog_size=524288000
sync_binlog=100

#logging
log_error=/u01/my3306/log/error.log
slow_query_log_file=/u01/my3306/log/slow.log
log_queries_not_using_indexes=0
slow_query_log=1
log_slave_updates=ON
log_slow_admin_statements=1
long_query_time=1

#relay
relay_log=/u01/my3306/log/relaylog
relay_log_index=/u01/my3306/log/relay.index
relay_log_info_file=/u01/my3306/log/relay-log.info

#slave
slave_load_tmpdir=/u01/my3306/tmp
slave_skip_errors=OFF


#innodb
innodb_data_home_dir=/u01/my3306/log/iblog
innodb_log_group_home_dir=/u01/my3306/log/iblog
innodb_adaptive_flushing=ON
innodb_adaptive_hash_index=ON
innodb_autoinc_lock_mode=1
innodb_buffer_pool_instances=8

#default
innodb_change_buffering=inserts
innodb_checksums=ON
innodb_buffer_pool_size= 128M
innodb_data_file_path=ibdata1:32M;ibdata2:16M:autoextend
innodb_doublewrite=ON
innodb_file_format=Barracuda
innodb_file_per_table=ON
innodb_flush_log_at_trx_commit=1
innodb_flush_method=O_DIRECT
innodb_io_capacity=1000
innodb_lock_wait_timeout=10
innodb_log_buffer_size=67108864
innodb_log_file_size=1048576000
innodb_log_files_in_group=4
innodb_max_dirty_pages_pct=60
innodb_open_files=60000
innodb_purge_threads=1
innodb_read_io_threads=4
innodb_stats_on_metadata=OFF
innodb_support_xa=ON
innodb_use_native_aio=OFF
innodb_write_io_threads=10

[mysqld_safe]
datadir=/u01/my3306/data

然后把/u01/my3306目录属主改成mysql

chown -R mysql:mysql /u01/my3306

12、初始化mysql脚本

cd /u01/my3306/scripts

 

./mysql_install_db --help

./scripts/mysql_install_db --defaults-file=/u01/my3306/my.cnf --datadir=/u01/my3306/data --user=mysql

 

 

 

注意此命令要在/u01/my3306目录下执行。

 

13、启动mysql

[mysql@mysql bin]$ pwd

/u01/my3306/bin

[mysql@mysql bin]$ ./mysqld_safe --defaults-file=/u01/my3306/my.cnf --user=mysql &

 

 

 

检查mysql进程:

 

 

 

14、登录mysql

登录mysql

Logo

更多推荐