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
參考文章:
Mysql 安装(Using Generic Binaries)的更多相关文章
- Debian 8.2 下安装MySQL5.7.9 Generic Binaries
安装过程参考了Installing MySQL on Unix/Linux Using Generic Binaries 首先检查是否安装libaio shell> apt-cache sear ...
- 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- ...
- MySQL下载与MySQL安装图解(MySQL5.7与MySQL8.0)
MySQL下载与MySQL安装图解(MySQL5.7与MySQL8.0) 1.MySQL下载(MySQL8.0社区版) mysql下载方法,请根据风哥以下步骤与图示来下载mysql8.0最新社区版本: ...
- Windows系统MySQL安装配置
MySQL是一个开放源代码的数据库管理系统,是由MySQL AB公司开发.发布并支持的,现在属于Oracle旗下产品. 与其他大型数据库管理系统如Oracle.DB2.SQL Server等相比,虽然 ...
- centos mysql 实战 第一节课 安全加固 mysql安装
centos mysql 实战 第一节课 安全加固 mysql安装 percona名字的由来=consultation 顾问+performance 性能=per con a mysql ...
- Linux下mysql安装过程
到mysql官网下载mysql编译好的二进制安装包,在下载页面Select Platform:选项选择linux-generic,然后把页面拉到底部,64位系统下载Linux - Generic (g ...
- 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 ...
- mysql安装一 --- 源码包安装
1.登陆http://www.mysql.com/ 或者 www.oracle.com 2. 3. 4. 上面如果不能加载,禁用代理软件 5. 6. 7. 8. 9.上传 10.md5校验安装包的完整 ...
- Ubuntu14.04 Django Mysql安装部署全过程
Ubuntu14.04 Django Mysql安装部署全过程 一.简要步骤.(阿里云Ubuntu14.04) Python安装 Django Mysql的安装与配置 记录一下我的部署过程,也方便 ...
随机推荐
- ThinkPHP5.0---静态方法
ThinkPHP5大量的使用了这种可以直接使用::调用的方法,它们有一个很响亮的名字:静态方法.静态方法的引用,大幅提升了程序的运行效率,降低了资源的占用. 静态方法(ASK$ANSWER) 为什么要 ...
- CSU1660: K-Cycle
Description A simple cycle is a closed simple path, with no other repeated vertices or edges other t ...
- meld文件的脚本
今天模仿着别人的脚本,结合网上的资料,摸索着写了一个简单的脚本,用来打开meld 工具.这个脚本虽然简单,但这是第一次自己写脚本,记录下来,作为自己python学习的起点.代码如下 #/use/bin ...
- 洛谷P1876 开灯
题目背景 该题的题目是不是感到很眼熟呢? 事实上,如果你懂的方法,该题的代码简直不能再短. 但是如果你不懂得呢?那...(自己去想) 题目描述 首先所有的灯都是关的(注意是关!),编号为1的人走过来, ...
- ospp.vbs是什么文件?激活过程cscript ospp.vbs命令详解
ospp.vbs是什么文件?激活过程cscript ospp.vbs命令详解 在Office 2013激活过程中我们经常会用到cscript ospp.vbs这个命令.那么,很有必要来了解一下,osp ...
- C语言库函数,头文件
参看:https://zhidao.baidu.com/question/328173842.html 该文件包含了的C语言标准库函数的定义 stdlib.h里面定义了五种类型.一些宏和通用工具函数. ...
- Makefile的问题
注意包含路径的变量,可能会带有空格而使得运行失败 直接定义:DEBUG = false后面引用需要使用 $(DEBUG) 或者set DEBUG $(DEBUG)之后就可以直接引用了
- 在 Windows 10 x64 上安装及使用 ab 工具的流程
本文转自:www.shuijingwanwq.com/2017/04/18/1568/ 1.基于AB测试工具进行高并发情形下的模拟测试,打开:http://httpd.apache.org/docs/ ...
- 【Codeforces Round #443 (Div. 2) A】Borya's Diagnosis
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 模拟 [代码] #include <bits/stdc++.h> using namespace std; const ...
- Oracle数据库(三)
专题一:oracle查询 1.where查询 查询部门编号是1的部门信息 ; 查询姓名是kw的员工,字符串使用‘’,内容大小写敏感 select *from emp where name='kw' 查 ...