MySQL源代码安装实录

  categories:mysql资料  tags:  author:

原创文章,转载请指明出处并保留原文url地址

Percona 为 MySQL 数据库服务器进行了改进,在功能和性能上较 MySQL 有着很显著的提升。该版本提升了在高负载情况下的 InnoDB 的性能、为 DBA 提供一些非常有用的性能诊断工具;另外有更多的参数和命令来控制服务器行为。

Percona Server 只包含 MySQL 的服务器版,并没有提供相应对 MySQL 的 Connector 和 GUI 工具进行改进。

Percona Server 使用了一些 google-mysql-tools, Proven Scaling, Open Query 对 MySQL 进行改造。

Percona 网址如下:http://www.percona.com/

下载地址:http://www.percona.com/downloads/

实验安装的mysql版本:

http://www.percona.com/redir/downloads/Percona-Server-5.5/Percona-Server-5.5.28-29.3/source/Percona-Server-5.5.28-rel29.3.tar.gz

一.linux环境准备

我们采用vmware软件安装linux系统进行实验,vmware软件到搜索引擎搜索并下载安装, linux软件可以到下面地址下载安装好的linux虚拟机, 然后在vmware中运行。

64-bit: centos-5.6-x86_64-server.zip, 456M
fast torrent download!, web download
md5sum: 2590006571f52ca00674d20d3b376672

解压缩下载后的虚拟机文件到一个硬盘空间比较大的硬盘分区中.

打开解压缩的文件目录

双击文件centos-5.5-x86_64-server.vmx,然后启动vmware虚拟机

登录系统

如下图, 启动后系统如下界面

wps_clip_image-11840[4][1]

用户点击鼠标左键后, 在登录页面可以输入用户名 :root

然后提示输入密码信息, 用户可以输入原始密码 :”thoughtpolice”(密码是双引号中内容)The root password for this image is “thoughtpolice”.

配置SecureCRT软件,

SecureCRT是一常见的linux终端软件,我们可以通过这个软件登录我们的虚拟机系统,完成各种操作,他的操作方法比直接在虚拟机上操作方便多了.软件的下载及安装大家自己去搜索及下载.

wps_clip_image-11382[4][1]

安装完成后, 启动软件, 然后点击

图1处 启动快速连接,

图2处 输入ip地址

图3处 输入用户名

二. MySQL安装

1. 源代码下载

登录linux系统, 输入下面命令下载mysql源代码

wget http://www.percona.com/redir/downloads/Percona-Server-5.5/Percona-Server-5.5.28-29.3/source/Percona-Server-5.5.28-rel29.3.tar.gz

wps_clip_image-27379[4][1]

2. 创建mysql的安装目录

mkdir -p /apps/mysql3306

wps_clip_image-21131[3][1]

3. 创建mysql帐号

[root@mysql01 ~]# useradd mysql

[root@mysql01 ~]# chown -R mysql:mysql /apps

[root@mysql01 ~]# ll /apps

total 4

drwxr-xr-x 2 mysql mysql 4096 Jan 17 22:18 mysql3306

wps_clip_image-1868[3][1]

4. 解压缩Mysql文件

输入如下命令进行解释压缩mysql源代码安装文件

tar xzvf Percona-Server-5.5.28-rel29.3.tar.gz

wps_clip_image-26720[4][1]

5. 进入MySQL源代码目录,准备编译

cd   Percona-Server-5.5.28-rel29.3

ll

wps_clip_image-16713[3][1]

6. 执行安装命令

cmake \

-DCMAKE_INSTALL_PREFIX=/apps/mysql3306 \

-DMYSQL_DATADIR=/apps/mysql3306/data \

-DMYSQL_TCP_PORT=3306  \

-DSYSCONFDIR=/apps/mysql3306 \

-DMYSQL_UNIX_ADDR=/apps/mysql3306/mysql.sock

显示结果如下

wps_clip_image-5005[3][1]

Linux系统中默认没有安装cmake软件,我们需要手动安装

下面是关于命令的解释部分, 解释采用命令后面添加注释的办法, 这个文本是不能执行的

cmake \  // 产生make的配置文件

-DCMAKE_INSTALL_PREFIX=/apps/mysql3306 \  // 设置mysql安装后主目录

-DMYSQL_DATADIR=/apps/mysql3306/data \     // 设置mysql的data目录

-DMYSQL_TCP_PORT=3306  \     // 设置mysql端口,多服务器安装需要

-DSYSCONFDIR=/apps/mysql3306 \  // 设置mysql默认配置文件路径,非常必要

-DMYSQL_UNIX_ADDR=/apps/mysql3306/mysql.sock  // 设置mysql的unix socket文件

上面配置主要是为在一个linux服务器中,安装多份mysql数据库软件做的配置工作。

7. 安装cmake软件

yum install cmake命令

wps_clip_image-20851[3][1]

输入y进行下载并安装

安装完成后, 再次运行

cmake \

-DCMAKE_INSTALL_PREFIX=/apps/mysql3306 \

-DMYSQL_DATADIR=/apps/mysql3306/data \

-DMYSQL_TCP_PORT=3306  \

-DSYSCONFDIR=/apps/mysql3306 \

-DMYSQL_UNIX_ADDR=/apps/mysql3306/mysql.sock

命令,如有如下信息

wps_clip_image-22170[4][1]

上面信息是 cmake没有找到 c语言的编译工具,需要安装gcc

8. 安装gcc

yum install gcc -y

wps_clip_image-13260[4][1]

-y 不在确认直接安装相关软件

重新运行cmake命令如下图

wps_clip_image-6836[3][1]

错误信息:

[root@mysql01 Percona-Server-5.5.28-rel29.3]# cmake \

> -DCMAKE_INSTALL_PREFIX=/apps/mysql3306 \

> -DMYSQL_DATADIR=/apps/mysql3306/data \

> -DMYSQL_TCP_PORT=3306  \

> -DSYSCONFDIR=/apps/mysql3306 \

> -DMYSQL_UNIX_ADDR=/apps/mysql3306/mysql.sock

— The C compiler identification is GNU

— The CXX compiler identification is unknown

— Check for working C compiler: /usr/bin/gcc

— Check for working C compiler: /usr/bin/gcc — works

— Detecting C compiler ABI info

— Detecting C compiler ABI info – done

CMake Error: your CXX compiler: “CMAKE_CXX_COMPILER-NOTFOUND” was not found.   Please set CMAKE_CXX_COMPILER to a valid compiler path or name.

— MySQL 5.5.28

— Packaging as: mysql-5.5.28-Linux-x86_64

— Could NOT find Threads  (missing:  Threads_FOUND)

— Could NOT find Threads  (missing:  Threads_FOUND)

— Check if the system is big endian

— Searching 16 bit integer

CMake Error at /usr/share/cmake/Modules/TestBigEndian.cmake:31 (MESSAGE):

no suitable type found

Call Stack (most recent call first):

configure.cmake:529 (TEST_BIG_ENDIAN)

CMakeLists.txt:267 (INCLUDE)

从错误信息中我们可以了解到 cmake没有找到 CXX文件的编译器, CXX其实就是C++文件的编译器,解决办法安装c++编译器

9. 安装c++软件

yum install gcc-c++ -y

wps_clip_image-23862[4][1]

安装完成后, 退出mysql源代码安装目录, 上一层, 删除当前的mysql源代码目录,重新执行cmake程序,如下:

145  cd ..

146  ls

147  rm -rf Percona-Server-5.5.28-rel29.3

148  tar xzvf Percona-Server-5.5.28-rel29.3.tar.gz

149  cd Percona-Server-5.5.28-rel29.3

150  cmake -DCMAKE_INSTALL_PREFIX=/apps/mysql3306 -DMYSQL_DATADIR=/apps/mysql3306/data -DMYSQL_TCP_PORT=3306  -DSYSCONFDIR=/apps/mysql3306 -DMYSQL_UNIX_ADDR=/apps/mysql3306/mysql.sock

执行结果如下:

wps_clip_image-6131[5][1]

错误信息:

— Check size of wctype_t – done

— Check size of wint_t

— Check size of wint_t – done

— Could NOT find Curses  (missing:  CURSES_LIBRARY CURSES_INCLUDE_PATH)

CMake Error at cmake/readline.cmake:83 (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:127 (FIND_CURSES)

cmake/readline.cmake:217 (MYSQL_USE_BUNDLED_LIBEDIT)

CMakeLists.txt:278 (MYSQL_CHECK_READLINE)

— Configuring incomplete, errors occurred!

通过错误信息可以了解到 cmake缺少CURSES_LIBRARY库

10. 安装ncurses-devel

yum install ncurses-devel -y

安装完成后,删除当前源代码,重新解压缩文件, 然后在次运行cmake如下:

125  cd ..

126  ls

127  rm -rf Percona-Server-5.5.28-rel29.3

128  tar Percona-Server-5.5.28-rel29.3.tar.gz

129  tar xzvf Percona-Server-5.5.28-rel29.3.tar.gz

130  ls

131  cd Percona-Server-5.5.28-rel29.3

132  ls

133  cmake -DCMAKE_INSTALL_PREFIX=/apps/mysql3306 -DMYSQL_DATADIR=/apps/mysql3306/data -DMYSQL_TCP_PORT=3306  -DSYSCONFDIR=/apps/mysql3306 -DMYSQL_UNIX_ADDR=/apps/mysql3306/mysql.sock

134  history

运行后结果如下(建议删除上一次编译过的文件, 否则有可能不会成功,并且编译后的信息可能是上一次的)

wps_clip_image-26910[4][1]

— Looking for getpwnam_r – found

— Looking for getgrgid_r

— Looking for getgrgid_r – found

Warning: Bison executable not found in PATH

CMake Error at cmake/bison.cmake:78 (MESSAGE):

Bison (GNU parser generator) is required to build MySQL.Please install

bison.

Call Stack (most recent call first):

sql/CMakeLists.txt:197 (RUN_BISON)

— Configuring incomplete, errors occurred!

我们需要安装bison

11. 安装bison

yum install bison -y

安装完成后,运行

cmake \

-DCMAKE_INSTALL_PREFIX=/apps/mysql3306 \

-DMYSQL_DATADIR=/apps/mysql3306/data \

-DMYSQL_TCP_PORT=3306  \

-DSYSCONFDIR=/apps/mysql3306 \

-DMYSQL_UNIX_ADDR=/apps/mysql3306/mysql.sock

命令产生mysql的make文件

若是出现错误,请删除当前解压缩后源代码,重新解压缩,然后在重新运行上次命令。

最后上述命令没有错误后, 我们可以运行下列命令来编译并安装mysql

make && make install

没有编译错误后安装成功。

然后执行下列命令, 来对mysql目录进行用户宿主的修改。

Chown -R mysql:mysql  /apps

12. 初始化数据库

进入mysql目录

cd /apps/mysql3306

从root帐号切换到mysql帐号

su – mysql

注意切换完成用户后需要重新进入mysql目录

cd /apps/mysql3306/

然后在mysql目录运行下列命令

./scripts/mysql_install_db –user=mysql –datadir=/apps/mysql3306/data

初始化mysql数据库

执行结果如下:

[mysql@mysql01 mysql3306]$

[mysql@mysql01 mysql3306]$ ./scripts/mysql_install_db –user=mysql –datadir=/apps/mysql3306/data

WARNING: The host ‘mysql01′ could not be looked up with resolveip.

This probably means that your libc libraries are not 100 % compatible

with this binary MySQL version. The MySQL daemon, mysqld, should work

normally with the exception that host name resolving will not work.

This means that you should use IP addresses instead of hostnames

when specifying MySQL privileges !

Installing MySQL system tables…

OK

Filling help tables…

OK

To start mysqld at boot time you have to copy

support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !

To do so, start the server, then issue the following commands:

./bin/mysqladmin -u root password ‘new-password’

./bin/mysqladmin -u root -h mysql01 password ‘new-password’

Alternatively you can run:

./bin/mysql_secure_installation

which will also give you the option of removing the test

databases and anonymous user created by default.  This is

strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:

cd . ; ./bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl

cd ./mysql-test ; perl mysql-test-run.pl

Please report any problems with the ./bin/mysqlbug script!

Percona recommends that all production deployments be protected with a support

contract (http://www.percona.com/mysql-suppport/) to ensure the highest uptime,

be eligible for hot fixes, and boost your team’s productivity.

13. 创建配置文件

cp support-files/my-medium.cnf  my.cnf

14. 启动数据库

./bin/mysqld_safe –defaults-file=/apps/mysql3306/my.cnf

15. 创建启动脚本

输入如下命令

vi startmyql.sh

在vi中输入如下文本

#!/bin/bash

# s.sh  启动本mysql进程

export MYSQL_HOME=/apps/mysql3306

nohup  ./bin/mysqld_safe –defaults-file=/apps/mysql3306/my.cnf >/dev/null 2>&1  &

保存退出后,输入如下命令,赋予脚本可执行权限

chmod a+x *.sh   // 全部 *.sh文件都具备可执行的权限了

这样以后我们就可以通过这个命令来启动mysql了

执行./startmyql.sh 启动mysql,如下图

wps_clip_image-6372[5][1]

16. 安装另外一份mysql数据库

切换到root帐号,然后删除当前解压缩的msyql源文件,进入目录。

wps_clip_image-26990[4][1]

解压缩mysql源文件,进入解压缩后的文件目录

~]# tar xzvf Percona-Server-5.5.28-rel29.3.tar.gz

……

[root@mysql01 ~]# ll

total 21960

-rw——-  1 root root     1126 Sep  6  2010 anaconda-ks.cfg

-rw-r–r–  1 root root    22433 Sep  6  2010 install.log

-rw-r–r–  1 root root     3974 Sep  6  2010 install.log.syslog

drwxr-xr-x 34 root root     4096 Jan 18 02:08 Percona-Server-5.5.28-rel29.3

-rw-r–r–  1 root root 22408844 Jan  7 01:43 Percona-Server-5.5.28-rel29.3.tar.gz

[root@mysql01 ~]#

[root@mysql01 ~]# cd Percona-Server-5.5.28-rel29.3

[root@mysql01 Percona-Server-5.5.28-rel29.3]# pwd

/root/Percona-Server-5.5.28-rel29.3

[root@mysql01 Percona-Server-5.5.28-rel29.3]#

进入目录后运行下面命令

cmake \

-DCMAKE_INSTALL_PREFIX=/apps/mysql3307 \

-DMYSQL_DATADIR=/apps/mysql3307/data \

-DMYSQL_TCP_PORT=3307  \

-DSYSCONFDIR=/apps/mysql3307 \

-DMYSQL_UNIX_ADDR=/apps/mysql3307/mysql.sock

运行 make && make install 命令编译并安装mysql

运行下列命令更改宿主 chown -R mysql:mysql  /apps

然后切换到mysql帐号  su – msyql

最后 进入mysql目录

cd /apps/mysql3307

执行12到15的步骤, 注意里面 将 3306替换成3307 等,最后就可以完成另外一个mysql服务器的安装工作。



快乐成长 每天进步一点点