你好,游客 登录 注册 搜索
背景:
阅读新闻

MySQL源码安装

[日期:2014-04-25] 来源:Linux社区  作者:Richardzhu [字体: ]

一、文章说明

最近接触到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,本人是在度娘搜的。

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

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

[root@node4 ~]# mkdir -p /opt/mysql5.5
[root@node4 ~]# mkdir -p /opt/mysql5.5/data 

四、创建mysql用户及用户组

[root@node4 ~]# groupadd mysql
[root@node4 ~]# useradd -r -g mysql mysql

五、安装mysql

 
[root@node4 ~]# tar -zxvf mysql-5.5.22.tar.gz
[root@node4 ~]# cd mysql-5.5.22
----编译出现以下错误,需要ncurses-devel
[root@node4 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是否安装: [root@node4 mysql-5.5.22]# rpm -qa|grep necurses ncurses-5.5-24.20060715 ----安装ncurses-devel [root@node4]# 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 [root@node4 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 [root@node4 mysql-5.5.22]# rm /root/mysql-5.5.22/CMakeCache.txt rm: remove regular file `/root/mysql-5.5.22/CMakeCache.txt'? yes [root@node4 mysql-5.5.22]# rm /root/cmake-2.8.4/CMakeCache.txt rm: remove regular file `/root/cmake-2.8.4/CMakeCache.txt'? yes [root@node4 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 [root@node4 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 [root@node4 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 [root@node4 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 ----再次进行编译: [root@node4 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
[root@node4 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

六、设置目录权限

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

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

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款