一、编写目的

MySQL是一个开放源码的小型关联式数据库管理系统,开发者为瑞典MySQL AB公司。目前MySQL被广泛地应用在Internet上的中小型网站中。由于其体积小、速度快、总体拥有成本低,尤其是开放源码这一特点,许多中小型网站为了降低网站总体拥有成本而选择了MySQL作为网站数据库。

本文档为操作人员提供mysql-5.6安装指导。

第二章mysql安装

1、安装所需软件包

[root@host1 ~]#yum install -y gccgcc-c++ libtool autoconf automake imake libxml2-devel expat-devel ncurses-develcmake bison

2、创建需要的用户和目录

[root@host1~]#groupadd mysql                                                   //创建mysql用户组


[root@host1~]#useradd -g mysql mysql                                     //创建mysql用户


[root@host1~]#mkdir -p /data/mysql/rs                                    //创建数据存放目录


[root@host1~]#mkdir -p /usr/local/mysqld                               //创建mysql安装目录


[root@host1~]#chown mysql:mysql -R /data/mysql/             //修改目录的所属组和用户为mysql


[root@host1~]#chown mysql:mysql -R /usr/local/mysqld

3、编译并安装mysql

[root@host1~]#tar zxvf mysql-5.6.10.tar.gz                    //解压


[root@host1~]#cd mysql-5.6.10


[root@host1 mysql-5.6.10]# cmake .-DCMAKE_INSTALL_PREFIX=/usr/local/mysqld -DMYSQL_DATADIR=/data/mysql/rs-DMYSQL_UNIX_ADDR=/data/mysql/rs/mysqld.sock -DWITH_INNOBASE_STORAGE_ENGINE=1-DENABLED_LOCAL_INFILE=1-DDEFAULT_CHARSET=utf8 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1-DWITH_PARTITION_STORAGE_ENGINE=1 -DDEFAULT_COLLATION=utf8_general_ci-DMYSQL_USER=mysql -DEXTRA_CHARSETS=all -DMYSQL_TCP_PORT=3106

                                                                                                               //cmake参数进行编译安装

[root@localhostmysql-5.6.10]# make


[root@localhostmysql-5.6.10]# make install

4、修改配置文件,启动数据库

[root@localhost mysqld]# cpsupport-files/my-default.cnf ./my.cnf       //拷贝参数文件


[root@localhost mysqld]# cpsupport-files/mysql.server ./server


[root@localhost mysqld]#./scripts/mysql_install_db --user=mysql --ldata=/data/mysql/rs

                                                                                                                                  //初始化数据库

[root@host1 mysqld]#vi server


替换conf值为/usr/local/mysqld/my.cnf

conf=/etc/my.cnf ----->conf=/usr/local/mysqld/my.cnf                              //修改参数文件路径

[root@localhost mysqld]# ./server start                                                                 //启动mysql服务

Starting MySQL.                                           [  OK  ]

5、进入数据库,修改密码

[root@localhostmysqld]# /usr/local/mysqld/bin/mysql    //第一次进入数据库

Welcometo the MySQL monitor.  Commands end with; or \g.

YourMySQL connection id is 1

Serverversion: 5.6.10 Source distribution

Copyright(c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracleis 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>update mysql.user set Password=password("123456") whereUser="root" and Host="localhost";                                        //修改root用户登录密码

QueryOK, 1 row affected (0.00 sec)

Rowsmatched: 1  Changed: 1  Warnings: 0


mysql>flush privileges;                                //更新授权表

QueryOK, 0 rows affected (0.01 sec)


mysql>









附录1:关于make时出现警告官网说明

http://bugs.mysql.com/bug.php?id=47609


[29 Nov 2010 8:26] Alexander Nozdrin

These warnings are now in trunk (5.6).


sql/sql_select produces the following warnings duringbuild on

'linux x86_64 werror':


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

/export/home/pb2/build/sb_0-2577370-1290600489.98/mysql-5.6.1-m5/sql/sql_select.cc:6829:warning: 'loose_scan_opt.Loose_scan_opt::bound_sj_equalities' may be useduninitialized in this function /export/home/pb2/build/sb_0-2577370-1290600489.98/mysql-5.6.1-m5/sql/sql_select.cc:6829:warning: 'loose_scan_opt.Loose_scan_opt::quick_max_loose_keypart' may be useduninitialized in this function/export/home/pb2/build/sb_0-2577370-1290600489.98/mysql-5.6.1-m5/sql/sql_select.cc:6829:warning: 'loose_scan_opt.Loose_scan_opt::best_loose_scan_key' may be useduninitialized in this function/export/home/pb2/build/sb_0-2577370-1290600489.98/mysql-5.6.1-m5/sql/sql_select.cc:6829:warning: 'loose_scan_opt.Loose_scan_opt::best_loose_scan_records' may be useduninitialized in this function/export/home/pb2/build/sb_0-2577370-1290600489.98/mysql-5.6.1-m5/sql/sql_select.cc:6829:warning: 'loose_scan_opt.Loose_scan_opt::best_max_loose_keypart' may be useduninitialized in this function/export/home/pb2/build/sb_0-2577370-1290600489.98/mysql-5.6.1-m5/sql/sql_select.cc:6829:warning: 'loose_scan_opt.Loose_scan_opt::best_loose_scan_start_key' may be useduninitialized in this function

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


The thing is that those variables are left uninitializedintentionally.

Here is what a comment in sql_select.cc says:


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

We needn't initialize:

bound_sj_equalities - protected by try_loosescan

quick_max_loose_keypart - protected byquick_uses_applicable_index

best_loose_scan_key - protected by best_loose_scan_cost!= DBL_MAX

best_loose_scan_records - same

best_max_loose_keypart - same

best_loose_scan_start_key - same

Not initializing them causes compiler warnings, but usingUNINIT_VAR()

would cause a 2% CPU time loss in a 20-table plan search.

So, until UNINIT_VAR(x) doesn't do x=0 for any C++ code,it's not used

here.

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































附录2cmake参数对照

从mysql5.5起,mysql源码安装开始使用cmake。下面是 mysql 5.5 与以前的参数对照:

configure Command

CMake Command

./configure

cmake .

./configure --help

cmake . -LH or ccmake .


Parameter

configure Option

CMake Option

CMake Notes

Installation base directory

--prefix=/usr

-DCMAKE_INSTALL_PREFIX=/usr


mysqld directory

--libexecdir=/usr/sbin

-DINSTALL_SBINDIR=sbin

interpreted relative to  prefix

Data directory

--localstatedir=/var/lib/mysql

-DMYSQL_DATADIR=/var/lib/mysql


Config directory (for my.cnf)

--sysconfdir=/etc/mysql

-DSYSCONFDIR=/etc/mysql


Plugin directory

--with-plugindir=/usr/lib64/mysql/plugin

-DINSTALL_PLUGINDIR=lib64/mysql/plugin

interpreted relative to  prefix

Man page directory

--mandir=/usr/share/man

-DINSTALL_MANDIR=share/man

interpreted relative to  prefix

Shared-data directory

--sharedstatedir=/usr/share/mysql

-DINSTALL_SHAREDIR=share

this is where  aclocal/mysql.m4 should be installed

Library installation  directory

--libdir=/usr/lib64/mysql

-DINSTALL_LIBDIR=lib64/mysql

interpreted relative to  prefix

Header installation  directory

--includedir=/usr/include/mysql

-DINSTALL_INCLUDEDIR=include/mysql

interpreted relative to  prefix

Info doc directory

--infodir=/usr/share/info

-DINSTALL_INFODIR=share/info

interpreted relative to  prefix


Parameter

configure Option

CMake Option

CMake Notes

readline library

--with-readline

-DWITH_READLINE=1


SSL library

--with-ssl=/usr

-DWITH_SSL=system


zlib library

--with-zlib-dir=/usr

-DWITH_ZLIB=system


libwrap library

--without-libwrap

-DWITH_LIBWRAP=0



TCP/IP port number

--with-tcp-port-=3306

-DMYSQL_TCP_PORT=3306


UNIX socket file

--with-unix-socket-path=/tmp/mysqld.sock

-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock


Enable LOCAL for LOAD DATA

--enable-local-infile

-DENABLED_LOCAL_INFILE=1


Extra charsets

--with-extra-charsets=all

-DEXTRA_CHARSETS=all

default is "all"

Default charset

--with-charset=utf8

-DDEFAULT_CHARSET=utf8


Default collation

--with-collation=utf8_general_ci

-DDEFAULT_COLLATION=utf8_general_ci


Build the server

--with-server

none


Build the embedded server

--with-embedded-server

-DWITH_EMBEDDED_SERVER=1


libmysqld privilege control

--with-embedded-privilege-control

none

always enabled?

Install the documentation

--without-docs

none


Big tables

--with-big-tables,  --without-big-tables

none

tables are big by default

mysqld user

--with-mysqld-user=mysql

-DMYSQL_USER=mysql

mysql is the default

Debugging

--without-debug

-DWITH_DEBUG=0

default is debugging  disabled

GIS support

--with-geometry

none

always enabled?

Community features

--enable-community-features

none

always enabled

Profiling

--disable-profiling

-DENABLE_PROFILING=0

enabled by default

pstack

--without-pstack

none

pstack is removed

Assembler string functions

--enable-assembler

none


Build type

--build=x86_64-pc-linux-gnu

no equivalent

unneeded?

Cross-compile host

--host=x86_64-pc-linux-gnu

no equivalent

unneeded?

Client flag

--with-client-ldflags=-lstdc++

none

unneeded

Client flag

--enable-thread-safe-client

none

unneeded, clients are always  thread safe

Comment

--with-comment='string'

-DWITH_COMMENT='string'


Shared/static binaries

--enable-shared  --enable-static

none

there is only DISABLE_SHARED

Memory use

--with-low-memory

none

unneeded

1.命令语法:

重新编译时,需要清除旧的对象文件和缓存信息
 # make clean
 # rm -f  CMakeCache.txt

2.安装选项

CMAKE_INSTALL_PREFIX值是安装的基本目录,其他cmake选项值是不包括前缀,是相对路径名,绝对路径包括CMAKE_INSTALL_PREFIX路径。如-DINSTALL_SBINDIR=sbin的绝对路径是/usr/local/mysql/sbin
3.存储引擎选项
mysql存储引擎是插件式的,因此插件控制选项可以指定那个存储引擎安装。
configure编译插件选项--with-plugins=csv,myisam,myisammrg,heap,innobase,
archive,blackhole在cmake中没有直接对应的相同选项。对于csv,myisam,myisammrg,heap在cmake中是不需要明确指定存储引擎的名称,因为它们是强制性安装。

可以使用以下选择来安装innodb,archive,blackhole存储引擎
-DWITH_INNOBASE_STORAGE_ENGINE=1

-DWITH_ARCHIVE_STORAGE_ENGINE=1

-DWITH_BLACKHOLE_STORAGE_ENGINE=1

(1可以使用on代替)

如果既不是-DWITH_<ENGINE>_STORAGE_ENGINE 也不是 -DWITHOUT_<ENGINE>_STORAGE_ENGINE 来指定存储引擎,该存储引擎将安装成共享模块式的。如果不是共享模块式的将排除在外。共享模块安装时必须使用INSTALL PLUGIN语句或--plugin-load才可以使用。

4.其他选项
之前MySQL的编译选项大多数都支持。新旧版本之间的安装选项映射成大写字母,删除选项前面破折号,中间字符间的破折号替换成下划线。如:
 --with-debug => WITH_DEBUG=1

--with-embedded-server => WITH_EMBEDDED_SERVER

5.调试配置过程
使用configure编译完将生成config.log和config.status文件。
使用cmake编译完在CMakeFiles目录下生成CMakeError.log 和CMakeOutput.log文件。

编译参数参考:

BUILD_CONFIG  采用官方发行版一致的编译参数
CMAKE_BUILD_TYPE 指定产品编译说明信息   RelWithDebInf
CMAKE_INSTALL_PREFIX 指定MySQL安装路径  /usr/local/mysql
CPACK_MONOLITHIC_INSTALL是否建立单个安装包文件 OFF  5.5.7
DEFAULT_CHARSET  MYSQL 默认字符集 latin1   5.5.7
DEFAULT_COLLATION MYSQL 默认排序字符集  latin1_swedish_ci5.5.7
ENABLE_DEBUG_SYNC 是否启用同步调试功能  ON   5.5.7
ENABLE_DOWNLOADS 是否下载可选文件  OFF   5.5.7
ENABLE_DTRACE  是否包含 DTrace 支持     5.5.7
ENABLE_GCOV  是否包含 Gcov 支持    5.5.14
ENABLED_LOCAL_INFILE 是否启用本地 LOAD DATA INFILEOFF   5.5.7
ENABLED_PROFILING 是否启用代码查询分析  ON   5.5.7
INSTALL_BINDIR  MySQL 主执行文件目录 PREFIX/bin  5.5.7
INSTALL_DOCDIR  文档安装路径  PREFIX/docs  5.5.7
INSTALL_DOCREADMEDIR 自述文件目录  PREFIX   5.5.7
INSTALL_INCLUDEDIR 头文件目录  PREFIX/include  5.5.7
INSTALL_INFODIR  关于信息文件目录  PREFIX/docs 5.5.7
INSTALL_LAYOUT  选择预定义的安装  STANDALONE 5.5.7
INSTALL_LIBDIR  库文件目录   PREFIX/lib 5.5.7
INSTALL_MANDIR  手册页面目录  PREFIX/man  5.5.7
INSTALL_MYSQLSHAREDIR 共享数据目录  PREFIX/share  5.5.7
INSTALL_MYSQLTESTDIR mysql-test 目录  PREFIX/mysql-test 5.5.7
INSTALL_PLUGINDIR 插件目录   PREFIX/lib/plugin5.5.7
INSTALL_SBINDIR  服务器超级用户执行文件目录 PREFIX/bin 5.5.7
INSTALL_SCRIPTDIR 脚本目录   PREFIX/scripts 5.5.7
INSTALL_SHAREDIR aclocal/mysql.m4 安装目录PREFIX/share  5.5.7
INSTALL_SQLBENCHDIR sql-bench 性能测试工具目录PREFIX   5.5.7
INSTALL_SUPPORTFILESDIR 扩展支持文件目录 PREFIX/support-files 5.5.7
MYSQL_DATADIR  数据库存放目录     5.5.7
MYSQL_MAINTAINER_MODE 是否启用MySQL的维护环境  OFF   5.5.7
MYSQL_TCP_PORT  TCP/IP 端口号  3306   5.5.7
MYSQL_UNIX_ADDR  Unix Socket 套接字文件 /tmp/mysql.sock  5.5.7
SYSCONFDIR  选项配置文件目录     5.5.7
WITH_COMMENT  编译环境发表评论    5.5.7
WITH_DEBUG  是否包括调试支持  OFF   5.5.7
WITH_EMBEDDED_SERVER 是否要建立嵌入式服务器  OFF  5.5.7
WITH_xxx_STORAGE_ENGINE 静态编译xxx 存储引擎到服务器    5.5.7
WITH_EXTRA_CHARSETS 额外的字符集,包括  all  5.5.7
WITH_LIBWRAP  是否包括支持libwrap(TCP包装) OFF   5.5.7
WITH_READLINE  使用捆绑的readline  OFF  5.5.7
WITH_SSL  是否支持SSL  no   5.5.7
WITH_ZLIB  是否支持Zlib  system   5.5.7
WITHOUT_xxx_