CentOS下源码安装MySQL软件

步骤

  1. 安装依赖包

    yum -y install gcc make cmake ncurses-devel libxm12-devel libtool-ltdl-devel gcc-c++ autoconf automake bison zlib-devel

  2. 获取源码软件包

    yum -y install wget #安装wget
    wget http://cdn.mysql.com/archives/mysql-5.6/mysql-5.6.11.tar.gz #从官网拉去mysql软件源码包

  3. 为数据库进程创建用户及组账户

    groupadd mysql # 添加用户组mysql
    useradd -r -s /sbin/nologin -g mysql mysql # 添加用户账户mysql

  4. 将源码包解压到/usr/src/目录下

    tar -xzf mysql-5.6.11.tar.gz -C /usr/src/

  5. 编译安装MySQL软件

    cd /usr/src/mysql-5.6.11/ #进入源码目录
    cmake . -DENABLE_DOWNLOADS=1 # 编译MySQL
    make && make install # 编译MySQL
    chown -R mysql.mysql /usr/local/mysql #改变文件夹归属

  6. 初始化数据库

    使用mysql_install_db脚本初始化数据库,user定义数据库账户,basedir定义软件主目录,datadir定义数据库存放目录
    /usr/local/mysql/scripts/mysql_install_db –user=mysql –basedir=/usr/local/mysql –datadir=/usr/local/mysql/data
    将mysql主配置文件mysql.cnf复制一份到/etc/目录下
    cp /usr/local/mysql/my.cnf /etc/my.cnf

  7. 启动mysqld服务,并设置为开机启动

    使用mysqld_safe进程手动启动数据库服务进程
    /usr/local/mysql/bin/mysqld_safe –user=mysql &
    设置mysql开启启动
    cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
    chkconfig –add mysqld
    chkconfig mysqld on

  8. 将mysql命令添加到环境变量中

    PATH= PATH:/usr/local/mysql/bin/echoexportPATH= P A T H : / u s r / l o c a l / m y s q l / b i n / e c h o “ e x p o r t P A T H = PATH:/usr/local/mysql/bin/” >> /etc/profile

  9. 更改数据库默认设置

    mysql -u root -e “select User,Host,Password from mysql.user”
    /usr/local/mysql/bin/mysql_secure_installation

你可能感兴趣的:(运维管理,mysql)