CentOS 6.4 64Bit 编译安装Mysql 5.6.11源码包
1、实验环境:
OS:CentOS 6.464Bit
Mem:8G
CPU:Intel(R) Xeon(R) 5110
DB:Mysql 5.6.11 (在mysql官网下载5.6.11的版本)
2、安装编译工具、设置iptables、关闭SElinux
#安装gcc编译器和Mysql依赖关系包
[root@DB1 /]#yum -y install gcc gcc-c++ ncurses-devel
#设置Iptables
[root@DB1 /]#vim/etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp--dport 3306 -j ACCEPT
#关闭Selinux
[root@DB1 ~]# setenforce 0 #临时关闭
#永久关闭SElinux 修改标红的配置文件
[root@DB1 ~]# vim /etc/sysconfig/selinux
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing -SELinux security policy is enforced.
# permissive - SELinux prints warningsinstead of enforcing.
# disabled -SELinux is fully disabled.
SELINUX=disabled
# SELINUXTYPE= type of policy in use. Possible values are:
# targeted - Only targeted network daemons are protected.
# strict - FullSELinux protection.
SELINUXTYPE=targeted
3、下载源码(安装Mysql需要的编译工具)
wgethttp://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.11.tar.gz/from/http://mysql.he.net/
wgethttp://wwwNaNake.org/files/v2.8/cmake-2.8.4.tar.gz
wget http://ftp.gnu.org/gnu/bison/bison-2.5.tar.gz
4、安装cmake和bison
[root@DB1 soft]# tar zxvfcmake-2.8.4.tar.gz -C /usr/local/src/
[root@DB1 soft]# cd /usr/local/src/cmake-2.8.4/
[root@DB1 cmake-2.8.4]#./bootstrap && make && make install
…………………………………………默认安装到/usr/local/bin………………….
[root@DB1 cmake-2.8.4]# ll /usr/local/bin/cmake
-rwxr-xr-x 1 root root 8309168 2012-08-13/usr/local/bin/cmake
[root@DB1 cmake-2.8.4]#tar zxvf /root/soft/bison-2.5.tar.gz �CC /usr/local/src
[root@DB1 cmake-2.8.4]#cd ../ bison-2.5/
[root@DB1 bison-2.5] ./configure && make&& make install
注:CMake是一个比make更高级的编译配置工具,它可以根据不同平台、不同的编译器,生成相应的Makefile或者vcproj项目。
通过编写CMakeLists.txt,可以控制生成的Makefile,从而控制编译过程。CMake自动生成的Makefile不仅可以通过make命令构建项目生成目标文件,还支持安装(make install)、测试安装的程序是否能正确执行(make test,或者ctest)、生成当前平台的安装包(make package)、生成源码包(make package_source)、产生Dashboard显示数据并上传等高级功能,只要在CMakeLists.txt中简单配置,就可以完成很多复杂的功能,包括写测试用例。
如果有嵌套目录,子目录下可以有自己的CMakeLists.txt。
总之,CMake是一个非常强大的编译自动配置工具,支持各种平台,KDE也是用它编译的,感兴趣的可以试用一下。
注:根据一系列规则来生成一个可以分析文本文件的结构的程序的程序,Bison是一个替代Yacc(Yet AnotherCompiler Compiler) 的语法分析程序生成器。(至于在Mysql安装过程中具体的作用,我还没高明白)
5、创建Mysql用户和组
[root@DB1 soft]# groupadd mysql
[root@DB1 soft]# useradd -r -g mysql mysql
6、解压并编译安装Mysql
[root@DB1 bison-2.5]cd /root/soft
[root@DB1 soft]# tar zxvf mysql-5.6.11.tar.gz -C/usr/local/src/
[root@DB1 soft]# cd /usr/local/src/mysql-5.6.11/
[root@DB1 mysql-5.6.11]# cmake-DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/tmp/mysql.sock-DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci-DWITH_EXTRA_CHARSETS=all -DWITH_MYISAM_STORAGE_ENGINE=1-DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1-DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1-DMYSQL_DATADIR=/usr/loacl/mysql/data -DMYSQL_USER=mysql
[root@DB1 mysql-5.6.11]#make
……………或者可以使用:make �Cj CPU核心数替代make,可以加快编译速度……………
[root@DB1 mysql-5.6.11]#makeinstall
-------------------------默认情况下是安装在/usr/local/mysql
[root@DB1 mysql-5.6.11]# ll/usr/local/mysql/
总计 76
drwxr-xr-x 2 root root 4096 05-07 12:52 bin
-rw-r--r-- 1 root root 17987 04-05 20:27 COPYING
drwxr-xr-x 3 root root 4096 05-07 12:52 data
drwxr-xr-x 2 root root 4096 05-07 12:52 docs
drwxr-xr-x 3 root root 4096 05-07 12:52 include
-rw-r--r-- 1 root root 7468 04-05 20:27 INSTALL-BINARY
drwxr-xr-x 3 root root 4096 05-07 12:52 lib
drwxr-xr-x 4 root root 4096 05-07 12:52 man
drwxr-xr-x 10 root root 4096 05-07 12:52 mysql-test
-rw-r--r-- 1 root root 2552 04-05 20:27 README
drwxr-xr-x 2 root root 4096 05-07 12:52 scripts
drwxr-xr-x 28 root root 4096 05-07 12:52 share
drwxr-xr-x 4 root root 4096 05-07 12:52 sql-bench
drwxr-xr-x 3 root root 4096 05-07 12:52 support-files
7、配置Mysql后期环境
[root@DB1 scripts]# vim /etc/profile #设置环境变量
新追加如下内容:
PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
export PATH
#执行初始化配置脚本,创建系统自带的数据库和表以及my.cnf配置文件。
[root@DB1 scripts]#/usr/local/mysql/scripts/mysql_install_db--user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data
#拷贝Mysql启动脚本到/etc/init.d下
[root@DB1 scripts]# cp /usr/local/mysql/support-files/mysql.server/etc/init.d/mysqld
#添加到开及启动项,并设置开机启动Mysql
[root@DB1 scripts]#chkconfig --add mysqld
[root@DB1 scripts]#chkconfigmysqld on
#编辑Mysql配置文件
[root@DB1 scripts]#vim /etc/my.cnf
[mysqld]
datadir =/usr/local/mysql/data
basedir = /usr/local/mysql
socket = /tmp/mysql.sock
user=mysql
port = 3306
# server_id = .....
# socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-linksis recommended to prevent assorted security risks
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[root@DB1scripts]#/etc/init.d/mysqld start
#修改mysql root用户登录密码:
[root@DB1 bin]# /usr/local/mysql/bin/mysql #登录Mysql
Welcome to the MySQLmonitor. Commands end with ; or \g.
Your MySQL connection id is3
Server version: 5.6.11Source distribution
Copyright (c) 2000, 2013,Oracle and/or its affiliates. All rights reserved.
Oracle is a registeredtrademark of Oracle Corporation and/or its
affiliates. Other names maybe trademarks of their respective
owners.
Type 'help;' or '\h' forhelp. Type '\c' to clear the current input statement.
mysql> use mysql; #跳转到Mysql数据库
Reading table informationfor completion of table and column names
You can turn off thisfeature to get a quicker startup with -A
Database changed
mysql> update mysql.userset password=PASSWORD('11qq```') where user='root'; #更新root用户密码为11qq```
Query OK, 4 rows affected(0.01 sec)
Rows matched: 4 Changed: 4 Warnings: 0
mysql> flush privileges; #强制刷新所有策略生效
Query OK, 0 rows affected(0.00 sec)
mysql> quit #退出Mysql
Bye
#修改修改MySQL用户root(不是系统的root!)的密码,禁止root远程连接(防止破解密码),移除test数据库和匿名用户,强烈建议生产服务器使用:
[root@DB1 scripts]#/usr/local/mysql/bin/mysql_secure_installation
NOTE: RUNNING ALL PARTS OFTHIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQLto secure it, we'll need the current
password for the rootuser. If you've just installed MySQL,and
you haven't set the rootpassword yet, the password will be blank,
so you should just pressenter here.
Enter current password forroot (enter for none): #输入当然Mysql root用户密码
OK, successfully usedpassword, moving on...
Setting the root passwordensures that nobody can log into the MySQL
root user without the properauthorisation.
You already have a rootpassword set, so you can safely answer 'n'.
Change the root password?[Y/n] y #是否修改Mysql root用户密码,Y是同意修改Mysql root用户密码
New password: # 输入新密码
Re-enter new password: # 再次输入新密码
Password updatedsuccessfully!
Reloading privilege tables..
... Success!
By default, a MySQLinstallation has an anonymous user, allowing anyone
to log into MySQL withouthaving to have a user account created for
them. This is intended only for testing, and tomake the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users?[Y/n] y #是否删除Mysql root匿名用户,Y是同意删除Mysql 匿名用户
... Success!
Normally, root should onlybe allowed to connect from 'localhost'. This
ensures that someone cannotguess at the root password from the network.
Disallow root loginremotely? [Y/n] y #是否拒绝Mysql root用户远程连接到数据库,Y是同意Mysql root用户远程连接到数据库
... Success!
By default, MySQL comes witha database named 'test' that anyone can
access. This is also intended only for testing, andshould be removed
before moving into aproduction environment.
Remove test database andaccess to it? [Y/n] y #是否删除Mysql 默认的测试数据库(test数据库),Y是同意删除Mysql测试数据库
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilegetables will ensure that all changes made so far
will take effectimmediately.
Reload privilege tables now?[Y/n] y #是否加载,让所有配置立刻生效。
... Success!
All done! If you've completed all of the above steps,your MySQL
installation should now besecure.
Thanks for using MySQL!
Cleaning up...
至此,Mysql只是安装成功。数据库及系统都是最新版本,如有 错误的地方请指出,笔者尽快修改,多谢各位朋友多多支持,
后期有时间会研究一下Mysql 调优、冗余、集群............