您的位置:首页 > 运维架构 > Linux

centos编译安装mysql

2017-04-25 00:00 465 查看
安装时最好使用root账号,如果没有root账号的话,使用普通账号需要使用sudo进行操作,没有sudo需要root管理员进行添加。

源码目录/wwwroot/source/,安装目录/wwwroot/apps/。除了目录之外,还有其他的地方可能需要更换。举一隅不以三隅反,则不复也。

一.安装相关依赖

1.安装gcc-c++库,gcc-c++库又依赖libstdc++

yum -y install libstdc++ gcc-c++

2.安装cmake,用于configure

wget http://distfiles.macports.org/cmake/cmake-3.7.0.tar.gz

tar -zxvf cmake-3.7.0.tar.gz && cd cmake-3.7.0

./bootstarp && gmake && gmake install

3.安装bison(mysql语法解析器需要使用bison进行编译)和ncurses-devel(用于终端操作的开发包)

wget http://ftp.gnu.org/gnu/bison/bison-2.7.tar.gz

tar -zxvf bison-2.7.tar.gz && cd bison-2.7

./configure && make && make install

wget http://ftp.gnu.org/pub/gnu/ncurses/ncurses-6.0.tar.gz

tar -zxvf ncurses-6.0.tar.gz && cd ncurses-6.0

./configure && make && make install

二.安装mysql

1.下载源码

    wget http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.54.tar.gz

    tar -zxvf mysql-5.5.54.tar.gz && cd mysql-5.5.54

2.编译

  ```
  cmake \

    -DCMAKE_INSTALL_PREFIX=/wwwroot/apps/mysql \

    -DMYSQL_DATADIR=/wwwroot/apps/data \

    -DDEFAULT_CHARSET=utf8 \

    -DDEFAULT_COLLATION=utf8_general_ci

    注:

        DCMAKE_INSTALL_PREFIX:安装目录,和./configure 参数 --prefix是一样的

        DMYSQL_DATADIR:数据存储目录

        DDEFAULT_CHARSET:指定默认字符集

        DDEFAULT_COLLATION:指定默认校对集

        字符集是库表和字段的默认字符集,校对集是字符集的默认排序

3.安装并配置

 ```
make && make install

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

    vim /etc/my.cnf 

        在 [mysqld] 下面加一行 

        datadir = /wwwroot/apps/data

    groupadd mysql

    useradd -g mysql mysql

    /wwwroot/sources/mysql-5.5.54/script/mysql_install_db \

        --basedir = /wwwroot/apps/mysql \

        --datadir = /wwwroot/apps/data \

        --user=mysql

    touch /wwwroot/apps/data/cloud.err

       touch /wwwroot/apps/data/cloud.pid

        注:文件名可能不一样,但如果没有这两个文件一定会报错的

三.启动mysql服务

1.起服务

/wwwroot/apps/mysql/bin/mysqld_safe --user=mysql &

2.登录

/wwwroot/apps/mysql/bin/mysql -u root

ok!

可能会遇到很多未知名的错误,多来几次就好了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: