TShopping

 找回密碼
 註冊
搜索
查看: 2494|回復: 0

[CentOS] Centos7使用yum安裝MySQL5.6 及完整移除 MySQL 伺服器

[複製鏈接]
發表於 2019-9-5 22:20:41 | 顯示全部樓層 |閱讀模式
 
Push to Facebook
因為CentOS7.6改成MySQL 5.7版後,居然mysql資料庫下的user表下居然沒有password欄位,所以怎麼樣都無法設定root的密碼,指令 mysqladmin -u root password "newpassword" 居然無法使用,找了古歌大神之後,才發現必須降回MySQL5.6才行

改repo
  1. vi /etc/yum.repos.d/mysql-community.repo
複製代碼

[mysql56-community]

enable=1

[mysql57-community-dmr]

enable=0

存檔離開
2.png

伺服器端端

一,安裝
  1. //1.先安装带有可用的mysql5系列社区版资源的rpm包
  2. [root@iZ28gvqe4biZ ~]# rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
  3. 获取http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
  4. 准备中...                          ################################# [100%]
  5. 正在升级/安装...
  6.    1:mysql-community-release-el7-5    ################################# [100%]
複製代碼
  1. //2.查看当前可用的mysql安装资源
  2. [root@iZ28gvqe4biZ ~]# yum repolist enabled | grep "mysql.*-community.*"
  3. mysql-connectors-community/x86_64 MySQL Connectors Community                  17
  4. mysql-tools-community/x86_64      MySQL Tools Community                       31
  5. mysql56-community/x86_64          MySQL 5.6 Community Server                 199
複製代碼
  1. //3.使用yum的方式安装MySQL;
  2. //一般来说,只要安装mysql-server跟mysql-client
  3. [root@iZ28gvqe4biZ ~]# yum -y install mysql-community-server
  4. 已加载插件:langpacks
  5. 正在解决依赖关系
  6. --> 正在检查事务
  7. ---> 软件包 mysql-community-server.x86_64.0.5.6.28-2.el7 将被 安装
  8. --> 正在处理依赖关系 mysql-community-common(x86-64) = 5.6.28-2.el7,它被软件包 mysql-community-server-5.6.28-2.el7.x86_64 需要
  9. --> 正在处理依赖关系 mysql-community-client(x86-64) = 5.6.28-2.el7,它被软件包 mysql-community-server-5.6.28-2.el7.x86_64 需要
  10. --> 正在处理依赖关系 perl(DBI),它被软件包 mysql-community-server-5.6.28-2.el7.x86_64 需要
  11. --> 正在检查事务
  12. ---> 软件包 mysql-community-client.x86_64.0.5.6.28-2.el7 将被 安装
  13. --> 正在处理依赖关系 mysql-community-libs(x86-64) = 5.6.28-2.el7,它被软件包 mysql-community-client-5.6.28-2.el7.x86_64 需要
  14. ---> 软件包 mysql-community-common.x86_64.0.5.6.28-2.el7 将被 安装
  15. ---> 软件包 perl-DBI.x86_64.0.1.627-4.el7 将被 安装
  16. --> 正在处理依赖关系 perl(RPC::PlServer) >= 0.2001,它被软件包 perl-DBI-1.627-4.el7.x86_64 需要
  17. --> 正在处理依赖关系 perl(RPC::PlClient) >= 0.2000,它被软件包 perl-DBI-1.627-4.el7.x86_64 需要
  18. --> 正在检查事务
  19. ---> 软件包 mariadb-libs.x86_64.1.5.5.40-1.el7_0 将被 取代
  20. ---> 软件包 mysql-community-libs.x86_64.0.5.6.28-2.el7 将被 舍弃
  21. ---> 软件包 perl-PlRPC.noarch.0.0.2020-14.el7 将被 安装
  22. --> 正在处理依赖关系 perl(Net::Daemon) >= 0.13,它被软件包 perl-PlRPC-0.2020-14.el7.noarch 需要
  23. --> 正在处理依赖关系 perl(Net::Daemon::Test),它被软件包 perl-PlRPC-0.2020-14.el7.noarch 需要
  24. --> 正在处理依赖关系 perl(Net::Daemon::Log),它被软件包 perl-PlRPC-0.2020-14.el7.noarch 需要
  25. --> 正在处理依赖关系 perl(Compress::Zlib),它被软件包 perl-PlRPC-0.2020-14.el7.noarch 需要
  26. --> 正在检查事务
  27. ---> 软件包 perl-IO-Compress.noarch.0.2.061-2.el7 将被 安装
  28. --> 正在处理依赖关系 perl(Compress::Raw::Zlib) >= 2.061,它被软件包 perl-IO-Compress-2.061-2.el7.noarch 需要
  29. --> 正在处理依赖关系 perl(Compress::Raw::Bzip2) >= 2.061,它被软件包 perl-IO-Compress-2.061-2.el7.noarch 需要
  30. ---> 软件包 perl-Net-Daemon.noarch.0.0.48-5.el7 将被 安装
  31. --> 正在检查事务
  32. ---> 软件包 perl-Compress-Raw-Bzip2.x86_64.0.2.061-3.el7 将被 安装
  33. ---> 软件包 perl-Compress-Raw-Zlib.x86_64.1.2.061-4.el7 将被 安装
  34. --> 解决依赖关系完成

  35. 依赖关系解决

  36. ==============================================================================================
  37. Package                       架构         版本                源                       大小
  38. ==============================================================================================
  39. 正在安装:
  40. mysql-community-libs          x86_64       5.6.28-2.el7        mysql56-community       2.0 M
  41.       替换  mariadb-libs.x86_64 1:5.5.40-1.el7_0
  42. mysql-community-server        x86_64       5.6.28-2.el7        mysql56-community        58 M
  43. 为依赖而安装:
  44. mysql-community-client        x86_64       5.6.28-2.el7        mysql56-community        19 M
  45. mysql-community-common        x86_64       5.6.28-2.el7        mysql56-community       256 k
  46. perl-Compress-Raw-Bzip2       x86_64       2.061-3.el7         base                     32 k
  47. perl-Compress-Raw-Zlib        x86_64       1:2.061-4.el7       base                     57 k
  48. perl-DBI                      x86_64       1.627-4.el7         base                    802 k
  49. perl-IO-Compress              noarch       2.061-2.el7         base                    260 k
  50. perl-Net-Daemon               noarch       0.48-5.el7          base                     51 k
  51. perl-PlRPC                    noarch       0.2020-14.el7       base                     36 k

  52. 事务概要
  53. ==============================================================================================
  54. 安装  2 软件包 (+8 依赖软件包)

  55. 总下载量:80 M
  56. Downloading packages:
  57. 警告:/var/cache/yum/x86_64/7/mysql56-community/packages/mysql-community-common-5.6.28-2.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
  58. mysql-community-common-5.6.28-2.el7.x86_64.rpm 的公钥尚未安装
  59. (1/10): mysql-community-common-5.6.28-2.el7.x86_64.rpm                 | 256 kB  00:00:14     
  60. (2/10): mysql-community-libs-5.6.28-2.el7.x86_64.rpm                   | 2.0 MB  00:02:57     
  61. (3/10): perl-Compress-Raw-Zlib-2.061-4.el7.x86_64.rpm                  |  57 kB  00:00:00     
  62. (4/10): perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64.rpm                 |  32 kB  00:00:00     
  63. (5/10): perl-IO-Compress-2.061-2.el7.noarch.rpm                        | 260 kB  00:00:00     
  64. (6/10): perl-Net-Daemon-0.48-5.el7.noarch.rpm                          |  51 kB  00:00:00     
  65. (7/10): perl-PlRPC-0.2020-14.el7.noarch.rpm  
  66. (8/10): perl-DBI-1.627-4.el7.x86_64.rpm                                | 802 kB  00:00:00     
  67. (9/10): mysql-community-server-5.6.28-2.el7.x86_64.rpm                 |  58 MB  00:54:45     
  68. (10/10): mysql-community-client-5.6.28-2.el7.x86_64.rpm                |  19 MB  00:20:42     
  69. 总计                                                           13 kB/s |  80 MB  01:45:50     
  70. 从 file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql 检索密钥
  71. 导入 GPG key 0x5072E1F5:
  72. 用户ID     : "MySQL Release Engineering <[url=mailto:mysql-build@oss.oracle.com]mysql-build@oss.oracle.com[/url]>"
  73. 指纹       : a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
  74. 软件包     : mysql-community-release-el7-5.noarch (installed)
  75. 来自       : file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
  76. Running transaction check
  77. Running transaction test
  78. Transaction test succeeded
  79. Running transaction
  80. 警告:RPM 数据库已被非 yum 程序修改。
  81.   正在安装    : mysql-community-common-5.6.28-2.el7.x86_64                               1/11
  82.   正在安装    : mysql-community-libs-5.6.28-2.el7.x86_64                                 2/11
  83.   正在安装    : mysql-community-client-5.6.28-2.el7.x86_64                               3/11
  84.   正在安装    : 1:perl-Compress-Raw-Zlib-2.061-4.el7.x86_64                              4/11
  85.   正在安装    : perl-Net-Daemon-0.48-5.el7.noarch                                        5/11
  86.   正在安装    : perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64                               6/11
  87.   正在安装    : perl-IO-Compress-2.061-2.el7.noarch                                      7/11
  88.   正在安装    : perl-PlRPC-0.2020-14.el7.noarch                                          8/11
  89.   正在安装    : perl-DBI-1.627-4.el7.x86_64                                              9/11
  90.   正在安装    : mysql-community-server-5.6.28-2.el7.x86_64                              10/11
  91.   正在删除    : 1:mariadb-libs-5.5.40-1.el7_0.x86_64                                    11/11
  92.   验证中      : perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64                               1/11
  93.   验证中      : perl-Net-Daemon-0.48-5.el7.noarch                                        2/11
  94.   验证中      : mysql-community-common-5.6.28-2.el7.x86_64                               3/11
  95.   验证中      : perl-IO-Compress-2.061-2.el7.noarch                                      4/11
  96.   验证中      : mysql-community-libs-5.6.28-2.el7.x86_64                                 5/11
  97.   验证中      : mysql-community-client-5.6.28-2.el7.x86_64                               6/11
  98.   验证中      : 1:perl-Compress-Raw-Zlib-2.061-4.el7.x86_64                              7/11
  99.   验证中      : perl-DBI-1.627-4.el7.x86_64                                              8/11
  100.   验证中      : mysql-community-server-5.6.28-2.el7.x86_64                               9/11
  101.   验证中      : perl-PlRPC-0.2020-14.el7.noarch                                         10/11
  102.   验证中      : 1:mariadb-libs-5.5.40-1.el7_0.x86_64                                    11/11

  103. 已安装:
  104.   mysql-community-libs.x86_64 0:5.6.28-2.el7   mysql-community-server.x86_64 0:5.6.28-2.el7  

  105. 作为依赖被安装:
  106.   mysql-community-client.x86_64 0:5.6.28-2.el7  mysql-community-common.x86_64 0:5.6.28-2.el7
  107.   perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7  perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7  
  108.   perl-DBI.x86_64 0:1.627-4.el7                 perl-IO-Compress.noarch 0:2.061-2.el7        
  109.   perl-Net-Daemon.noarch 0:0.48-5.el7           perl-PlRPC.noarch 0:0.2020-14.el7            

  110. 替代:
  111.   mariadb-libs.x86_64 1:5.5.40-1.el7_0                                                        

  112. 完毕!
複製代碼

一,配置
  1. //加入开机启动
  2. [root@iZ28gvqe4biZ ~]# systemctl enable mysqld
複製代碼
  1. //启动mysql服务进程
  2. [root@iZ28gvqe4biZ ~]# systemctl start mysqld
複製代碼

Centos yum MySQL

Centos yum MySQL

  1. //重置密码
  2. [root@iZ28gvqe4biZ ~]# mysql_secure_installation

  3. NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
  4.       SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

  5. In order to log into MySQL to secure it, we'll need the current
  6. password for the root user.  If you've just installed MySQL, and
  7. you haven't set the root password yet, the password will be blank,
  8. so you should just press enter here.

  9. Enter current password for root (enter for none):
  10. OK, successfully used password, moving on...

  11. Setting the root password ensures that nobody can log into the MySQL
  12. root user without the proper authorisation.

  13. Set root password? [Y/n] y        [设置root用户密码]
  14. New password:
  15. Re-enter new password:
  16. Password updated successfully!
  17. Reloading privilege tables..
  18. ... Success!


  19. By default, a MySQL installation has an anonymous user, allowing anyone
  20. to log into MySQL without having to have a user account created for
  21. them.  This is intended only for testing, and to make the installation
  22. go a bit smoother.  You should remove them before moving into a
  23. production environment.

  24. Remove anonymous users? [Y/n] y            [删除匿名用户]
  25. ... Success!

  26. Normally, root should only be allowed to connect from 'localhost'.  This
  27. ensures that someone cannot guess at the root password from the network.

  28. Disallow root login remotely? [Y/n] n            [禁止root远程登录]
  29. ... skipping.

  30. By default, MySQL comes with a database named 'test' that anyone can
  31. access.  This is also intended only for testing, and should be removed
  32. before moving into a production environment.

  33. Remove test database and access to it? [Y/n] y       [删除test数据库]
  34. - Dropping test database...
  35. ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist
  36. ... Failed!  Not critical, keep moving...
  37. - Removing privileges on test database...
  38. ... Success!

  39. Reloading the privilege tables will ensure that all changes made so far
  40. will take effect immediately.

  41. Reload privilege tables now? [Y/n] y        [刷新权限]
  42. ... Success!


  43. All done!  If you've completed all of the above steps, your MySQL
  44. installation should now be secure.

  45. Thanks for using MySQL!

  46. Cleaning up...
複製代碼

示例:新建測試數據庫
  1. //登录MYSQL(有ROOT权限)。这里我以ROOT身份登录
  2. [root@iZ28gvqe4biZ ~]# mysql -u root -p
  3. //修改访问权限,让其他计算机也能访问
  4. GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'yourpassword' WITH GRANT OPTION;
  5. //首先为用户创建一个数据库hivemeta
  6. mysql  > create database test;
  7. mysql  > use test
  8. //授权hdp用户拥有hivemeta数据库的所有权限。
  9. mysql  > grant all privileges on *.* to cgq@"%" identified by "yckj" with grant option;
  10. //刷新系统权限表
  11. mysql  > flush privileges;
  12. mysql  > use test;
  13. //mysql/hive字符集问题
  14. mysql  > alter database test character set latin1;

  15. 测试连接......
複製代碼


RHEL / CentOS 完整移除 MySQL 伺服器


以下文章會示範在 RHEL 及 CentOS 下完整移除 MySQL 伺服器, 如果 MySQL 的資料還有用, 在開始前務必要先備份 MySQL 的資料。

首先檢查安裝在系統的 MySQL 相關套件, 可以用 rpm 或 yum 指令查看:


  1. # rpm -qa | grep mysql
  2. mysql-libs-5.1.73-5.el6_6.x86_64
  3. mysql-server-5.1.73-5.el6_6.x86_64
  4. mysql-5.1.73-5.el6_6.x86_64
複製代碼




  
  1. # yum list installed | grep mysql
複製代碼

知道了安裝在系統的 MySQL 相關套件後, 用 YUM 移除:

  1. # yum remove mysql-libs mysql-server mysql-client mysql
複製代碼

移除了 MySQL 的相關套件後, 接著是把資料庫目錄及 my.cnf 移除:

  1. # rm -rf /var/lib/mysql/
  2. # rm -rf /etc/my.cnf
複製代碼

這時已經完整地從系統移除 MySQL 了。
參考文章
https://www.jianshu.com/p/481763139ef2
https://www.opencli.com/linux/rhel-centos-remove-mysql-server

 

臉書網友討論
*滑块验证:
您需要登錄後才可以回帖 登錄 | 註冊 |

本版積分規則



Archiver|手機版|小黑屋|免責聲明|TShopping

GMT+8, 2024-3-29 18:23 , Processed in 0.054607 second(s), 26 queries .

本論壇言論純屬發表者個人意見,與 TShopping綜合論壇 立場無關 如有意見侵犯了您的權益 請寫信聯絡我們。

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表