MySQL5.7--------基于CentOS6二进制包安装

本文介绍MySQL5.7的安装步骤与配置方法,包括环境准备、安装过程及服务启动测试等内容。MySQL是一个广泛使用的关系型数据库管理系统,适用于多种平台。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 ]

wKioL1lOX5jQoVFpAAFaXeTnnpM723.jpg


3. MySQL安装方式

   * 二制包安装

   * 源码编译安装

   * 平台安装包,如rpm包[centos,redhat]或deb[debian,ubuntu]包


4. 环境 [关闭selinux]

1
2
3
4
5
6
7
8
9
10
11
[root@MySQL ~] # cat /etc/redhat-release 
CentOS release 6.9 (Final)
 
[root@MySQL ~] # uname -r
2.6.32-642.3.1.el6.x86_64
 
[root@MySQL ~] # hostname
MySQL
 
[root@MySQL ~] # getenforce 
Disabled


5. 安装 [ MySQL 5.7的安装方式与MySQL 5.5/5.6不劲相同 ]

   * 下载 MySQL5.7 二进制包 [ 推荐从MySQL官方下载 ]

1
[root@MySQL ~] # wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz


   * 解压 MySQL 5.7 二进制包

1
[root@MySQL ~] # tar zxvf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz


   * 移动 MySQL 5.7 二进制包

1
[root@MySQL ~] # mv mysql-5.7.18-linux-glibc2.5-x86_64 /usr/local/


   * 创建软链接

1
[root@MySQL ~] # ln -s /usr/local/mysql-5.7.18-linux-glibc2.5-x86_64 /usr/local/mysql


   * 创建 mysql 用户

1
[root@MySQL ~] # useradd -r -s /sbin/nologin mysql


   * 创建 MySQL 数据存放目录

1
2
3
[root@MySQL ~] # mkdir -vp /data/mysql_data
mkdir : created directory ` /data '
mkdir : created directory ` /data/mysql_data '


   * 在 MySQL 二进制包目录中创建 mysql-files 目录 [MySQL 数据导入/导出数据专放目录]

1
2
[root@MySQL ~] # mkdir -v /usr/local/mysql/mysql-files
mkdir : created directory ` /usr/local/mysql/mysql-files '


   * 修改 MySQL 二进制包目录的所属用户与所属组

1
[root@MySQL ~] # chown root.mysql -R /usr/local/mysql-5.7.18-linux-glibc2.5-x86_64


   * 修改 MySQL 数据目录与 数据导入/导出专放目录的所属用户与所属组

1
[root@MySQL ~] # chown mysql.mysql /usr/local/mysql/mysql-files /data/mysql_data


   * 重命名不使用系统自带 MySQL 配置文件 /etc/my.cnf [ debian类系统在 /etc/mysql/my.cnf ]

1
[root@MySQL ~] # mv /etc/my.cnf{,.old}


   * 初始化 [ 初始化完成后会自带随机密码在输出日志中 ]

     * 版本小于MySQL 5.7.6 [ < 5.7.6 ]

1
2
3
4
[root@MySQL ~] # /usr/local/mysql/bin/mysql_install_db \
--user=mysql \
--basedir= /usr/local/mysql  \
--datadir= /data/mysql_data

 

     * 版本大于或等于MySQL 5.7.6 [ >= 5.7.6 ]

     * 初始化 并指定基本目录与数据存放目录

1
2
3
4
5
6
7
8
9
10
[root@MySQL ~] # /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  root@localhost: Z91g%.6d&fay

     * 开启 SSL 连接 

1
2
3
[root@MySQL ~] # /usr/local/mysql/bin/mysql_ssl_rsa_setup --user=mysql \
--user=mysql \
--basedir= /usr/local/mysql  \

6. 创建启动脚本

   * 复制启动脚本到service 服务管理目录下[ /etc/init.d ]

1
[root@MySQL ~] # cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld


   * 修改mysql启动脚本 [ /et/init.d/mysqld ]

1
2
basedir=    ==> basedir= /usr/local/mysql
datadir=    ==> datadir= /data/mysql_data


   * 添加脚本执行权限

1
[root@MySQL ~] # chmod +x /etc/init.d/mysqld


   * 添加进service服务管理

1
[root@MySQL ~] # chkconfig --add mysqld


7. 服务启动测试

   * 启动 MySQL 服务

1
2
3
[root@MySQL ~] # /etc/init.d/mysqld start
Starting MySQL.Logging to  '/data/mysql_data/MySQL.err' .
.. SUCCESS!


   * 查看服务是否启动并监听端口 [默认3306]

1
2
[root@MySQL ~] # netstat -lntp | grep 3306
tcp        0      0 :::3306             :::*                LISTEN      20896 /mysqld


8. 服务启动测试

   * 通过自带mysql客户端连接 [ 使用初始化时输出的随机密码 ]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@MySQL ~] # /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>

   * 修改密码

1
2
mysql>  set  password =  '123456' ;
Query OK, 0 rows affected (0.00 sec)

   * 重新使用密码连接

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
mysql> quit
Bye
[root@MySQL ~] # /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. 总结


以需求驱动技术,技术本身没有优略之分,只有业务之分。



      本文转自asd1123509133 51CTO博客,原文链接:http://blog.51cto.com/lisea/1941607,如需转载请自行联系原作者



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值