centos7.4手动安装mysql5.6

355 阅读2分钟

安装前准备

Cenos7.4服务器:

一台已安装好的centos7.4的服务器

数据库:

mysql5.6.49 下载地址

开始表演

准好上面两步,开始造吧。

  1. 查看系统是否默认安装mysql,CentOS7下默认安装了mariadb,是mysql的一个分支,我们这里卸载掉

    rpm -qa|grep mariadb		#查找系统是否存在Mariadb
    
    mariadb-libs-5.5.56-2.e17.x86_64
    

    如果存在就删除

    rpm -e --nodeps   mariadb-libs-5.5.56-2.e17.x86_64
    
  2. 把mysql5.6.27back.tar编译包 上传到 /opt 目录下 (可以通过 filezilla 等辅助工具上传)

  3. 解压编译包,解压后在当前目录下会多一个mysql文件夹。

    tar xvf mysql5.6.27back.tar
    
  4. 复制mysql到指定目录

    mv mysql /usr/local/mysql
    
  5. 创建mysql用户和组(passwd 设置密码安装后需要登录,牢记)

    groupadd mysql
    useradd -g mysql mysql
    passwd mysql
    
  6. 修改目录权限

    chown -R mysql:mysql /usr/local/mysql
    
  7. 安装数据库(安装出错,根据提示执行相应安装操作,切记如果已经 su mysql 进入mysql模式,先exit退出,再执行yum 安装 )

    su mysql  
    
    /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
    
    exit
    

    安装出错提示1

    ./scripts/mysql_install_db  --user=mysql
    -bash: ./scripts/mysql_install_db: /usr/bin/perl: bad interpreter: No such file or directory
    

    执行

    yum -y install perl perl-devel
    

    安装出错提示2

    FATAL ERROR: please install the following Perl modules before executing /usr/bin/mysql_install_db: 
    Data::Dumper
    

    执行

    yum install -y perl-Data-Dumper
    

    安装出错提示3

    Installing MySQL system tables.../usr/local/mysql/bin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
    

    执行

    yum install libaio* -y
    

    如果还是有问题,执行

    yum -y install numactl
    
  8. 复制mysql配置文件

    cd /usr/local/mysql/support-files
    cp my-default.cnf /etc/my.cnf
    
  9. 添加系统服务

    cp mysql.server /etc/init.d/mysql
    chkconfig mysql on
    
  10. 添加环境变量

    vi /etc/profile
    

    在最下面添加

    export MYSQL_HOME="/usr/local/mysql"
    export PATH="$PATH:$MYSQL_HOME/bin"
    

    保存退出后,执行生效代码

    . /etc/profile
    
  11. 启动mysql

    service mysql start
    

    启动出错提示

    ERROR! The server quit without updating PID file (/usr/local/mysql/data/mysql.pid).
    

    查看进程,删除所有mysql进程

    ps aux |grep mysql
    
    kill -9 pid
    
  12. 允许所有外部链接访问(可选)

    mysql -u root -p
    

    mysql命令行输入

    GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
    
    FLUSH PRIVILEGES;
    

    出错提示

     -bash: mysql: command not found
    

    解决

    ln -s /usr/local/mysql/bin/mysql /usr/bin/
    

    如果提示密码错误,在/etc/my.cnf

    skip-grant-tables //跳过密码验证
    
    msyql //进入mysql
    
    update mysql.user set password=password("123456") where user='root';  //更新密码
    
    flush privileges; //刷新
    

    到此已经安装完毕。 如果连接不上需要注意两个点

  13. 数据是否启动

  14. 防火墙问题

    firewall-cmd --state   //查看防火墙状态
    systemctl stop firewalld.service  //停止防火墙
    systemctl disable firewalld.service  //禁止防火墙开机启动