• CentOS下安装 MySQL5.5


     
    1. 安装mysql的三种方法
     
     yum/rpm安装 简单,快速,但是没办法定制
    二进制包安装 解压后,简单配置就可以使用,不用安装,速度快,专业DBA喜欢这种方式.
    源码编译安装 可定制安装,但是安装时间长

    本案例使用MySQL5.5 二进制包安装。

    MySQL5.5源码包地址链接: https://pan.baidu.com/s/16Dn7UeZzAx1kSt-0u6eawg 提取码: m4nx

    2. 安装过程

    1.解压软件包mkdir /application/
    tar zxvf mysql-5.5.32-linux2.6-x64.tar.gz -C /application/
    2. 创建目录和用户
    groupadd mysql
    useradd -s /sbin/nologin -g mysql -M mysql #-s 不允许登录, -M 不需要家目录
    3. 做软连接,去掉版本号
    ln -s /application/mysql-5.5.32-linux2.6-x86_64 /application/mysql
    4. 选择配置样例
    [root@linux-node1 mysql]# cd support-files/
    [root@linux-node1 support-files]# ls *.cnf
    my-huge.cnf             my-large.cnf   my-small.cnf
    my-innodb-heavy-4G.cnf  my-medium.cnf
    个人实验一般选 small.cnf
    my-small.cnf为小型系统示例MySQL配置文件。
    #
    #这是一个仅使用MySQL的内存少(<= 64M)的系统
    #不时,mysqld守护进程很重要
    #不用太多的资源。
    /bin/cp /application/mysql/support-files/my-small.cnf /etc/my.cnf  #将配置文件覆盖到主配置中
    5.创建数据库目录 mkdir -p /application/mysql/data chown -R mysql.mysql /application/mysql/ 6. 初始化安装 /application/mysql/scripts/mysql_install_db --basedir=$mysql --datadir=$mysql/data --user=mysql
    7. 复制启动脚本到/etc/init.d/下 MySQL二进制默认安装目录是/usr/local/mysql, 所以需要替换掉启动脚本中的路径: sed -i 's#/usr/local/mysql#/application/mysql#g' /application/mysql/support-files/mysql.server sed -i 's#/usr/local/mysql#/application/mysql#g' /application/mysql/bin/mysqld_safe /bin/cp /application/mysql/support-files/mysql.server /etc/init.d/mysqld chmod +x /etc/init.d/mysqld
    8.启动mysqld 服务 /etc/init.d/mysqld start
    9. 检查端口 netstat -an | grep 3306 lsof -i:3306 ps -ef | grep mysql [root@linux-node1 support-files]# netstat -an | grep 3306 tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN [root@linux-node1 support-files]# lsof -i:3306 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME mysqld 24401 mysql 10u IPv4 127222 0t0 TCP *:mysql (LISTEN) [root@linux-node1 support-files]# ps -ef | grep mysql root 24160 1 0 15:53 pts/1 00:00:00 /bin/sh /application/mysql/bin/mysqld_safe --datadir=/application/mysql/data --pid-file=/application/mysql/data/linux-node1.openstack.com.pid mysql 24401 24160 0 15:53 pts/1 00:00:00 /application/mysql/bin/mysqld --basedir=/application/mysql --datadir=/application/mysql/data --plugin-dir=/application/mysql/lib/plugin --user=mysql --log-error=/application/mysql/data/linux-node1.openstack.com.err --pid-file=/application/mysql/data/linux-node1.openstack.com.pid --socket=/tmp/mysql.sock --port=3306 root 24426 24086 0 15:53 pts/1 00:00:00 grep mysql

    到此安装结束,但是以上9步有点麻烦 写个小脚本一键执行就ok!

    前提是目录和路径都ok!
    mysql_install.sh
    #!/bin/sh
    mysql=/application/mysql
    groupadd mysql
    useradd -s /sbin/nologin -g mysql -M mysql
    ln -s /application/mysql-5.5.32-linux2.6-x86_64 $mysql
    /bin/cp $mysql/support-files/my-small.cnf /etc/my.cnf
    mkdir -p /application/mysql/data
    chown -R mysql.mysql /application/mysql/
    #tail -1 /etc/passwd
    $mysql/scripts/mysql_install_db --basedir=$mysql --datadir=$mysql/data --user=mysql
    /bin/cp $mysql/support-files/mysql.server /etc/init.d/mysqld
    chmod +x /etc/init.d/mysqld
    sed -i 's#/usr/local/mysql#/application/mysql#g' /application/mysql/support-files/mysql.server
    sed -i 's#/usr/local/mysql#/application/mysql#g' /application/mysql/bin/mysqld_safe
    /bin/cp /application/mysql/support-files/mysql.server /etc/init.d/mysqld
    /etc/init.d/mysqld start
    netstat -an | grep 3306
    
     
     
  • 相关阅读:
    网络流24题总结和题解
    NOIP复习之1 数学数论
    BZOJ3301 P2524 UVA11525 算法解释康托展开
    线段树与树状数组的综合运用
    P2261 bzoj1257 [CQOI2007]余数求和
    BZOJ 1968_P1403 [AHOI2005]约数研究--p2260bzoj2956-模积和∑----信息学中的数论分块
    P1064 金明的预算方案
    洛谷p1002 过河卒
    Luogu P3014 [USACO11FEB]牛线Cow Line
    Luogu P3927 SAC E#1
  • 原文地址:https://www.cnblogs.com/shanghai1918/p/12842578.html
Copyright © 2020-2023  润新知