服务器环境:

centos7 x64

需要安装mysql5.7+

一、卸载CentOS7系统自带mariadb

# 查看系统自带的Mariadb
[root@CDH-141 ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.44-2.el7.centos.x86_64
# 卸载系统自带的Mariadb
[root@CDH-141 ~]# rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64
# 删除etc目录下的my.cnf
[root@CDH-141 ~]# rm /etc/my.cnf

二、检查mysql是否存在

# 检查mysql是否存在
[root@CDH-141 ~]# rpm -qa | grep mysql
[root@CDH-141 ~]#

三、查看用户和组是否存在

1)检查mysql组合用户是否存在

# 检查mysql组和用户是否存在,如无则创建
[root@CDH-141 ~]# cat /etc/group | grep mysql
[root@CDH-141 ~]# cat /etc/passwd | grep mysql

# 查询全部用户(只是做记录,没必要执行)

[root@CDH-141 ~]# cat /etc/passwd|grep -v nologin|grep -v halt|grep -v shutdown|awk -F ":" '{print $1 "|" $3 "1" $4}' | more
root|010
sync|510
flume|9921989
hdfs|9911988
zookeeper|9891986
llama|9881985
httpfs|9871984
mapred|9861983
sqoop|9851982
yarn|9841981
kms|9831980
hive|9821979
oozie|9801977
hbase|9781975
impala|9761973
hue|9741971
wlaqzc2018|100111001
[root@CDH-141 mysql]#

2)若不存在,则创建mysql组和用户

# 创建mysql用户组
[root@CDH-141 ~]# groupadd mysql
# 创建一个用户名为mysql的用户,并加入mysql用户组
[root@CDH-141 ~]# useradd -g mysql mysql
# 制定password 为111111
[root@CDH-141 ~]# passwd mysql
Changing password for user mysql.
New password:
BAD PASSWORD: The password is a palindrome
Retype new password:
passwd: all authentication tokens updated successfully.

四、下载mysql离线安装包tar文件

官网下载地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads

版本选择,可以选择一下两种方式:

1)使用Red Hat Enterprise Linux
Select Version:5.7.25
Select Operating System:Red Hat Enterprise Linux / Oracle Linux
Select OS Version:Red Hat Enterprise Linux 7 / Oracle Linux 7 (x86, 64-bit)
列表中下载:
Compressed TAR Archive:(mysql-5.7.25-el7-x86_64.tar.gz)
2)使用Linux - Generic
Select Version:5.7.25
Select Operating System:Linux - Generic
Select OS Version:Linux - Generic (glibc 2.12) (x86, 64-bit)
列表中下载:
Compressed TAR Archive:(mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz)【本文中使用的是这个版本】
注意:上边两种方式找mysql离线安装包的方式都可以。

五、上传第四步下载的mysql TAR包

# 进入/usr/local/文件夹
[root@CDH-141 ~]# cd /usr/local/
# 上传mysql TAR包
[root@CDH-141 local]# rz
# 解压mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz
[root@CDH-141 local]# ls
bin full-path-to-mysql-VERSION-OS include lib64 mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz share
etc games lib libexec sbin src
[root@CDH-141 local]# tar -zxvf mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz
mysql-5.7.25-lin
...
mysql-5.7.25-linux-glibc2.12-x86_64/share/install_rewriter.sql
mysql-5.7.25-linux-glibc2.12-x86_64/share/uninstall_rewriter.sql
mysql-5.7.25-linux-glibc2.12-x86_64/support-files/magic
mysql-5.7.25-linux-glibc2.12-x86_64/support-files/mysql.server
mysql-5.7.25-linux-glibc2.12-x86_64/docs/INFO_BIN
mysql-5.7.25-linux-glibc2.12-x86_64/docs/INFO_SRC
[root@CDH-141 local]# ls
bin full-path-to-mysql-VERSION-OS include lib64 mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz share
etc games lib libexec mysql-5.7.25-linux-glibc2.12-x86_64 sbin src
# 进入/usr/local下,修改为mysql
[root@CDH-141 local]# mv mysql-5.7.25-linux-glibc2.12-x86_64 mysql
[root@CDH-141 local]# ls
bin etc full-path-to-mysql-VERSION-OS games include lib lib64 libexec mysql mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz sbin share src

六、更改所属的组和用户

# 更改所属的组和用户
[root@CDH-141 ~]# cd /usr/local/
[root@CDH-141 local]# chown -R mysql mysql/
[root@CDH-141 local]# chgrp -R mysql mysql/
[root@CDH-141 local]# cd mysql/
[root@CDH-141 mysql]# mkdir data
[root@CDH-141 mysql]# chown -R mysql:mysql data

七、在/etc下创建my.cnf文件

# 进入/usr/local/mysql文件夹下
[root@CDH-141 ~]# cd /usr/local/mysql
# 创建my.cnf文件
[root@CDH-141 mysql]# touch my.cnf #或者cd ''>my.conf
# 编辑my.cnf
[root@CDH-141 mysql]# vi my.conf
[mysql]
socket=/var/lib/mysql/mysql.sock
# set mysql client default chararter
default-character-set=utf8 [mysqld]
socket=/var/lib/mysql/mysql.sock
# set mysql server port
port = 3323 #默认是3306,这里发现3306已经被占用,因此防止这种情况发生,可以避免使用3306mysql默认端口
# set mysql install base dir
basedir=/usr/local/mysql
# set the data store dir
datadir=/usr/local/mysql/data
# set the number of allow max connnection
max_connections=200
# set server charactre default encoding
character-set-server=utf8
# the storage engine
default-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=16M
explicit_defaults_for_timestamp=true [mysql.server]
user=mysql
basedir=/usr/local/mysql
[root@CDH-141 mysql]#

八、进入mysql文件夹,并安装mysql

# 进入mysql
[root@CDH-141 local]# cd /usr/local/mysql
# 安装mysql
[root@CDH-141 mysql]# bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
2019-03-08 18:11:07 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2019-03-08 18:11:24 [WARNING] The bootstrap log isn't empty:
2019-03-08 18:11:24 [WARNING] 2019-03-08T10:11:07.208602Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead

设置文件及目录权限:

[root@CDH-141 mysql]# cp ./support-files/mysql.server /etc/init.d/mysqld
[root@CDH-141 mysql]# chown 777 my.cnf
[root@CDH-141 mysql]# ls
bin COPYING data docs include lib man my.cnf README share support-files
[root@CDH-141 mysql]# ls -l
total 60
drwxr-xr-x 2 root root 4096 Mar 8 15:56 bin
-rw-r--r-- 1 7161 31415 17987 Dec 21 18:39 COPYING
drwxr-x--- 5 mysql mysql 4096 Mar 8 16:21 data
drwxr-xr-x 2 root root 4096 Mar 8 15:56 docs
drwxr-xr-x 3 root root 4096 Mar 8 15:56 include
drwxr-xr-x 5 root root 4096 Mar 8 15:56 lib
drwxr-xr-x 4 root root 4096 Mar 8 15:56 man
-rw-r--r-- 1 777 root 516 Mar 8 16:19 my.cnf
-rw-r--r-- 1 7161 31415 2478 Dec 21 18:39 README
drwxr-xr-x 28 root root 4096 Mar 8 15:56 share
drwxr-xr-x 2 root root 4096 Mar 8 15:56 support-files
[root@CDH-141 mysql]# chmod +x /etc/init.d/mysqld
[root@CDH-141 mysql]#
[root@CDH-141 mysql]# mkdir data
[root@CDH-141 mysql]#
[root@CDH-141 mysql]# chown -R mysql:mysql data
[root@CDH-141 mysql]#

九、启动mysql

# 启动mysql
[root@CDH-141 mysql]# /etc/init.d/mysqld restart
MySQL server PID file could not be found![FAILED]
Starting MySQL.Logging to '/usr/local/mysql/data/CDH-141.err'.
..The server quit without updating PID file (/usr/local/mysql/data/CDH-141.pid).[FAILED]
[root@CDH-141 mysql]#

出现错误,解决方案如下:

#找到是否已经有进程占用
[root@CDH-141 mysql]# ps aux|grep mysql
root 32483 0.0 0.0 113252 1620 pts/0 S 18:04 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/CDH-141.pid
mysql 32684 0.1 0.1 1119892 178224 pts/0 Sl 18:04 0:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=CDH-141.err --pid-file=/usr/local/mysql/data/CDH-141.pid --port=3323
root 35137 0.0 0.0 112648 944 pts/0 S+ 18:12 0:00 grep --color=auto mysql #关闭进程
[root@CDH-141 mysql]# kill -9 32684
[root@CDH-141 mysql]# /usr/local/mysql/bin/mysqld_safe: line 198: 32684 Killed nohup /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=CDH-141.err --pid-file=/usr/local/mysql/data/CDH-141.pid --port=3323 < /dev/null > /dev/null 2>&1
#确认是否还占用
[root@CDH-141 mysql]# ps aux|grep mysql
root 35501 0.0 0.0 112644 948 pts/0 S+ 18:13 0:00 grep --color=auto mysql
[root@CDH-141 mysql]# /etc/init.d/mysqld restart
MySQL server PID file could not be found![FAILED]
Starting MySQL..[ OK ]
[root@CDH-141 mysql]# # 重启mysql
[root@CDH-141 mysql]# /etc/init.d/mysqld restart
Shutting down MySQL..[ OK ]
Starting MySQL..[ OK ]
[root@CDH-141 mysql]#

十、设置开机启动

#设置开机启动
[root@CDH-141 mysql]# chkconfig --level 35 mysqld on
[root@CDH-141 mysql]# chkconfig --list mysqld Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration. If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'. mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@CDH-141 mysql]# chmod +x /etc/rc.d/init.d/mysqld
[root@CDH-141 mysql]# chkconfig --add mysqld
[root@CDH-141 mysql]# chkconfig --list mysqld Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration. If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'. mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@CDH-141 mysql]# service mysqld status
MySQL running (26122)[ OK ]
[root@CDH-141 mysql]#

十一、修改配置文件

# 进入/etc/profile文件夹
[root@CDH-141 mysql]# vim /etc/profile
修改/etc/profile,在最后添加如下内容
# 修改/etc/profile文件
#set mysql environment
export PATH=$PATH:/usr/local/mysql/bin
# 使文件生效
[root@CDH-141 mysql]# source /etc/profile

十二、获得mysql初始密码

1)获得mysql初始密码

[root@CDH-141 mysql]#  cat /root/.mysql_secret
# Password set for user 'root@localhost' at 2019-03-08 17:40:42
poc3u0mO_luv
[root@CDH-141 mysql]#

2)修改密码

[root@CDH-141 mysql]# mysql -uroot -p
Enter password: #此处填写上边获取到的初始密码‘poc3u0mO_luv’
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.25 Copyright (c) 2000, 2015, 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 = PASSWORD('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec) mysql> exit
Bye

3)验证新密码是否登录成功:

[root@CDH-141 mysql]# mysql -uroot -p
Enter password: #此处输入新密码‘123456’
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.25 MySQL Community Server (GPL) Copyright (c) 2000, 2015, 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> show tables;
ERROR 1046 (3D000): No database selected
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec) mysql>

十三、添加远程访问权限

# 添加远程访问权限
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A Database changed
mysql> update user set host='%' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0 mysql> select host,user from user;
+-----------+---------------+
| host | user |
+-----------+---------------+
| % | root |
| localhost | mysql.session |
| localhost | mysql.sys |
+-----------+---------------+
3 rows in set (0.00 sec) mysql>

十四、重启mysql生效

# 重启mysql
[root@CDH-141 mysql]# /etc/init.d/mysqld restart
Shutting down MySQL..[ OK ]
Starting MySQL..[ OK ]
[root@CDH-141 mysql]#

参考《CentOS7.4安装配置mysql5.7 TAR免安装版

centos7下使用mysql离线安装包安装mysql5.7的更多相关文章

  1. centos7 二进制安装包安装 mysql5.6

    centos7 二进制安装包安装 mysql5.6 一.下载mysql5.6二进制安装包 http://mirrors.sohu.com/mysql/MySQL-5.6/ 如:mysql-5.6.34 ...

  2. mysql非安装包安装教程

    设置mysql的环境变量 本人设置安装的路径是:E:\WebApplication\webMySQL\mysql-5.7.13-winx64 我的电脑 ---> 高级系统配置 ---> 环 ...

  3. WIN10使用安装包安装Mysql5.6+JDBC

    很多教程教的是安装绿色版mysql或者是安装zip版的mysql,没什么不好,各有千秋,今天要教大家的是使用mysql-installer-community-5.6.43.0.msi安装mysql5 ...

  4. 省去在线安装 直接下载Chrome官方离线安装包

    首页>软件之家>便捷上网 省去在线安装 直接下载Chrome官方离线安装包 2013-10-12 23:22:02来源:IT之家 原创作者:阿象责编:阿象人气:54487 评论:19 谷歌 ...

  5. MySql(零):Linux(CentOS7)下安装和配置MySQL5.7.20(安装包安装)

    一.下载安装包 1.在官网下载MySQL5.7安装包 mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz. 下载地址:https://dev.mysql.com/do ...

  6. Windows下安装mysql(非安装包)

    Windows下安装mysql(非安装包) 参考:https://www.cnblogs.com/yunlongaimeng/p/12558638.html 1.下载MYSQL(慢的话可以用迅雷,或其 ...

  7. Office365完整离线安装包下载及自定义安装教程

    Office 365是微软打造的一款适用于教育机构使用的office办公软件,这里为大家提供了一个Office 365离线安装包下载工具,让office 365离线包下载到本地再安装,而不是联网下载安 ...

  8. centos 7.4 安装docker 19.03.6 版本。附带离线安装包

    说明: 1.此环境为未安装过docker服务的环境, 如果已经安装,则自行卸载. 2.以下环境中上传的包及离线yum源默认为/home目录下,如无特殊说明,以此目录为准 步骤一:下载docker离线安 ...

  9. Windows 10 Framework 3.5 _x64 离线安装包 最新安装版

    原文:http://www.jb51.net/softs/325481.html Windows 10 Framework 3.5 离线安装包,适用于 Win10 和 Server 2016 离线安装 ...

随机推荐

  1. JavaScript onmousewheel鼠标滚轮示例

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  2. 062 SparkStream内部原理

    1.DStream 内部是一系列的RDD组成的,每个RDD与RDD的产生时间形成一个pair保存在内存中(下面有) RDD包含了对应时间段的所有block数据. 2.DStream下的方法 /** T ...

  3. day16 函数的用法:内置函数,匿名函数

    思维导图需要补全 : 一共有68个内置函数: #内置:python自带 # def func(): # a = 1 # b = 2 # print(locals()) # print(globals( ...

  4. Java中菜单的实现以及画实线与画虚线之间的自由转化

    1.Java画线 1 import java.awt.Color; import java.awt.Container; import java.awt.Graphics; import java.a ...

  5. 【python】常用第三方模块

    No1: [Pillow]图像处理标准库 缩放 from PIL import Image # 打开一个jpg图像文件,注意是当前路径: im = Image.open('test.jpg') # 获 ...

  6. POJ 1904 King's Quest (强连通分量+完美匹配)

    <题目链接> 题目大意: 有n个王子,每个王子都有k个喜欢的妹子,每个王子只能和喜欢的妹子结婚,大臣给出一个匹配表,每个王子都和一个妹子结婚,但是国王不满意,他要求大臣给他另一个表,每个王 ...

  7. numpy 用于图像处理

    1. 转换为灰度图 灰度图的数据可以看成是二维数组,元素取值为0 ~ 255,其中,0为黑色,255为白色.从0到255逐渐由暗色变为亮色. 灰度图转换(ITU-R 601-2亮度变换): L = R ...

  8. java设计模式之-观察者模式(发布-订阅模式)

    1.观察者模式定义  观察者模式定义了一种一对多的依赖关系,让多个观察者对象同时监听某一个主题对象. 这个主题对象在状态上发生变化时,会通知所有观察者对象,让它们能够自动更新自己. 2.观察者模式结构 ...

  9. 一个简单需求:HashMap实现相同key存入数据后不被覆盖

    做一个积极的人 编码.改bug.提升自己 我有一个乐园,面向编程,春暖花开! 看似是一个简单的问题,其实里面包含很多的东西! 需求: 实现一个在HashMap中存入(任意类型)相同的key值后,key ...

  10. 按键排序JavaScript对象

    问题描述 我需要按键排序JavaScript对象. 因此如下: { 'b' : 'asdsad', 'c' : 'masdas', 'a' : 'dsfdsfsdf' } 会成为: { 'a' : ' ...