RHEL 7.2 安装 MySQL 5.7.11 二进制版

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介:

操作系统:rhel7.2 

MySQL版本:5.7.11

1、MySQL下载

  http://dev.mysql.com/downloads/

2、上传MySQL软件到操作系统

1
2
[root@rhel7 ~] # ls -l mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz 
-rw-r--r--. 1 root root 548193637 Dec  4 21:16 mysql-5.7.11-linux-glibc2.5-x86_64. tar .gz

3、添加mysql用户和组

1
2
3
4
[root@rhel7 ~] # groupadd mysql
[root@rhel7 ~] # useradd -r -g mysql -s /bin/false mysql
[root@rhel7 ~] # id mysql
uid=996(mysql) gid=1000(mysql)  groups =1000(mysql)

4、创建目录、改属组及解压文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@rhel7 ~] # mkdir -p /opt/mysql/
[root@rhel7 ~] # mkdir /mysqldata
[root@rhel7 ~] # mv /root/mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz /opt/mysql/
[root@rhel7 ~] # cd /opt/mysql/
[root@rhel7 mysql] # ls
mysql-5.7.11-linux-glibc2.5-x86_64. tar .gz
[root@rhel7 mysql] # tar -zxvf mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz 
......
[root@rhel7 mysql] # mv mysql-5.7.11-linux-glibc2.5-x86_64 mysql5.7.11
[root@rhel7 mysql] # ls -l
total 535352
drwxr-xr-x. 9 7161 wheel      4096 Feb  2  2016 mysql5.7.11
-rw-r--r--. 1 root root  548193637 Dec  4 21:16 mysql-5.7.11-linux-glibc2.5-x86_64. tar .gz
[root@rhel7 mysql] # chown mysql:mysql -R /opt/mysql/
[root@rhel7 mysql] # chown mysql:mysql -R /mysqldata/

5、初始化库

1
2
3
4
5
6
7
8
9
10
[root@rhel7 mysql] # cd mysql5.7.11/
[root@rhel7 mysql5.7.11] # ./bin/mysqld --initialize --user=mysql --basedir=/opt/mysql/mysql5.7.11/ --datadir=/mysqldata/
2016-12-04T13:33:01.318081Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation  for  more  details).
2016-12-04T13:33:01.729086Z 0 [Warning] InnoDB: New log files created, LSN=45790
2016-12-04T13:33:02.027182Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2016-12-04T13:33:02.111882Z 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: 2dca0cf3-ba26-11e6-b4ff-080027e818bc.
2016-12-04T13:33:02.118970Z 0 [Warning] Gtid table is not ready to be used. Table  'mysql.gtid_executed'  cannot be opened.
2016-12-04T13:33:02.120080Z 1 [Note] A temporary password is generated  for  root@localhost: rqwPw!9iNEEP
[root@rhel7 mysql5.7.11] # ls /mysqldata/
auto.cnf  ib_buffer_pool  ibdata1  ib_logfile0  ib_logfile1  mysql  performance_schema  sys

注意:root的初始密码已经在日志中给出:rqwPw!9iNEEP

在5.7.6之前的版本中使用bin/mysql_install_db --user=mysql初始化库。

6、启动MySQL数据库

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#替换系统自带的my.cnf文件
[root@rhel7 mysql5.7.11] # mv /etc/my.cnf /etc/my.cnf.bak
[root@rhel7 mysql5.7.11] # cp support-files/my-default.cnf /etc/my.cnf
#在my.cnf中添加如下两条
[root@rhel7 mysql5.7.11] # vi /etc/my.cnf
basedir =  /opt/mysql/mysql5 .7.11
datadir =  /mysqldata
#启动MySQL
[root@rhel7 mysql5.7.11] # ./bin/mysqld_safe --user=mysql &
[1] 1756
[root@rhel7 mysql5.7.11] # 2016-12-04T13:44:30.046089Z mysqld_safe Logging to '/mysqldata/rhel7.err'.
2016-12-04T13:44:30.097978Z mysqld_safe Starting mysqld daemon with databases from  /mysqldata
 
[root@rhel7 mysql5.7.11] # ps -ef |grep mysql
root      1756  1182  0 21:44 pts /0     00:00:00  /bin/sh  . /bin/mysqld_safe  --user=mysql
mysql     1876  1756  1 21:44 pts /0     00:00:00  /opt/mysql/mysql5 .7.11 /bin/mysqld  --basedir= /opt/mysql/mysql5 .7.11 --datadir= /mysqldata  --plugin- dir = /opt/mysql/mysql5 .7.11 /lib/plugin  --user=mysql --log-error= /m
ysqldata /rhel7 .err --pid- file = /mysqldata/rhel7 .pidroot      1905  1182  0 21:44 pts /0     00:00:00  grep  --color=auto mysql

7、登录MySQL,使用安装时给出密码登录并更改root密码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@rhel7 mysql5.7.11] # ./bin/mysql -uroot -p 
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection  id  is 2
Server version: 5.7.11
 
Copyright (c) 2000, 2016, 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>  set  password= '1qaz!QAZ' ;
Query OK, 0 rows affected (0.01 sec)

注意:5.6之前使用set password=password('newpassword')进行改密码,5.7版本不再建议这样改密码,会有如下提示:

1
2
3
4
5
6
7
8
9
10
mysql>  set  password=password( '123456' );
Query OK, 0 rows affected, 1 warning (0.00 sec)
 
mysql> show warnings;
+---------+------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Level   | Code | Message                                                                                                                                                           |
+---------+------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Warning | 1287 |  'SET PASSWORD = PASSWORD(' <plaintext_password> ')'  is deprecated and will be removed  in  a future release. Please use SET PASSWORD =  '<plaintext_password>'  instead |
+---------+------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row  in  set  (0.00 sec)

到此,MySQL5.7.11安装完成。

配置环境变量就可以方便使用了:

1
2
3
4
5
[root@rhel7 mysql5.7.11] # vi /root/.bash_profile
#添加
export  MYSQL_HOME= /opt/mysql/mysql5 .7.11
export  PATH=$MYSQL_HOME /bin :$PATH
[root@rhel7 mysql5.7.11] # source /root/.bash_profile

关闭MySQL

mysqladmin -uroot -p shutdown


官方文档:http://dev.mysql.com/doc/refman/5.7/en/binary-installation.html






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


相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
1天前
|
关系型数据库 MySQL Linux
Linux下安装MySQL
Linux下安装MySQL
8 0
|
1天前
|
SQL 分布式计算 关系型数据库
Ubuntu上安装MySQL以及hive
Ubuntu上安装MySQL以及hive
11 1
|
1天前
|
关系型数据库 MySQL 数据库
mysqlTools 一分钟部署安装本mysql多个版本,解锁繁琐部署过程
mysqlTools 一分钟部署安装本mysql多个版本,解锁繁琐部署过程
96 2
|
1天前
|
关系型数据库 MySQL Linux
本地虚拟机centos7通过docker安装主从mysql5.7.21
本地虚拟机centos7通过docker安装主从mysql5.7.21
18 0
|
1天前
|
关系型数据库 MySQL 数据库
龙蜥操作系统上安装MySQL:步骤详解与常见问题解决
龙蜥操作系统上安装MySQL:步骤详解与常见问题解决
|
1天前
|
关系型数据库 MySQL Linux
在Centos7中:通过Docker安装MySQL5.7(保姆级)
在Centos7中:通过Docker安装MySQL5.7(保姆级)
104 0
|
1天前
|
编解码 安全 关系型数据库
祝福CSDN的小伙伴2024年快乐!Windows7安装MySQL
祝福CSDN的小伙伴2024年快乐!Windows7安装MySQL
|
1天前
|
关系型数据库 MySQL Linux
Linux CentOs7 安装Mysql(5.7和8.0版本)密码修改 超详细教程
Linux CentOs7 安装Mysql(5.7和8.0版本)密码修改 超详细教程
|
1天前
|
安全 关系型数据库 MySQL
MySQL安装教程
MySQL安装教程
33 0
|
1天前
|
SQL 关系型数据库 MySQL
【简单无脑】自动化脚本一键安装虚拟机下的MySQL服务
该文章提供了在虚拟机上安装MySQL服务的简化方法,特别是针对新手。作者提供了一个自动化脚本`install_mysql.sh`,使得安装过程更简单。用户需要下载`install.rpm`资源,将其放在指定目录下,然后创建并编辑脚本文件,将提供的代码粘贴进去,通过`chmod u+x`授权,最后运行脚本`./install_mysql.sh [rpm文件路径]`来安装MySQL。文章还附有相关图片说明。
28 1
【简单无脑】自动化脚本一键安装虚拟机下的MySQL服务