本次 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方法分享

p=1194">RHEL7中防火墙firewalld的配置(1)

Mysql 安装(Using Generic Binaries)的更多相关文章

  1. Debian 8.2 下安装MySQL5.7.9 Generic Binaries

    安装过程参考了Installing MySQL on Unix/Linux Using Generic Binaries 首先检查是否安装libaio shell> apt-cache sear ...

  2. MySQL安装、基本账户安全(5.0以后版本)

    博文目录: 1.Mysql-5.0.40.tar.gz Mysql-5.1.72.tar.gz 2.Mysql-5.5.22.tar.gz 3.Mysql-5.5.34.tar.gz 4.Mysql- ...

  3. MySQL下载与MySQL安装图解(MySQL5.7与MySQL8.0)

    MySQL下载与MySQL安装图解(MySQL5.7与MySQL8.0) 1.MySQL下载(MySQL8.0社区版) mysql下载方法,请根据风哥以下步骤与图示来下载mysql8.0最新社区版本: ...

  4. Windows系统MySQL安装配置

    MySQL是一个开放源代码的数据库管理系统,是由MySQL AB公司开发.发布并支持的,现在属于Oracle旗下产品. 与其他大型数据库管理系统如Oracle.DB2.SQL Server等相比,虽然 ...

  5. centos mysql 实战 第一节课 安全加固 mysql安装

    centos mysql  实战  第一节课   安全加固  mysql安装 percona名字的由来=consultation 顾问+performance 性能=per  con  a mysql ...

  6. Linux下mysql安装过程

    到mysql官网下载mysql编译好的二进制安装包,在下载页面Select Platform:选项选择linux-generic,然后把页面拉到底部,64位系统下载Linux - Generic (g ...

  7. linux Mysql 安装及配置

    1.准备 cmake-3.6.0.tar.gz bison-3.0.4.tar.gz mysql-5.7.13.tar.gz (http://dev.mysql.com/get/Downloads/M ...

  8. mysql安装一 --- 源码包安装

    1.登陆http://www.mysql.com/ 或者 www.oracle.com 2. 3. 4. 上面如果不能加载,禁用代理软件 5. 6. 7. 8. 9.上传 10.md5校验安装包的完整 ...

  9. Ubuntu14.04 Django Mysql安装部署全过程

    Ubuntu14.04 Django Mysql安装部署全过程   一.简要步骤.(阿里云Ubuntu14.04) Python安装 Django Mysql的安装与配置 记录一下我的部署过程,也方便 ...

随机推荐

  1. 洛谷P3273 [SCOI2011]棘手的操作

    题目描述 有N个节点,标号从1到N,这N个节点一开始相互不连通.第i个节点的初始权值为a[i],接下来有如下一些操作:U x y: 加一条边,连接第x个节点和第y个节点A1 x v: 将第x个节点的权 ...

  2. 使用缓存Memcache存储更新微信access token

    关键字:Memcache access_token 更新 存储 7200 本文介绍如何使用缓存Memcache存储及更新 access token的方法. 一.Access Token access_ ...

  3. Vue的学习--开始之前的思考

    1.前端后端的思考,到底前端做什么工作 有关前端后端工作的区分,曾经有个朋友告诉我:web开发过程,前端负责从将数据从数据接口提取到前端.路由转换.前端交互展示等等所有工作,后端负责处理数据库里面的数 ...

  4. hibernate中的事务管理是怎么概念?

    1.JDBC事务 JDBC 事务是用 Connection 对象控制的.JDBC Connection 接口( java.sql.Connection )提供了两种事务模式:自动提交和手工提交. ja ...

  5. How to remove a Data Guard Configuration from Primary Database (文档 ID 733794.1)

    APPLIES TO: Oracle Database - Enterprise Edition - Version 10.1.0.2 to 11.2.0.3 [Release 10.1 to 11. ...

  6. 【Codeforces Round #431 (Div. 2) C】From Y to Y

    [链接]点击打开链接 [题意] 让你构造一个大小最多为10W的字符multiset. 你进行n-1次操作; 每次操作,从set中取出两个字符串,一开始单个字符被认为是字符串. 然后把它们连接在一起. ...

  7. 【原创】面向对象版本地CPU资源占用监控脚本

    前期准备: 1.python2.7环境 2.相关第三方库下载安装 脚本工作过程: 1.根据输入的进程名判断进程是否存在,如果不存在则进行等待,直到检测到进程PID,中途进程退出抛出异常,键入enter ...

  8. python中数据结构

    列表:数组,矩阵 元组 映射:字典 集合

  9. Altium Designer的pcb界面如何让线变成点

    但是16版本,需要tools  ---  Grid Manager --双击 双击后: 转自:http://blog.csdn.net/ldcung/article/details/77411434

  10. P2P借款的几种情况

    借款,至少出现2种人,借款人和出借人.根据人的性质,企业和个人,分成4种情况. 企业-个人,企业-企业,个人-企业,个人-个人. P2P平台可能出现几种情况: 个人-个人 2种情况:   a. 借款人 ...