当前位置:   article > 正文

Centos7安装mysql_root@localhost ~]# yum install -y mysql-community-

root@localhost ~]# yum install -y mysql-community-server 已加载插件:fastestm

自己琢磨了好几天装了一半又放弃,各种百度都是装一半不是这问题就是这个过期,总结一下截止今天安装成功记录一下:

1、下载安装Mysql官网的YumRepository

wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm

注意: 我是刚装好了Centos7就开始装Mysql遇到了问题如下

执行命令:

  1. [root@localhost ~]# yum -y install wget
  2. 已加载插件:fastestmirror
  3. base | 3.6 kB 00:00:00
  4. extras | 2.9 kB 00:00:00
  5. updates | 2.9 kB 00:00:00
  6. (1/4): base/7/x86_64/group_gz | 153 kB 00:00:00
  7. (2/4): extras/7/x86_64/primary_db | 249 kB 00:00:00
  8. (3/4): updates/7/x86_64/primary_db | 17 MB 00:00:03
  9. (4/4): base/7/x86_64/primary_db | 6.1 MB 00:00:25
  10. Determining fastest mirrors
  11. * base: mirrors.163.com
  12. * extras: mirrors.163.com
  13. * updates: mirrors.163.com
  14. 正在解决依赖关系
  15. --> 正在检查事务
  16. ---> 软件包 wget.x86_64.0.1.14-18.el7_6.1 将被 安装
  17. --> 解决依赖关系完成
  18. 依赖关系解决
  19. ==============================================================================================================================================================================
  20. Package 架构 版本 源 大小
  21. ==============================================================================================================================================================================
  22. 正在安装:
  23. wget x86_64 1.14-18.el7_6.1 base 547 k
  24. 事务概要
  25. ==============================================================================================================================================================================
  26. 安装 1 软件包
  27. 总下载量:547 k
  28. 安装大小:2.0 M
  29. Downloading packages:
  30. 警告:/var/cache/yum/x86_64/7/base/packages/wget-1.14-18.el7_6.1.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY ] 0.0 B/s | 337 kB --:--:-- ETA
  31. wget-1.14-18.el7_6.1.x86_64.rpm 的公钥尚未安装
  32. wget-1.14-18.el7_6.1.x86_64.rpm | 547 kB 00:00:00
  33. file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 检索密钥
  34. 导入 GPG key 0xF4A80EB5:
  35. 用户ID : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
  36. 指纹 : 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
  37. 软件包 : centos-release-7-4.1708.el7.centos.x86_64 (@anaconda)
  38. 来自 : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
  39. Running transaction check
  40. Running transaction test
  41. Transaction test succeeded
  42. Running transaction
  43. 正在安装 : wget-1.14-18.el7_6.1.x86_64 1/1
  44. 验证中 : wget-1.14-18.el7_6.1.x86_64 1/1
  45. 已安装:
  46. wget.x86_64 0:1.14-18.el7_6.1
  47. 完毕!
  48. [root@localhost ~]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
  49. [root@localhost ~]# sudo yum -y install wget
  50. 已加载插件:fastestmirror
  51. Loading mirror speeds from cached hostfile
  52. There are no enabled repos.
  53. Run "yum repolist all" to see the repos you have.
  54. To enable Red Hat Subscription Management repositories:
  55. subscription-manager repos --enable <repo>
  56. To enable custom repositories:
  57. yum-config-manager --enable <repo>
  58. [root@localhost ~]# yum clean all
  59. 已加载插件:fastestmirror
  60. Loading mirror speeds from cached hostfile
  61. There are no enabled repos.
  62. Run "yum repolist all" to see the repos you have.
  63. To enable Red Hat Subscription Management repositories:
  64. subscription-manager repos --enable <repo>
  65. To enable custom repositories:
  66. yum-config-manager --enable <repo>

安装成功后在执行:wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm

执行成功在执行:yum localinstall mysql57-community-release-el7-8.noarch.rpm -y

上面操作成功以后执行命令:

[root@localhost mysql-server]# yum install mysql-community-server -y

好家伙又出问题:

mysql-community-libs-compat-5.7.39-1.el7.x86_64.rpm 的公钥尚未安装


 失败的软件包是:mysql-community-libs-compat-5.7.39-1.el7.x86_64
 GPG  密钥配置为:file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

那就给他配置一个公钥:

  1. rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
  2. yum -y install mysql-community-server

结果如下:

好目前为止是下好Mysql了接下来启动Mysql

[root@localhost mysql-server]# systemctl start mysqld

查看MySQL运行状态,运行状态如图:

[root@localhost mysql-server]# systemctl status mysqld

目前为止Mysql终于可以正常跑起来了,Mysql要求是必须要重置密码,那就先找出当前root用户的密码,命令如下:

[root@localhost mysql-server]# grep "password" /var/log/mysqld.log

 然后进入Mysql数据库:

  1. [root@localhost mysql-server]# mysql -uroot -p
  2. Enter password: 输入上图框出来的初始密码即可

 现在要修改初始密码的刚刚也说了如果不修改初始密码是不能操作数据库的,上图框出来的就是当前查到的初始密码:

  1. mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '输入要修改的密码';
  2. //密码要求大小数字即符号组成

 修改成功如上图,开启远程方便后续想用Navicat连接数据库

grant all privileges on *.* to 'root'@'%' identified by 'password' with grant option;

%代表开启所有,可自行将%改为IP

  1. 然后再输入下面两行命令
  2. mysql> flush privileges;
  3. mysql> exit

 为firewalld添加开放端口

添加mysql端口3306和Tomcat端口8080

  1. [root@localhost ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
  2. [root@localhost ~]# firewall-cmd --zone=public --add-port=8080/tcp --permanent

重新开启

[root@localhost mysql-server]# firewall-cmd --reload

 配置成功以后需要把Mysql语言修改成Utf8

  1. [root@localhost mysql-server]# mysql -uroot -p //进入数据库
  2. Enter password: //输入密码
  3. Welcome to the MySQL monitor. Commands end with ; or \g.
  4. Your MySQL connection id is 3
  5. Server version: 5.7.39 MySQL Community Server (GPL)
  6. Copyright (c) 2000, 2022, Oracle and/or its affiliates.
  7. Oracle is a registered trademark of Oracle Corporation and/or its
  8. affiliates. Other names may be trademarks of their respective
  9. owners.
  10. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  11. mysql> status //查看
  12. --------------
  13. mysql Ver 14.14 Distrib 5.7.39, for Linux (x86_64) using EditLine wrapper
  14. Connection id: 3
  15. Current database:
  16. Current user: root@localhost
  17. SSL: Not in use
  18. Current pager: stdout
  19. Using outfile: ''
  20. Using delimiter: ;
  21. Server version: 5.7.39 MySQL Community Server (GPL)
  22. Protocol version: 10
  23. Connection: Localhost via UNIX socket
  24. Server characterset: latin1 //改成utf8
  25. Db characterset: latin1 //改成utf8
  26. Client characterset: utf8
  27. Conn. characterset: utf8
  28. UNIX socket: /var/lib/mysql/mysql.sock
  29. Uptime: 10 min 51 sec
  30. Threads: 1 Questions: 13 Slow queries: 0 Opens: 113 Flush tables: 1 Open tables: 106 Queries per second avg: 0.019
  31. --------------

exit退出Mysql,再到目录下修改对应内容

 将框起来的代码加上去保存更改然后退出:

注:此模式下操作命令如下

  1. 保存命令
  2. ESC键 跳到命令模式,然后:
  3. :w 保存文件但不退出vi
  4. :w file 将修改另外保存到file中,不退出vi
  5. :w! 强制保存,不推出vi
  6. :wq 保存文件并退出vi
  7. :wq! 强制保存文件,并退出vi
  8. :q 不保存文件,退出vi
  9. :q! 不保存文件,强制退出vi
  10. :e! 放弃所有修改,从上次保存文件开始再编辑

以上操作后在去查看

 到此为止Centos就安装及部署成功Mysql了!

接下来就是用Navicat连接Mysql啦:

查看当前的IP地址:输入ip addr 

2下面的就是当前的IP地址啦

然后打开Navicat

输入以下内容:

连接名:随意想起什么起什么

主机:就是刚刚Centos中查到的Ip地址 

端口:因为刚刚设置的端口为3306,如果你做别的修改就填你修改的

用户名:root

密码:就是刚刚修改的密码

 

到此为止就全部搞定了!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/爱喝兽奶帝天荒/article/detail/868074
推荐阅读
相关标签
  

闽ICP备14008679号