Home > Database > Mysql Tutorial > body text

RHEL Server 6.3下MySQL5.5.25a源码安装

WBOY
Release: 2016-06-07 17:17:38
Original
800 people have browsed it

RHEL Server 6.3下MySQL5.5.25a源码安装

OS:RHEL Server 6.3

MySQL:mysql-5.5.25a.tar.gz

相关依赖包:

ncurses-5.9.tar.gz

bison-2.5.tar.gz

安装MySQL

一、安装依赖包

(1)ncurses

[root@test ~]# cd /data1/lnmp/

[root@test lnmp]# tar -xzf ncurses-5.9.tar.gz

[root@test lnmp]# cd ncurses-5.9

[root@test ncurses-5.9]# ./configure

[root@test ncurses-5.9]# make && make install

(2)bison

[root@test lnmp]# tar -xzf bison-2.5.tar.gz

[root@test lnmp]# cd bison-2.5

[root@test bison-2.5]# ./configure

[root@test bison-2.5]# make && make install

二、安装用于编译 MySQL 的 cmake 工具

[root@test lnmp]# tar -xzf cmake-2.8.8.tar.gz

[root@test lnmp]# cd cmake-2.8.8

[root@test cmake-2.8.8]#./configure

[root@test cmake-2.8.8]#make && make install

三、源码安装 MySQL

(1)建立运行MySQL的用户和组

[root@test ~]# groupadd mysql

[root@test ~]# useradd -M -g mysql -s /sbin/nologin mysql

(2)建立相关目录

[root@test ~]# mkdir /usr/local/mysql

[root@test ~]# mkdir /var/lock/mysql

[root@test ~]# mkdir /var/run/mysql

[root@test ~]# mkdir /var/log/mysql

[root@test ~]# mkdir /data1/mysql_db

 

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

注意:

之所以要创建/var/lock/mysql和/var/run/mysql目录,这是因为mysql server是用mysql这个用户启动的。而/var/lock//var/run/这两个目录只有root才有写的权限,所以mysql这个用户不能在其中建立mysql.lock和mysql.pid文件。所以要在/var/lock//var/run/这两个目录分别再建立一个目录,例如:mysql。并把这个目录所有者和群组改为mysql这具用户和群组。此种做法也是为了便于管理,例如把日志存放在/var/log/mysql/,日志只会在这一个目录下轮转,,便于管理;#chown mysql:mysql /var/run/mysql/ /var/lock/mysql/ /var/log/mysql/

错误:

如果数据库 /data1/mysql_db/ 目录权限设置不正确,在启动 mysql 时可能会出现下面的错误。

[root@test ~]# tail /var/log/mysql.log

120713 17:15:21 mysqld_safe Starting mysqld daemon with databases from /data1/mysql_db

 /usr/local/mysql/bin/mysqld: File './mysql-bin.index' not found (Errcode: 13)

120713 17:15:21 [ERROR] Aborting


120713 17:15:21 [Note] /usr/local/mysql/bin/mysqld: Shutdown complete


120713 17:15:21 mysqld_safe mysqld from pid file /var/run/mysql/mysql.pid ended

[root@test ~]#


解决方法:

这里是用mysql这个用户启动数据库的。所以要把建立的数据库目录 /data1/mysql_db/ 的所有者和群组更改为mysql。


[root@test ~]#chown -R mysql:mysql /data1/mysql_db/


这一步最好在初始化完数据库时再做一下。初始化完成后,可以先检查这个目录下的新建立的文件和目录的权限是否正确,如果正确则不用再做这一步了。


为了安全可以指定用户 mysql 初始化数据库:

#./mysql_install_db --user=mysql \

--defaults-file=/etc/my.cnf \

--basedir=/usr/local/mysql/ \

--datadir=/data1/mysql_db

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

(3)源码安装 MySQL

[root@test ~]# cd /data1/lnmp/

[root@test lnmp]# tar -xzf mysql-5.5.25a.tar.gz

[root@test lnmp]# cd mysql-5.5.25a

[root@test mysql-5.5.25a]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \


-DSYSCONFDIR=/etc \


-DINSTALL_MANDIR=/usr/share/man \


-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock \

-DMYSQL_DATADIR=/data1/mysql_db \

-DEXTRA_CHARSETS=all \

-DDEFAULT_CHARSET=utf8 \

-DWITH_READLINE=ON

-DWITH_SSL=system \

-DWITH_DEBUG=0 \

-DWITH_PARTITION_STORAGE_ENGINE=1 \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_ARCHIVE_STORAGE_ENGINE=1 \

-DWITH_FEDERATED_STORAGE_ENGINE=1 \ 

-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \

-DINSTALL_LAYOUT=STANDALONE \

-DENABLED_LOCAL_INFILE=1 \

-DENABLED_PROFILING=1 \

-DMYSQL_MAINTAINER_MODE=0 \

-DWITH_EMBEDDED_SERVER=1 \

-DMYSQL_TCP_PORT=3306 \

-DMYSQL_USER=mysql

[root@test mysql-5.5.25a]#make

[root@test mysql-5.5.25a]#make install

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

[root@test mysql-5.5.25a]# cmake . LH

注意:

在编译的时候有可能会出现以下错误。

-- 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:268 (MYSQL_CHECK_READLINE)

 

-- Configuring incomplete, errors occurred!

错误原因:

这是因为没有安装curses library的原因,如果是


解决方法:

[root@test mysql-5.5.25a]# yum install ncurses-devel #或源码安装

[root@test mysql-5.5.25a]# rm -rf CMakeCache.txt    #删除CMakeCache.txt文件

[root@test mysql-5.5.25a]# cmake .  #再重新编译,即可!

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

(4)

[root@test mysql-5.5.25a]# cp support-files/my-huge.cnf /etc/my.cnf

[root@test mysql-5.5.25a]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld


[root@test mysql-5.5.25a]# chmod 755 /etc/rc.d/init.d/mysqld


[root@test mysql-5.5.25a]# echo "export PATH=$PATH:/usr/local/mysql/bin" >> /ect/profile

[root@test mysql-5.5.25a]# source /etc/profile


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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template