下载源码包

http://dev.mysql.com/downloads/mysql/5.5.html#downloads

创建用户

shell> groupadd mysql
shell> useradd -g mysql mysql

解开源码包

shell> tar zxvf mysql-VERSION.tar.gz
shell> cd mysql-VERSION

设计参数

shell> ./configure 
--prefix=/usr/local/mysql
--with-client-ldflags=-all-static 这两行不能加,具休的再学习一下
--with-mysqld-ldflags=-all-static
--enable-assembler
--with-charset=utf8
--without-debug
--enable-thread-safe-client 
--enable-profiling
--with-mysqld-user=mysql
--with-plugins=all
--with-innodb

编译

shell> make

安装

shell> make install

到这里设计一下目录权限

shell> cd /usr/local/mysql
shell> chown -R mysql .
shell> chgrp -R mysql .

安装库

shell> bin/mysql_install_db --user=mysql
shell> chown -R root .
shell> chown -R mysql var

复制文件

shell> cp support-files/my-medium.cnf /etc/my.cnf

启动服务

shell> bin/mysqld_safe --user=mysql &

复制命令文件

shell> cp support-files/mysql.server /etc/init.d/mysql.server
shell> cp support-files/mysql.server /etc/init.d/mysql

/etc/init.d/mysql start 权限不够

加个权限

chmod +x /etc/init.d/mysql

加到service里

cd /etc/init.d/
chkconfig --add mysqld #将mysql加到启动服务列表里
chkconfig mysqld on #让系统启动时自动打开mysql服务
./configure --prefix=/usr/local/mysql/ --with-server-suffix=-junsansi-edition --enable-assembler --enable-local-infile --enable-thread-safe-client --with-big-tables --with-charset=utf8  --with-extra-charsets=gbk,gb2312,utf8,ascii  --with-readline --with-ssl --with-embedded-server --with-pthread --with-mysqld-user=mysql --with-mysqld-ldflags=-all-static --with-client-ldflags=-all-static --with-plugins=partition,innobase,innodb_plugin > /home/jss/mysql_setuplogs_configure.log 2>&1

提示:configure支持的选项非常多,详细的参数及说明建议参考官方文档,也可以通过./configure --help查看,这里仅列出常用及推荐使用的选项。

    --prefix=PREFIX:指定程序安装路径;
    --enable-assembler:使用汇编模式;
    --enable-local-infile:启用对LOAD DATA LOCAL INFILE语法的支持(默认不支持);
    --enable-profiling:Build a version with query profiling code (req.community-features)
    --enable-thread-safe-client:使用编译客户端;
    --with-big-tables:启用32位平台对4G大表的支持;
    --with-charset=CHARSET:指定字符集;
    --with-collation=:默认collation;
    --with-extra-charsets=CHARSET,CHARSET,...:指定附加的字符集;
    --with-fast-mutexes:Compile with fast mutexes
    --with-readline:
    --with-ssl:启用SSL的支持;
    --with-server-suffix=:添加字符串到版本信息;
    --with-embedded-server:编译embedded-server;
    --with-pthread:强制使用pthread类库;
    --with-mysqld-user=:指定mysqld守护进程的用户;
    --with-mysqld-ldflags=:静态编译MySQL服务器端;
    --with-client-ldflags=:静态编译MySQL客户端;
    --with-plugins=PLUGIN,PLUGIN,...:MySQL服务器端支持的组件(默认为空),可选值较多:
        partition:MySQL Partitioning Support;
        daemon_example:This is an example plugin daemon;
        ftexample:Simple full-text parser plugin;
        archive:Archive Storage Engine;
        blackhole:Basic Write-only Read-never tables;
        csv:Stores tables in text CSV format,强制安装;
        example:Example for Storage Engines for developers;
        federated:Connects to tables on remote MySQL servers;
        heap:Volatile memory based tables,强制安装;
        ibmdb2i:IBM DB2 for i Storage Engine;
        innobase:Transactional Tables using InnoDB;
        innodb_plugin:Transactional Tables using InnoDB;
        myisam:Traditional non-transactional MySQL tables,强制安装;
        myisammrg:Merge multiple MySQL tables into one,强制安装;
        ndbcluster:High Availability Clustered tables;
    --with-plugin-PLUGIN:强制指定的插件链接至MySQL服务器;
    --with-zlib-dir=:向MySQL提供一个自定义的压缩类库地址;
    --without-server:仅安装MySQL客户端;
    --without-query-cache:不要编译查询缓存;
    --without-geometry:不要编译geometry-related部分;
    --without-debug:编译为产品版,放弃debugging代码;
    --without-ndb-debug:禁用special ndb debug特性;

提示:执行Configure时如果报bin/rm: cannot remove `libtoolt’: No such file or directory错误,可按照下列步骤解决:

  1. 确认libtool是否已经安装,如果没有安装的话,则先安装libtool

    # rpm -qa | grep libtool
    # yum -y install libtool
    
  2. 分别执行以下三条命令:

    # autoreconf --force --install
    # libtoolize --automake --force
    # automake --force --add-missing
    

    再重新编译安装,问题解决!

error while loading shared libraries: libmysqlclient.so.16: cannot open shared object file: No such file or directory

在网上搜了下解决的方法:

在/etc/ld.so.conf里面加入下面2行:
/usr/local/mysql/lib/mysql
/usr/local/lib

ln -s /usr/local/mysql/lib/libmysqlclient.so.16 /usr/lib/libmysqlclient.so.16

然后用ldconfig重新加载下库文件

使用备份库时两个注意点

一要用备份时的那个my.cnf
二要用mysql.mysql加权限 #chown -R mysql.myssql .

转载请注明原地址: http://blog.noark.xyz/article/2012/5/2/mysql源码安装/