源码编译安装mysql


准备工作:

新建用户和用户组

groupadd mysql

useradd -g mysql mysql


1:下载:

bison-2.4.2.tar.bz2


cmake-2.8.3.tar.gz


make-3.82.tar.gz


bzr-2.3b5.tar.gz


mysql-5.6.11.tar.gz






2:解压安装前3个包






tar zxvf  cmake-2.8.3.tar.gz


cd cmake-2.8.3


./configure


make


make install


tar zxvf make-3.82.tar.gz


cd make-3.8.2


./configure


make


make install

tar jxvf bison-2.4.2.tar.bz2

cd bison-2.4.2

./configure

make

make install


3:解压mysql-5.5.8.tar.gz

tar zxvf mysql-5.5.8.tar.gz


cd mysql-5.5.8

cmake . \


-DCMAKE_INSTALL_PREFIX=/mysql/mysqldir \


-DMYSQL_DATADIR=/mysql/mysqldir/data \


-DWITH_INNOBASE_STORAGE_ENGINE=1 \


-DMYSQL_TCP_PORT=3306 \


-DMYSQL_UNIX_ADDR==/mysql/mysqldir/data/mysql.sock \


-DMYSQL_USER=mysql \


-DWITH_DEBUG=0

报错(如无报错直接make & make install 即可):

CMake Error at cmake/readline.cmake:82 (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:126 (FIND_CURSES)

cmake/readline.cmake:216 (MYSQL_USE_BUNDLED_LIBEDIT)

CMakeLists.txt:256 (MYSQL_CHECK_READLINE)


-- Configuring incomplete, errors occurred!


缺少包:ncurses-devel

解决:

到安装光盘或者网上DOWN相应的包
安装:

rpm -ivh ncurses-devel*.rpm


rm -f CMakeCache.txt

cmake . \


-DCMAKE_INSTALL_PREFIX=/mysql/mysqldir \


-DMYSQL_DATADIR=/mysql/mysqldir/data \


-DWITH_INNOBASE_STORAGE_ENGINE=1 \


-DMYSQL_TCP_PORT=3306 \


-DMYSQL_UNIX_ADDR==/mysql/mysqldir/data/mysql.sock \


-DMYSQL_USER=mysql \


-DWITH_DEBUG=0

make


make install

完成后进入MYSQL安装目录

cd /mysql/mysqldir


cp support-files/my-huge.cnf /etc/my.cnf        (这个步骤在5.6以后就没有了,可在mysql的changelog中发现。)


vi /etc/my.cnf

将数据目录和套接字文件修改为实际值.

修改权限

chown mysql:mysql /etc/my.cnf


chown -R mysql:mysql /mysql/mysqldir

切换用户进入安装目录

su - mysql


cd /mysql/mysqldir


cp scripts/mysql_install_db .  (这个步骤必须,如果成功则会见到相应的使用指南)


./mysql_install_db

启动MYSQL

bin/mysqld_safe &

OK


让服务开机自动运行 
  把/usr/local/mysql/support-files/my.server 复制到/etc/init.d/mysqld 
执行 
  sudo update-rc.d mysqld defaults 
把mysqld加入到服务中,重新启动机器即可 


另外,建议把/usr/local/mysql/bin目录加入系统路径,便于用户访问。 


* mysqld和mysqld_safe 有什么区别? 
直接运行mysqld程序来启动MySQL服务的方法很少见,mysqld_safe脚本会在启动MySQL服务器后继续监控其运行情况,并在其死机时重新启动它。 
用mysqld_safe脚本来启动MySQL服务器的做法在BSD风格的unix系统上很常见,非BSD风格的UNIX系统中的mysql.server脚本其实也是调用mysqld_safe脚本去启动MySQL服务器的。

你可能感兴趣的:(源码编译安装mysql)