• Mysql 安装(Using Generic Binaries)


    本次 Mysql 为Community 5.6.21 版本号。安装方式为通用Linux安装方式。即大多数Linux平台都能够採用该方式进行安装。

    一、安装步骤

    1、安装环境

    1)Centos 7.0.1406 X86_64 或 Centos 6.5 X86_64 两者仅在防火墙策略上略有不同!

    2、下载 Mysql 、解压缩、创建软连接,与官方提供解压缩路径有些许。

    $ wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.21-linux-glibc2.5-x86_64.tar.gz
    $ sudo tar zxvf mysql-5.6.21-linux-glibc2.5-x86_64.tar.gz -C /usr/local/src/
    $ sudo ln -s /usr/local/src/mysql-5.6.21-linux-glibc2.5-x86_64/ /usr/local/mysql
    

    3、安装方式分为两种。

    方式1 參考 Mysql 官方指导建议进行安装,多用在Mysql学习环境。下列命令来源Mysql官方。原文參见 Installing MySQL on Unix/Linux Using Generic Binaries

    shell> groupadd mysql
    shell> useradd -r -g mysql mysql
    shell> cd /usr/local
    shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
    shell> ln -s full-path-to-mysql-VERSION-OS mysql
    shell> cd mysql
    shell> chown -R mysql .
    shell> chgrp -R mysql .
    shell> scripts/mysql_install_db --user=mysql
    shell> chown -R root .
    shell> chown -R mysql data
    shell> bin/mysqld_safe --user=mysql &
    # Next command is optional
    shell> cp support-files/mysql.server /etc/init.d/mysql.server

    方式2 自己定义 Mysql 数据保存路径,多用在部署环境。

    1)创建Mysql用户以及用户组

    $ sudo groupadd mysql
    $ sudo useradd -r -g mysql mysql
    $ cd /usr/local/src/
    $ sudo chown -R mysql:mysql mysql-5.6.21-linux-glibc2.5-x86_64/ #定义mysql用户以及组
    $ ll
    总用量 4
    drwxr-xr-x. 13 mysql mysql 4096 11月  5 08:10 mysql-5.6.21-linux-glibc2.5-x86_64
    

    2)创建Mysql数据文件保存位置。若使用数据盘则自行挂载。

    $ sudo mkdir -p /data/mysql #定义mysql数据文件保存地址

    3)初始化 Mysql,可能会出现的问题參见文章底部问题处理方法

    $ sudo /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql/ #初始化 mysql

    4)配置 my.cnf

    $ sudo vi /usr/local/mysql/my.cnf 

    本演示样例仅保证能够正常执行,所以配置例如以下三项就可以。

      basedir = /usr/local/mysql
      datadir = /data/mysql
      port = 3306

    建立软连接 my.cnf 到 /etc/ 文件夹

    $ sudo ln -s /usr/local/mysql/my.cnf /etc/my.cnf

    5)启动 Mysql 服务

    $ sudo /usr/local/mysql/support-files/mysql.server start
    Starting MySQL. SUCCESS! 

    6)登陆 Mysql

    $ /usr/local/mysql/bin/mysql
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 1
    Server version: 5.6.21 MySQL Community Server (GPL)
    
    Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
    
    mysql> 

    二、开机启动

    $ sudo chkconfig --add mysqld

    三、环境变量

    1)编辑 profile 文件

    $ sudo vi /etc/profile

    2)加入下列信息到 profile 底部

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

    3)马上生效配置文件

    $ source /etc/profile

    四、Mysql远程连接

    mysql> select user();
    +----------------+
    | user()         |
    +----------------+
    | root@localhost |
    +----------------+
    1 row in set (0.01 sec)
    
    mysql> grant all privileges  on *.* to root@'%' identified by "你的password";
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> flush privileges;
    Query OK, 0 rows affected (0.00 sec)

    五、防火墙开启

    Centos 6.5 默认启用 iptables 管理port

    编辑 iptables 文件

    $ sudo vim /etc/sysconfig/iptables
    加入 3306 port规则,注意第11行 3306 port规则
    # Firewall configuration written by system-config-firewall
    # Manual customization of this file is not recommended.
    *filter
    :INPUT ACCEPT [0:0]
    :FORWARD ACCEPT [0:0]
    :OUTPUT ACCEPT [0:0]
    -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
    -A INPUT -p icmp -j ACCEPT
    -A INPUT -i lo -j ACCEPT
    -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
    -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
    -A INPUT -j REJECT --reject-with icmp-host-prohibited
    -A FORWARD -j REJECT --reject-with icmp-host-prohibited
    COMMIT
    重新启动 iptables 服务就能够远程连接了。
    $ sudo service iptables restart
    iptables:将链设置为政策 ACCEPT:filter                    [确定]
    iptables:清除防火墙规则:                                 [确定]
    iptables:正在卸载模块:                                   [确定]
    iptables:应用防火墙规则:                                 [确定]

    Centos 7 默认启用 firewall 管理port

    1)查看port开启情况,若之前没有配过会显示 no 说明 3306 port未开放,反之 yes 说明已开放直接可用 Mysql client远程訪问。

    $ sudo firewall-cmd --query-port=3306/tcp
    no

    2)暂时性开启 3306 port

    $ sudo firewall-cmd --add-port=3306/tcp
    success

    3)永久性开启 3306 port

    $ sudo firewall-cmd --permanent --zone=public --add-port=3306/tcp
    success
    $ sudo firewall-cmd --reload #又一次载入配置
    success
    [john@localhost ~]$ sudo firewall-cmd --zone=public --list-all #查看加入结果
    public (default, active)
      interfaces: eth0
      sources: 
      services: dhcpv6-client ssh
      ports: 3306/tcp 22/tcp
      masquerade: no
      forward-ports: 
      icmp-blocks: 
      rich rules: 

    六、问题整理

    问题1:

    $ sudo scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql/
    sudo: unable to execute scripts/mysql_install_db: No such file or directory

    解决:解决问题纯属巧合,去掉 sudo 提示 Perl 解析器有问题。又一次安装下

    $ sudo yum install perl
    $ sudo yum install perl-Data-Dumper.x86_64

    问题2:

    $ sudo scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql/
    Installing MySQL system tables.../usr/local/mysql//bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

    解决:

    $ sudo yum install libaio.x86_64

    问题3:

    $ sudo support-files/mysql.server start
    Starting MySQL. ERROR! The server quit without updating PID file (/data/mysql/localhost.localdomain.pid).
    解决:这个问题特别实在首次启动时会提示,简单说就是找不到 my.cnf 文件,将配置完成 my.cnf 拷贝到 /etc/  或 建立软连接到 /etc/ 文件夹下。

    $ sudo cp my.cnf /etc/
    这里我有点疑惑,表面现象 mysql 启动依赖 /etc/my.cnf 文件,但实际第一次正常启动 mysql 后能够删除 /etc/my.cnf 文件。第二次启动能够正常载入 /usr/local/mysql/my.cnf 文件!


    转载请注明出处:http://blog.csdn.net/johnnycode/article/details/40783553


    參考文章:

    Centos7 安装Mysql 5.6.19

    CentOS 7.0编译安装Nginx1.6.0+MySQL5.6.19+PHP5.5.14方法分享

    RHEL7中防火墙firewalld的配置(1)

  • 相关阅读:
    Assembly Manifest 通俗简易手册
    CruiseControl服务器安装配置
    关于URL编码
    从A到Z来说说Web开发
    通过注册表查看 .NET Framework的版本信息
    云数据存在哪里?
    C#中你可能不知道的8件事(zz)
    用PBKDF2 或BCrypt 来存储密码
    C++编译器什么时候为我们自动生成拷贝构造函数?
    C#中你可能不知道的8件事(zz)
  • 原文地址:https://www.cnblogs.com/llguanli/p/7232757.html
Copyright © 2020-2023  润新知