首页
登录 | 注册

MySQL源码安装

一、文章说明

最近接触到mysql数据库,因此闲来研究一下,今天演示一下用源码安装mysql,如果使用rpm包安装的话个人感觉挺简单的。

《MySQL权威指南(原书第2版)》清晰中文扫描版 PDF http://www.linuxidc.com/Linux/2014-03/98821.htm

源码包编译安装MySQL 5.6脚本 http://www.linuxidc.com/Linux/2014-04/99991.htm

环境说明:

操作系统:rhel 5.4 x86

Mysql版本:mysql-5.5.22

二、安装cmake(mysql5.5以后是通过cmake来编译的)

在mysql5.5之前的话直接编辑就可以,而在5.5以后需要通过cmake来编译,在附录中介绍一下直接编译。

下载cmake-2.8.4.tar.gz,本人是在度娘搜的。

[[email protected] ~]# tar -zxvf cmake-2.8.4.tar.gz
[[email protected] ~]# cd cmake-2.8.4
[[email protected] cmake-2.8.4]# ./configure --prefix=/usr/local/cmake
----在这里可以使用# gmake && make install
[[email protected] cmake-2.8.4]# make [[email protected] cmake-2.8.4]# make install

备注:configure需要执行编译到目录。
三、创建mysql的安装目录及数据库存放目录

[[email protected] ~]# mkdir -p /opt/mysql5.5
[[email protected] ~]# mkdir -p /opt/mysql5.5/data 

四、创建mysql用户及用户组

[[email protected] ~]# groupadd mysql
[[email protected] ~]# useradd -r -g mysql mysql

五、安装mysql

 
[[email protected] ~]# tar -zxvf mysql-5.5.22.tar.gz
[[email protected] ~]# cd mysql-5.5.22
----编译出现以下错误,需要ncurses-devel
[[email protected] mysql-5.5.22]#/usr/local/cmake/bin/cmake -DCMAKE_INSTALL_PREFIX=/opt/mysql5.5 -DMYSQL_DATADIR=/opt/mysql5.5/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci  -DEXTRA_CHARSETS=all  -DENABLED_LOCAL_INFILE=1
-- MySQL 5.5.22
-- 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! ----查看ncurses是否安装: [[email protected] mysql-5.5.22]# rpm -qa|grep necurses ncurses-5.5-24.20060715 ----安装ncurses-devel [[email protected]]# rpm -ivh ncurses-devel-5.5-24.20060715.i386.rpm warning: ncurses-devel-5.5-24.20060715.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186 Preparing... ########################################### [100%] 1:ncurses-devel ########################################### [100%] ----删除CMakeCache.txt [[email protected] mysql-5.5.22]# find / -name CMakeCache.txt /root/mysql-5.5.22/CMakeCache.txt /root/cmake-2.8.4/CMakeCache.txt /root/cmake-2.8.4/Tests/ComplexOneConfig/Cache/CMakeCache.txt /root/cmake-2.8.4/Tests/Complex/Cache/CMakeCache.txt /root/cmake-2.8.4/Tests/CMakeFiles/CheckFortran/CMakeCache.txt /root/cmake-2.8.4/Tests/ComplexRelativePaths/Cache/CMakeCache.txt [[email protected] mysql-5.5.22]# rm /root/mysql-5.5.22/CMakeCache.txt rm: remove regular file `/root/mysql-5.5.22/CMakeCache.txt'? yes [[email protected] mysql-5.5.22]# rm /root/cmake-2.8.4/CMakeCache.txt rm: remove regular file `/root/cmake-2.8.4/CMakeCache.txt'? yes [[email protected] mysql-5.5.22]# rm /root/cmake-2.8.4/Tests/ComplexOneConfig/Cache/CMakeCache.txt rm: remove regular file `/root/cmake-2.8.4/Tests/ComplexOneConfig/Cache/CMakeCache.txt'? yes [[email protected] mysql-5.5.22]# rm /root/cmake-2.8.4/Tests/Complex/Cache/CMakeCache.txt rm: remove regular file `/root/cmake-2.8.4/Tests/Complex/Cache/CMakeCache.txt'? yes [[email protected] mysql-5.5.22]# rm /root/cmake-2.8.4/Tests/CMakeFiles/CheckFortran/CMakeCache.txt rm: remove regular file `/root/cmake-2.8.4/Tests/CMakeFiles/CheckFortran/CMakeCache.txt'? yes [[email protected] mysql-5.5.22]# rm /root/cmake-2.8.4/Tests/ComplexRelativePaths/Cache/CMakeCache.txt rm: remove regular file `/root/cmake-2.8.4/Tests/ComplexRelativePaths/Cache/CMakeCache.txt'? yes ----再次进行编译: [[email protected] mysql-5.5.22]#/usr/local/cmake/bin/cmake -DCMAKE_INSTALL_PREFIX=/opt/mysql5.5 -DMYSQL_DATADIR=/opt/mysql5.5/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DENABLED_LOCAL_INFILE=1
[[email protected] mysql-5.5.22]#make && make install
 

备注:

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql //安装目录

-DINSTALL_DATADIR=/usr/local/mysql/data //数据库存放目录

-DDEFAULT_CHARSET=utf8     //使用utf8字符

-DDEFAULT_COLLATION=utf8_general_ci //校验字符

-DEXTRA_CHARSETS=all     //安装所有扩展字符集

-DENABLED_LOCAL_INFILE=1    //允许从本地导入数据

注意事项:

重新编译时,需要清除旧的对象文件和缓存信息。

#make clean

#rm -f CMakeCache.txt

#rm -rf /etc/my.cnf

六、设置目录权限

[[email protected] ~]# cd /opt/mysql5.5/
[[email protected] mysql5.5]# chown -R root:mysql .     //把当前目录中所有文件的所有者设为root,所属组为mysql                            
[[email protected] mysql5.5]# chown -R mysql:mysql data/

更多详情见请继续阅读下一页的精彩内容: http://www.linuxidc.com/Linux/2014-04/100758p2.htm

MySQL源码安装


2019 monjeep.com webmaster#monjeep.com
10 q. 0.018 s.
京ICP备10005923号