MySQL5.7--------基于CentOS6二进制包安装
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL5.7--------基于CentOS6二进制包安装相关的知识,希望对你有一定的参考价值。
1. 背景
* mysql是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于 Oracle 旗下产品。MySQL 是最流行的关系型数据库管理系统之一,在 WEB 应用方面,MySQL是最好的 RDBMS (Relational Database Management System,关系数据库管理系统) 应用软件。
* MySQL是一种关系数据库管理系统,关系数据库将数据保存在不同的表中,而不是将所有数据放在一个大仓库内,这样就增加了速度并提高了灵活性。
* MySQL所使用的 SQL 语言是用于访问数据库的最常用标准化语言。MySQL 软件采用了双授权政策,分为社区版和商业版,由于其体积小、速度快、总体拥有成本低,尤其是开放源码这一特点,一般中小型网站的开发都选择 MySQL 作为网站数据库。
2. 选择的理由
* 支持多种平台[AIX、FreeBSD、HP-UX、Linux、Mac OS、OpenBSD、Solaris、Windows......]
* 支持并提供多语言API
* 开源,采用了 GPL协议,可以修改源码来开发自己的 MySQL 系统
* 支持标准SQL语句
* 支持多种存储引擎
* 使用广泛 [ 全球top20网站除微软的Live和Bing之外全部应用MySQL ]
3. MySQL安装方式
* 二制包安装
* 源码编译安装
* 平台安装包,如rpm包[centos,redhat]或deb[debian,ubuntu]包
4. 环境 [关闭selinux]
[[email protected] ~]# cat /etc/redhat-release CentOS release 6.9 (Final) [[email protected] ~]# uname -r 2.6.32-642.3.1.el6.x86_64 [[email protected] ~]# hostname MySQL [[email protected] ~]# getenforce Disabled
5. 安装 [ MySQL 5.7的安装方式与MySQL 5.5/5.6不劲相同 ]
* 下载 MySQL5.7 二进制包 [ 推荐从MySQL官方下载 ]
[[email protected] ~]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz
* 解压 MySQL 5.7 二进制包
[[email protected] ~]# tar zxvf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz
* 移动 MySQL 5.7 二进制包
[[email protected] ~]# mv mysql-5.7.18-linux-glibc2.5-x86_64 /usr/local/
* 创建软链接
[[email protected] ~]# ln -s /usr/local/mysql-5.7.18-linux-glibc2.5-x86_64 /usr/local/mysql
* 创建 mysql 用户
[[email protected] ~]# useradd -r -s /sbin/nologin mysql
* 创建 MySQL 数据存放目录
[[email protected] ~]# mkdir -vp /data/mysql_data mkdir: created directory `/data‘ mkdir: created directory `/data/mysql_data‘
* 在 MySQL 二进制包目录中创建 mysql-files 目录 [MySQL 数据导入/导出数据专放目录]
[[email protected] ~]# mkdir -v /usr/local/mysql/mysql-files mkdir: created directory `/usr/local/mysql/mysql-files‘
* 修改 MySQL 二进制包目录的所属用户与所属组
[[email protected] ~]# chown root.mysql -R /usr/local/mysql-5.7.18-linux-glibc2.5-x86_64
* 修改 MySQL 数据目录与 数据导入/导出专放目录的所属用户与所属组
[[email protected] ~]# chown mysql.mysql /usr/local/mysql/mysql-files /data/mysql_data
* 重命名不使用系统自带 MySQL 配置文件 /etc/my.cnf [ debian类系统在 /etc/mysql/my.cnf ]
[[email protected] ~]# mv /etc/my.cnf{,.old}
* 初始化 [ 初始化完成后会自带随机密码在输出日志中 ]
* 版本小于MySQL 5.7.6 [ < 5.7.6 ]
[[email protected] ~]# /usr/local/mysql/bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data
* 版本大于或等于MySQL 5.7.6 [ >= 5.7.6 ]
* 初始化 并指定基本目录与数据存放目录
[[email protected] ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data 2017-06-23T20:13:52.827475Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2017-06-23T20:13:57.684349Z 0 [Warning] InnoDB: New log files created, LSN=45790 2017-06-23T20:13:58.435803Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2017-06-23T20:13:58.525266Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 7d8f2b79-5850-11e7-9dab-000c29f0b169. 2017-06-23T20:13:58.538505Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed‘ cannot be opened. 2017-06-23T20:13:58.543606Z 1 [Note] A temporary password is generated for [email protected]: Z91g%.6d&fay
* 开启 SSL 连接
[[email protected] ~]# /usr/local/mysql/bin/mysql_ssl_rsa_setup --user=mysql --user=mysql --basedir=/usr/local/mysql \
6. 创建启动脚本
* 复制启动脚本到service 服务管理目录下[ /etc/init.d ]
[[email protected] ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
* 修改mysql启动脚本 [ /et/init.d/mysqld ]
basedir= ==> basedir=/usr/local/mysql datadir= ==> datadir=/data/mysql_data
* 添加脚本执行权限
[[email protected] ~]# chmod +x /etc/init.d/mysqld
* 添加进service服务管理
[[email protected] ~]# chkconfig --add mysqld
7. 服务启动测试
* 启动 MySQL 服务
[[email protected] ~]# /etc/init.d/mysqld start Starting MySQL.Logging to ‘/data/mysql_data/MySQL.err‘. .. SUCCESS!
* 查看服务是否启动并监听端口 [默认3306]
[[email protected] ~]# netstat -lntp | grep 3306 tcp 0 0 :::3306 :::* LISTEN 20896/mysqld
8. 服务启动测试
* 通过自带mysql客户端连接 [ 使用初始化时输出的随机密码 ]
[[email protected] ~]# /usr/local/mysql/bin/mysql -p‘Z91g%.6d&fay‘ mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.18 Copyright (c) 2000, 2017, 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>
* 修改密码
mysql> set password = ‘123456‘; Query OK, 0 rows affected (0.00 sec)
* 重新使用密码连接
mysql> quit Bye [[email protected] ~]# /usr/local/mysql/bin/mysql -p‘123456‘ mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.7.18 MySQL Community Server (GPL) Copyright (c) 2000, 2017, 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>
9. 总结
以需求驱动技术,技术本身没有优略之分,只有业务之分。
本文出自 “sea” 博客,请务必保留此出处http://lisea.blog.51cto.com/5491873/1941607
以上是关于MySQL5.7--------基于CentOS6二进制包安装的主要内容,如果未能解决你的问题,请参考以下文章
基于Centos6.5的MySQL5.7.15二进制源码安装