源码编译mysql 5.5.40

[root@localhost cmake-3.1.0]#  yum install zlib-devel openssl-devel gcc-c++ gcc bison cmake ncurses-devel -y

[root@localhost ~]# groupadd -r mysql
[root@localhost ~]# useradd -g mysql -r -s /sbin/nologin mysql
[root@localhost ~]# id mysql #确认用户
[root@localhost ~]# mkdir /var/data/mysql -p #存放数据库文件
[root@localhost ~]# chown mysql:mysql /var/data –R

[root@localhost MailServer]# tar zxvf  mysql-5.5.40.tar.gz -C ../
[root@localhost MailServer]# cd ../mysql-5.5.40/

cmake编译MySQL的一些常用选项:

------------------------------------------------------------
cmake mysql 编译安装:
./configure -> cmake .
./configure --help -> cmake -LH -> ccmake .
------------------------------------------------------------
指定安装文件的安装路径常用选项
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql
-DMYSQL_DATADIR=/data/mysql
-DSYSCONFDIR=/etc
------------------------------------------------------------
默认编译的存储引擎包括: csv, myisma, myisammrg, heap. 若要安装其他存储引擎,可以使用类似如下的编译选项
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_ARCHIVE_STORAGE_ENGINE=1
-DWITH_BLACKHOLE_STORAGE_ENGINE=1
------------------------------------------------------------
若要明确指出不编译某存储引擎, 可以使用类似如下的选项:
-DWITHOUT_<ENGINE>_STORAGE_ENGINE=1
例如:
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1
-DWITHOUT_FEDERATED_STORAGE_ENGINE=1
------------------------------------------------------------
若要编译进其他功能, 如SSl等, 可使用类似如下选项来实现编译时使用某库文件或者, 或者不使用某库文件.
-DWITH_READLINE=1
-DWITH_SSL=system
-DWITH_ZLIB=system
-DWITH_LIBWRAP=0
------------------------------------------------------------
其他常用选项:
-DMYSQL_TCP_PORT=3306
-MYDQL_UNIX_ADDR=/tmp/mysql.sock
-DENABLED_LOCAL_INFILE=1
-DEXTRA_CHARSETS=all
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci
-DWITH_DEBUG=0
-DENABLE_PROFILING=1
------------------------------------------------------------

开始编译

[root@localhost mysql-5.5.40]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.5.40 \
-DMYSQL_DATADIR=/var/data/mysql \ #数据库目录
-DSYSCONFDIR=/etc \ #配置文件目录
-DWITH_INNOBASE_STORAGE_ENGINE=1 \ #启用InnoDB存储引擎
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \ #启用ARCHIVE存储引擎
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ #启用黑洞存储引擎
-DWITH_READLINE=1 \
-DWITH_SSL=system \ #启用SSL协议
-DWITH_ZLIB=system \ #启用Zlib压缩
-DWITH_LIBWRAP=0 \
-DDEFAULT_CHARSET=utf8 \ #设置字符集utf8
-DMYSQL_NUIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_COLLATION=utf8_general_ci

make

make install

如出现错误,原因是未安装数据库

141223 21:05:40 [Note] /usr/local/mysql/bin/mysqld: Shutdown complete

141223 21:05:40 mysqld_safe mysqld from pid file /usr/local/mysql/data/localhost.localdomain.pid ended
141223 21:05:45 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
^G/usr/local/mysql/bin/mysqld: File './mysql-bin.index' not found (Errcode: 13)
141223 21:05:46 [ERROR] Aborting

编译完成后,安装数据库

# cd /usr/local/mysql    
# chown -R mysql .    
# chgrp -R mysql .    
# scripts/mysql_install_db --user=mysql  --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data  
# chown -R root .   
# chown -R mysql ./data

错误日志显示:Can't open the mysql.plugin table...2009-06-01 00:52Can't open the mysql.plugin table. Please run mysql_upgrade to create it.

解决方法:重新执行数据库安装过程,并带上

--basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

将mysql的配置文件拷贝到/etc

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

拷贝服务,设置开机启动,启动MySQL

#cp support-files/mysql.server /etc/init.d/mysql
#chkconfig mysql on
#service mysql start  --启动MySQL

查看MySQL启动状态

# service mysqld status
MySQL running (62374)                                      [  OK  ]
posted @ 2014-12-24 13:34  xfans1982  阅读(383)  评论(0编辑  收藏  举报