一.删除原来安装的mysql

1.查询并删除

[root@1 /]# find / -name mysql
/usr/share/mysql
/usr/bin/mysql
[root@1 /]#  rm -rf /usr/share/mysql /usr/bin/mysql

2.删除配置文件

2.1删除mysql的配置文件(my.cnf文件)

[root@1 /]# rm -rf /etc/my.cnf

2.2删除 /etc/init.d/ 下跟mysql有关的全部文件

3. 删除mysql的用户和组

[root@1 /]# userdel mysql
userdel: user 'mysql' does not exis

到这里。mysql已经被删除完成,可以安装新的mysql了

二.安装步骤

1.进入mysql的安装目录

[root@1 /]# cd /usr/local

2.下载安装包两种方式:

方式一:官网下载:https://dev.mysql.com/downloads/mysql/5.7.html#downloads

方式二:通过linux的wget命令,服务器网速可以的话直接wget

[root@1 /]# wget https://dev.mysql.com//Downloads/MySQL-5.7/mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz

3.下载完后,先找到自己下载的 mysql包

[root@1 local]# ll /usr/local/

然后解压

[root@1 local]# tar -zxvf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz

重命名

[root@1 local]# mv mysql-5.7.31-linux-glibc2.12-x86_64 mysql

4.添加用户组mysql和用户mysql,并将其添加到mysql用户组中

[root@1 local]# groupadd mysql
[root@1 local]# useradd -r -g mysql mysql

注: useradd -r参数表示mysql用户是系统用户,不可用于登录系统。 useradd -g参数表示把mysql用户添加到mysql用户组中。

5.检查是否安装了 libaio

[root@1 local]# rpm -qa | grep libaio

如果没有安装,则执行:

[root@1 local]# yum search libaio
[root@1 local]# yum install -y libai

6.配置my.cnf文件

[root@1 local]# vim /etc/my.cnf

将下面内容拷进去

[mysql]  # 设置mysql客户端默认字符集  default-character-set=utf8   socket=/tmp/mysql.sock[mysqld]  #skip-name-resolve  #设置3306端口  port=3306   socket=/tmp/mysql.sock# 设置mysql的真正的安装目录 (看自己的是在哪里)basedir=/usr/local/mysql  # 设置mysql数据库的数据的存放目录 (看自己的是在哪里)datadir=/usr/local/mysql/data  # 允许最大连接数  max_connections=200  # 服务端使用的字符集默认为8比特编码的latin1字符雿 character-set-server=utf8  # 创建新表时将使用的默认存储引擿 default-storage-engine=INNODB  #lower_case_table_name=1  # 非必要
max_allowed_packet=16M
join_buffer_size = 128M
sort_buffer_size = 16M
read_rnd_buffer_size = 16M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
max_allowed_packet = 500000M

7.创建data文件夹(就是my.cnf中datadir 所指定的文件夹)

[root@1 mysql]# pwd
/usr/local/mysql
[root@1 mysql]# mkdir data

8.将mysql目录的所属用户和组改为mysql

[root@1 mysql]#  chown -R mysql:mysql ./

9.初始化mysqld 生成初始化密码(注意文件地址)

[root@1 mysql]# ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

输出为

2020-10-24T04:25:13.673365Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-10-24T04:25:15.808961Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-10-24T04:25:16.105505Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-10-24T04:25:16.184776Z 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: cec94f21-d744-11e8-a0b5-fa163ed8e403.
2020-10-24T04:25:16.188372Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-10-24T04:25:16.189074Z 1 [Note] A temporary password is generated for root@localhost: k;runXw2,2;r
[root@1 mysql]#

将打印信息最后一句的"root@localhost:" 后边的内容记录下来,这是第一次登陆mysql需要的密码(非常重要);

10.mysql配置

10.1 设置开机启动,复制mysql.server脚本到资源目录,并赋予执行权限

[root@1 mysql]# cp ./support-files/mysql.server /etc/rc.d/init.d/mysql.server
[root@1 mysql]# chmod +x /etc/rc.d/init.d/mysql.server

10.2:将 mysqld 服务加入到系统服务并检测是否生效:

[root@1 mysql]#  chkconfig --add mysql.server
[root@1 mysql]# chkconfig --list mysql.server

可以启动mysql了:

[root@1 mysql]#  service mysql.server start

11.配置环境变量

11.1 在 /etc/profile配置文件中,添加如下内容:

[root@1 mysql]#  vim  /etc/profile
#mysql环境变量PATH=$PATH:/usr/local/mysql/bin

11.2 执行命令,使etc/profile生效

[root@1 mysql]# source /etc/profile

11.3 校验是否成功:

[root@1 mysql]# echo $PATH
.:/usr/local/zk/bin:.:/usr/local/zk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/mysql/bin

12.初次登录 修改访问密码(第一次的密码就是 上边我让你记得密码,可以回去看下第9步)

[root@baidu64 mysql]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.31Copyright (c) 2017, 2020, 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>

修改登录密码:(为 ‘123456’)

mysql> SET PASSWORD = PASSWORD('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)
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 -ADatabase changed
mysql> update user set authentication_string=PASSWORD('123456') where User='root';
Query OK, 0 rows affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 0  Warnings: 1mysql>

13.允许远程访问

mysql> grant all privileges on *.* to root@"%" identified by "password" with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)mysql>

14.使用navicate远程连接报错
14.1关闭mysql服务

[root@1 mysql]# service mysql.server stopRedirecting to /bin/systemctl stop mysql.service

如果提示‘mysql unrecognized service’,则执行:

[root@1 mysql]#  cp ./support-files/mysql.server /etc/rc.d/init.d/mysql.server

然后执行:

[root@1 mysql]#   chmod +x /etc/rc.d/init.d/mysql.server

在执行:

[root@1 mysql]# service  mysql.server start

15.修改/etc/my.cnf修改为无密码登录

[root@1 mysql]# vim /etc/my.cnf

在my.cnf配置文件添加如下内容:

# mysql无密码登录
skip-grant-tables

16.重启mysql服务

[root@1 mysql]# service mysql.server restart
Redirecting to /bin/systemctl restart mysql.service

17.无密码登录mysql

[root@1 mysql]# mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.31 MySQL Community Server (GPL)Copyright (c) 2017, 2020, 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>

18.再次修改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 -ADatabase changed
mysql> update mysql.user set authentication_string=password('123456') where user='root' ;
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 2  Changed: 1  Warnings: 1mysql>

19.然后将my.cnf无密码登录配置去掉(就是上面刚加的那句话)

20.退出mysql,并重启:

mysql> quit
Bye
[root@1 mysql]# service mysql restart
Redirecting to /bin/systemctl restart mysql.service
[root@1 mysql]#

21.重新连接

相关链接:
mysql5.7.18安装教程
mysql5.7 yum安装

Linux.centos系统mysql5.7.31安装教程相关推荐

  1. linux通过yum安装vim,linux/centos系统如何使用yum安装vi/vim?

    linux/centos系统如何使用yum安装vi/vim? yum安装vim最简单的命令, yum -y install vim* 然后就可以使用vi命令了. 网上的文章: 要使用vim, 使用yu ...

  2. Linux/Unix系统下nginx+php安装简明教程

    本文转载自Linux/Unix系统下nginx+php安装简明教程,请保留转载信息~ 一.安装nginx: 1. 安装pcre库,nginx的rewrite模板需用到pcre库: mkdir -p / ...

  3. linux suse11安装包,SUSE Linux 11系统rpm包离线安装GCC

    SUSE Linux 11系统rpm包离线安装GCC 1.问题显示 编译失败 python2.6环境下编译pycrypto-2.6.1 src/hash_template.c:360: warning ...

  4. centos怎么汉化linux,linux centos 系统中文模式设置方法

    linux centos 系统中文模式设置方法 下面小编就为大家具体的介绍linux centos 系统怎么设置中文模式,方便大家阅读. 首先,需要安装一下linux桌面程序.一般系统有自带的桌面,然 ...

  5. suse linux 软件包安装,SUSE Linux 11系统rpm包离线安装GCC

    SUSE Linux 11系统rpm包离线安装GCC 1.问题显示 编译失败 python2.6环境下编译pycrypto-2.6.1 src/hash_template.c:360: warning ...

  6. Linux(centos)系统各个目录的作用详解

    转自:Linux(centos)系统各个目录的作用详解 现在公司的服务器使用CentOS系统,在网上找到了这篇介绍linux各个目录的文章,觉得十分不错,所以拿来存个档. 整理之后如下: 文件系统的类 ...

  7. linux CentOS 系统下如何将php和mysql命令加入到环境变量中

    在Linux CentOS系统上安装完php和MySQL后,为了使用方便,需要将php和mysql命令加到系统命令中,如果在没有添加到环境变量之前,执行"php -v"命令查看当前 ...

  8. linux环境怎么更新离线rpm包,SUSE Linux 11系统rpm包离线安装GCC

    SUSE Linux 11系统rpm包离线安装GCC 1.问题显示 编译失败 python2.6环境下编译pycrypto-2.6.1 src/hash_template.c:360: warning ...

  9. 方舟生存进化服务器Linux,Linux CentOS 方舟生存进化开服教程

    Linux CentOS 方舟生存进化开服教程 首页 > 技术教程 作者:青书's 2019年8月4日 6:59 星期日 热度:9955° 百度已收录 时间:2019-8-4 6:59 热度:9 ...

最新文章

  1. PyCharm为什么这么牛?
  2. 原生js实现触摸滚动轮播图
  3. 【学习笔记】Linux 命令万字解析(超详细)
  4. HZOJ 赤(CF739E Gosha is hunting)
  5. 第一章 SDN介绍 (附件3)【云计算,SDN,虚拟化三者关系】
  6. java内存shell_Springboot 内存shell
  7. android 360状态栏显示,Android高仿UC浏览器和360手机卫士消息常驻栏(通知栏)
  8. python os模块 os.chmod
  9. basys2数码管共阳还是共阴_如何判断PLC使用接近开关是PNP还是NPN?
  10. spark DataSet与DataFrame的区别
  11. canvas放射粒子效果
  12. python皮卡丘编程代码_儿童Python代码编程库Pygame Zero介绍
  13. 用DELPHI下载官方SVN中的示例原码
  14. H5 video 播放器demo代码
  15. 会员管理系统html,会员管理系统网页版
  16. 配置打印机共享时 报错 无法访问您可能没有权限使用网络资源
  17. 鼠标点击特效:canvas点击效果
  18. python爬虫爬微信数据可信吗_我用 Python 爬取微信好友,最后发现一个大秘密
  19. UITT 自动跟单系统
  20. SeekBarVolumizer.java

热门文章

  1. 模拟linux内核异常,Linux内核态缺页会发生什么 - 玩转Exception fixup表
  2. 大前端涉猎之前后端交互总结2:使用PHP进行表单数据上传与更新
  3. (十一)ApplicationContext详细介绍(上)
  4. 量子计算入门基础学习笔记(二 量子算符与张量)
  5. 一个有趣的关于setBackgroundColor问题
  6. RMS恢复-鲜为人知的坑
  7. 七牛云 QVM 「1 元上云」领取攻略 企业如何低成本上云必读
  8. json.cp37-win32.pyd HEUR/QVM30.2.223F.Malware...
  9. SequoiaDB巨杉数据库数据节点
  10. python variable explorer_在Spyder的Variable Explorer中查看局部变量