本次 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. 逐步配置企业版Symantec Norton防病毒服务器

    逐步配置企业版Symantec Norton防病毒服务器 配置企业版Symantec Norton NT操作系统,已经安装IIS 安装Symantec Norton 10 安装系统中心 650) th ...

  2. mySQL函数根据经纬度计算两点距离 复制代码

    http://www.cnblogs.com/lujiulong/p/6185041.html https://my.oschina.net/u/2273085/blog/505172?p={{pag ...

  3. Arch Linux实体机安装记录

    下面将记录笔者在戴尔笔记本安装arch linux的过程,用于记录,以便下次使用. 本文的内容参考arch linux官方Wiki. 首先,使用Power ISO把镜像安装到U盘,使用U盘安装. 通过 ...

  4. 巧用数据流让 Word 文档在线阅读

            常常写博客或空间日记的朋友,对网络编辑器(如图1,是CSDN的博客编辑器)并不陌生.也比較easy做出非常绚烂的排版.但这次在做一个BS的项目,客户一直在用Office的软件中的Wor ...

  5. [Javascript] Iterate Over Items with JavaScript's for-of Loop

    In this lesson we will understand the For Of loop in Javascript which was introduced in ES6. The for ...

  6. JavaScript原型及原型链

    代码一: <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF- ...

  7. vue 星星评分组件

    显示评分和打分组件,可现实半颗星星效果 效果图: 参数名 类型 说明 score Number 分数 ,默认0,保留一位小数 disabled Boolean 是否只读,默认false,鼠标点击可以打 ...

  8. 日历控件input框默认显示当日日期

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <script sr ...

  9. COGS——C2274. [HEOI 2016] tree

    http://www.cogs.pro/cogs/problem/problem.php?pid=2274 ★☆   输入文件:heoi2016_tree.in   输出文件:heoi2016_tre ...

  10. [D3] Animate Transitions in D3 v4

    D3 makes it easy to add meaningful animations to your data visualizations. Whether it’s fading in ne ...