您的位置:首页 > 运维架构 > Linux

在最小化安装的centos6.5中编译安装最新mysql-5.6.21并做基本优化

2017-02-17 11:04 726 查看
安装mysql之前的一些准备工作:1、建立一个存放软件源码包的目录,一般都存放在
/usr/local/src
cd /usr/local/src
wget https://www.cmake.org/files/v3.0/cmake-3.0.2.tar.gz wget https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.21.tar.gz
2、selinux可能会致使编译安装失败,我们先禁用它,永久禁用,需要重启生效
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
3、检查系统是否安装有mysql?
rpm -qa | grep mysql
特殊情况:
[root@c65mini ~]# rpm -qa|grep mysql
mysql-libs-5.1.73-3.el6_5.x86_64
[root@c65mini ~]# rpm -e mysql-libs-5.1.73-3.el6_5.x86_64
error: Failed dependencies:
libmysqlclient.so.16()(64bit) is needed by (installed) postfix-2:2.6.6-6.el6_5.x86_64
libmysqlclient.so.16(libmysqlclient_16)(64bit) is needed by (installed) postfix-2:2.6.6-6.el6_5.x86_64
mysql-libs is needed by (installed) postfix-2:2.6.6-6.el6_5.x86_64
这就是yum安装的弊端之处,依赖关系很多,因此这个
mysql-libs-5.1.73-3.el6_5.x86_64
库,不建议卸载,留着就可以了。如果卸载可能会导致postfix无法正常工作。4、有?就卸载之
#普通删除模式
rpm -e mysql
#强力删除模式,如果使用上面命令删除时,提示有依赖的其它文件,则用该命令可以对其进行强力删除
rpm -e --nodeps mysql
5、按照标准需要给mysql创建所属用户和用户组
#创建群组
groupadd mysql
#创建一个用户,不允许登陆和不创主目录
useradd -s /sbin/nologin -g mysql -M mysql
#检查创建用户
tail -1 /etc/passwd
开始安装mysql1、首先先安装cmake!MySQL从5.5版本开始,通过
./configure
进行编译配置方式已经被取消,取而代之的是cmake工具。 因此,我们首先要在系统中源码编译安装cmake工具。
tar zxvf cmake-3.0.2.tar.gz
cd cmake-3.0.2
./configure
make
make install
cd ..
可能会有错误提示:
Error when bootstrapping CMake:
Cannot find appropriate C compiler on this system.
Please specify one using environment variable CC.
See cmake_bootstrap.log for compilers attempted
解决方法:
#安装GCC
yum install gcc gcc-c++
2、安装mysql
tar zxvf mysql-5.6.21.tar.gz
cd mysql-5.6.21
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DMYSQL_USER=mysql \
-DWITH_DEBUG=0 \
-DWITH_ZLIB=system \
-DWITH_SSL=system
make && make install
可能会出现以下错误提示:
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
OPENSSL_INCLUDE_DIR
used as include directory in directory /usr/local/src/mysql-5.6.21/CMakeFiles/CMakeTmp

CMake Error: Internal CMake error, TryCompile configure of cmake failed
-- Check size of wchar_t - failed
-- Check size of wctype_t
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
OPENSSL_INCLUDE_DIR
used as include directory in directory /usr/local/src/mysql-5.6.21/CMakeFiles/CMakeTmp

CMake Error: Internal CMake error, TryCompile configure of cmake failed
-- Check size of wctype_t - failed
-- Check size of wint_t
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
OPENSSL_INCLUDE_DIR
used as include directory in directory /usr/local/src/mysql-5.6.21/CMakeFiles/CMakeTmp

CMake Error: Internal CMake error, TryCompile configure of cmake failed
-- Check size of wint_t - failed
-- 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:427 (MYSQL_CHECK_EDITLINE)

-- Configuring incomplete, errors occurred!
从上面的错误中我们可以很清楚的看到缺少两个依赖包,我们用yum安装一下即可!
yum install –y openssl openssl-devel ncurses ncurses-devel
再次一次运行上面的cmake以及后面的参数又报错:
[root@c65mini mysql-5.6.21]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_USER=mysql -DWITH_DEBUG=0 -DWITH_SSL=system -DWITH_ZLIB=system
-- Running cmake version 3.0.2
-- MySQL 5.6.21
-- Packaging as: mysql-5.6.21-Linux-x86_64
-- HAVE_VISIBILITY_HIDDEN
-- OPENSSL_INCLUDE_DIR = /usr/include
-- OPENSSL_LIBRARY = /usr/lib64/libssl.so
-- CRYPTO_LIBRARY = /usr/lib64/libcrypto.so
-- OPENSSL_MAJOR_VERSION = 1
CMake Error at cmake/ssl.cmake:234 (MESSAGE):
Cannot find appropriate system libraries for SSL.  Use WITH_SSL=bundled to
enable SSL support
Call Stack (most recent call first):
CMakeLists.txt:425 (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:427 (MYSQL_CHECK_EDITLINE)

-- Configuring incomplete, errors occurred!
See also "/usr/local/src/mysql-5.6.21/CMakeFiles/CMakeOutput.log".
See also "/usr/local/src/mysql-5.6.21/CMakeFiles/CMakeError.log".
这里是因为,我们在多次运行cmake有个文件我们需要删除,删除当前目录下CMakeCache.txt文件并重新编译,再次运行cmake命令就会正常!
rm  -rf CMakeCache.txt
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_USER=mysql -DWITH_DEBUG=0 -DWITH_SSL=system -DWITH_ZLIB=system
也有可能会出现错误提示
-- Googlemock 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.
可以在编译的参数后面加上:-DENABLE_DOWNLOADS=1让之自动下载,但是国内网络访问不了Google所以!解决方法:1、修改hosts让改主机能访问Google,你的懂得
curl https://tx.txthinking.com/fuckGFW.py | sudo python
2、也可以换个地址下载,到 /usr/local/src/mysql-5.6.21/source_downloads 目录下
wget --no-check-certificate https://pkgs.fedoraproject.org/repo/pkgs/gmock/gmock-1.6.0.zip/f547f47321ca88d3965ca2efdcc2a3c1/gmock-1.6.0.zip[/code]然后继续运行camake 以及后面的参数。然后发现又有错误提示:
Warning: Bison executable not found in PATH
解决方法:
yum install bison
再次运行没有发现任何错误
[root@c65mini mysql-5.6.21]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_USER=mysql -DWITH_DEBUG=0 -DWITH_SSL=system -DENABLE_DOWNLOADS=1
-- Running cmake version 3.0.2
-- MySQL 5.6.21
-- Packaging as: mysql-5.6.21-Linux-x86_64
-- HAVE_VISIBILITY_HIDDEN
-- OPENSSL_INCLUDE_DIR = /usr/include
-- OPENSSL_LIBRARY = /usr/lib64/libssl.so
-- CRYPTO_LIBRARY = /usr/lib64/libcrypto.so
-- OPENSSL_MAJOR_VERSION = 1
-- SSL_LIBRARIES = /usr/lib64/libssl.so;/usr/lib64/libcrypto.so;dl
-- Using cmake version 3.0.2
-- Not building NDB
-- Library mysqlclient depends on OSLIBS -lpthread;m;rt;/usr/lib64/libssl.so;/usr/lib64/libcrypto.so;dl
-- GMOCK_SOURCE_DIR:/usr/local/src/mysql-5.6.21/source_downloads/gmock-1.6.0
-- GTEST_LIBRARIES:gmock;gtest
-- Library mysqlserver depends on OSLIBS -lpthread;m;rt;/usr/lib64/libssl.so;/usr/lib64/libcrypto.so;dl;crypt
-- Configuring done
-- Generating done
-- Build files have been written to: /usr/local/src/mysql-5.6.21
然后一路顺利
make &&  make install
总结:要完整的安装mysql,其依赖关系用yum来解决的有
yum install gcc gcc-c++ openssl openssl-devel ncurses ncurses-devel bison
编译选项说明指定安装文件的安装路径时常用的选项
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql ----指定残可安装路径(默认的就是/usr/local/mysql)
-DMYSQL_DATADIR=/usr/local/mysql/data ----mysql的数据文件路径
-DSYSCONFDIR=/etc ----配置文件路径
编译过程中启用其它存储引擎时指令
-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=/var/lib/mysql/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 ----性能分析功能是否启用
mysql的服务脚本
#拷贝脚本
cp support-files/mysql.server /etc/init.d/mysqld
#赋予权限
chmod +x /etc/init.d/mysqld
#增加至sysV服务
chkconfig --add mysqld
#开机自启动
chkconfig mysqld on
#拷贝脚本
cp support-files/mysql.server /etc/init.d/mysqld
#赋予权限
chmod +x /etc/init.d/mysqld
#增加至sysV服务
chkconfig --add mysqld
#开机自启动
chkconfig mysqld on
MySQL 5.6.8开始,就不在分发my.cnf等配置的demo,因此需要手动复制
cd support-files/
如果还有my.cnf请备份
mv /etc/my.cnf /etc/my.cnf.bak
如果愿意也可以复制配置文件到etc下
cp my-default.cnf /etc/my.cnf
cd support-files/
如果还有my.cnf请备份
mv /etc/my.cnf /etc/my.cnf.bak
如果愿意也可以复制配置文件到etc下
cp my-default.cnf /etc/my.cnf
my.cnf的配置文件的默认读取顺序为:
FILE NAME(上面的优先)PURPOSE
/etc/my.cnfGlobal options
/etc/mysql/my.cnfGlobal options
SYSCONFDIR/my.cnfGlobal options
$MYSQL_HOME/my.cnfServer-specific options
defaults-extra-fileThe file specified with –defaults-extra-file=path, if any
~/.my.cnfUser-specific options
~/.mylogin.cnfLogin path options
修改/usr/local/mysql权限
chmod +w /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql
初始化mysql数据库
/usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
启动mysql数据库启动MySQL
service mysqld start
或者
/etc/init.d/mysql start
运行mysql安全工具:mysql_secure_installation#进入mysql安装目录
cd /usr/local/mysql
bin/mysql_secure_installation
详细过程:
[root@c65mini]# cd /usr/local/mysql/
[root@c65mini mysql]# bin/mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] y   			<---是否设定root密码,当然设置了,输入Y回车
New password:  							<---输入root密码,并回车,输入的过程中不会有任何显示
Re-enter new password: 					<---再次输入root密码,并回车,输入的过程中不会有任何显示
Password updated successfully!
Reloading privilege tables..
... Success!

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y 				<---是否删除匿名用户,删除,输入Y回车
... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n  			<---是否删禁止root用户远程登录
... skipping.

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y  <---是否删除测试数据库test,删除,输入Y回车
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y            <---刷新权限,输入Y回车
... Success!

All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

Cleaning up...
一些mysql安装的收尾工作1、设置全局变量方便输入mysql命令进行数据库管理修改/etc/profile文件
vi /etc/profile
在文件末尾添加
PATH=/usr/local/mysql/bin:$PATH
export PATH
重新读取环境变量
source /etc/profile
2、 输出mysql的man手册到man命令的查找路径
vim /etc/man.config
#新增一行
MANPATH /usr/local/mysql/man
3、输出mysql的库文件
vim /etc/ld.so.conf.d/mysql-x86_64.conf
#新增一行
/usr/local/mysql/lib/
查看mysql库文件
[root@c65mini mysql]# ldconfig -v | grep mysql
ldconfig: /etc/ld.so.conf.d/kernel-2.6.32-431.el6.x86_64.conf:6: duplicate hwcap 1 nosegneg
/usr/lib64/mysql:
libmysqlclient.so.16 -> libmysqlclient.so.16.0.0
libmysqlclient_r.so.16 -> libmysqlclient_r.so.16.0.0
/usr/local/mysql/lib:
libmysqlclient.so.18 -> libmysqlclient_r.so.18.1.0
4、输出mysql的头文件到系统头文件
[root@c65mini mysql]# ln -sv /usr/local/mysql/include/ /usr/include/mysql
"/usr/include/mysql" -> "/usr/local/mysql/include/"
[root@c65mini mysql]# cd /usr/include/mysql/
[root@c65mini mysql]# ls
big_endian.h                 my_dbug.h           mysql_version.h
byte_order_generic.h         my_dir.h            my_sys.h
byte_order_generic_x86_64.h  my_getopt.h         my_xml.h
byte_order_generic_x86.h     my_global.h         plugin_audit.h
decimal.h                    my_list.h           plugin_ftparser.h
errmsg.h                     my_net.h            plugin.h
keycache.h                   my_pthread.h        plugin_validate_password.h
little_endian.h              mysql               sql_common.h
m_ctype.h                    mysql_com.h         sql_state.h
m_string.h                   mysql_com_server.h  sslopt-case.h
my_alloc.h                   mysqld_ername.h     sslopt-longopts.h
my_attribute.h               mysqld_error.h      sslopt-vars.h
my_byteorder.h               mysql_embed.h       typelib.h
my_compiler.h                mysql.h
my_config.h                  mysql_time.h
验证安装
[root@c65mini mysql]# lsof -i:3306
COMMAND   PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
mysqld  56783 mysql   10u  IPv6 180460      0t0  TCP *:mysql (LISTEN)
用mysql的root账号登陆
mysql -u root -p
查看有哪些用户
select user,host from mysql.user;
利用一个强大mysql优化工具来做一些细节参数调优介绍:https://github.com/major/MySQLTuner-perl下载后运行
wget https://mysqltuner.pl/ -O mysqltuner.pl
perl mysqltuner.pl
根据提示,会做出一些参数需要来调整的。就一一写入my.cnf中。工具只是一方面,更多的需要根据实际机器性能做出一些经验性的判断!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mysql Failed local