当前位置:Gxlcms > 数据库问题 > Mysql 卸载 安装 全过程

Mysql 卸载 安装 全过程

时间:2021-07-01 10:21:17 帮助过:5人阅读

  1. https://dev.mysql.com/downloads/file/?id=469494

2. 确认OS版本

  1. # more /etc/issue
  2. CentOS release 6.7 (Final)
  3. Kernel \r on an \m
  1. # lsb_release -a
  2. LSB Version:    :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
  3. Distributor ID: CentOS
  4. Description:    CentOS release 6.7 (Final)
  5. Release:        6.7
  6. Codename:       Final

3. 根据OS版本,找到需要下载的Mysql版本,右键“将链接另存为”,即可获得下载地址

技术分享

4. 到Linux下,通过wget下载

  1. wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-server-5.7.18-1.el6.x86_64.rpm

下面三个rpm包存在依赖关系,也需要下载

  1. # wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-community-common-5.7.18-1.el6.x86_64.rpm
  2. # wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-community-client-5.7.18-1.el6.x86_64.rpm
  3. # wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-community-libs-5.7.18-1.el6.x86_64.rpm

5. 检查查询发现,已经安装Mysql-5.1.73,版本非常低。必须重新安装,当前最新版本是5.7

  1. # rpm -qa | grep mysql
  2. mysql-server-5.1.73-5.el6_6.x86_64
  3. mysql-libs-5.1.73-5.el6_6.x86_64
  4. mysql-5.1.73-5.el6_6.x86_64
  5. mysql-connector-odbc-5.1.5r1144-7.el6.x86_64

6. 准备安装,安装前,就怀疑,会不会覆盖?会不会冲突?安装一下试试,就知道了。

同时安装4个rpm包

  1. # rpm -ivh  mysql-community-server-5.7.18-1.el6.x86_64.rpm mysql-community-client-5.7.18-1.el6.x86_64.rpm  mysql-community-common-5.7.18-1.el6.x86_64.rpm mysql-community-libs-5.7.18-1.el6.x86_64.rpm

7. 果然冲突了

  1. warning: mysql-community-server-5.7.18-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
  2. Preparing...                ########################################### [100%]
  3. file /usr/share/mysql/czech/errmsg.sys from install of mysql-community-common-5.7.18-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
  4. file /usr/share/mysql/danish/errmsg.sys from install of mysql-community-common-5.7.18-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
  5. file /usr/share/mysql/dutch/errmsg.sys from install of mysql-community-common-5.7.18-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
  6. file /usr/share/mysql/english/errmsg.sys from install of mysql-community-common-5.7.18-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
  7. file /usr/share/mysql/estonian/errmsg.sys from install of mysql-community-common-5.7.18-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
  8. ......

8. 经过查询,也安装失败了,还是5.1.73版本

  1. # rpm -qa|grep mysql
  2. mysql-server-5.1.73-5.el6_6.x86_64
  3. mysql-libs-5.1.73-5.el6_6.x86_64
  4. mysql-5.1.73-5.el6_6.x86_64
  5. mysql-connector-odbc-5.1.5r1144-7.el6.x86_64

9. 开始卸载原有的5.1.73的Mysql,几种卸载方式,首推YUM方式卸载

  1. # yum remove mysql
  2. # rpm -e mysql  // 普通删除模式 
  3. # rpm -e --nodeps mysql  // 强力删除模式,如果使用上面命令删除时,提示有依赖的其它文件,则用该命令可以对其进行强力删除

10 .还剩余下面两个包

  1. # rpm -qa|grep mysql
  2. mysql-libs-5.1.73-5.el6_6.x86_64
  3. mysql-connector-odbc-5.1.5r1144-7.el6.x86_64

11. 执行yum localinstall安装,发现需要卸载mysql-libs-5.1.73-5.el6_6.x86_64,通过yun卸载这个包后,可以安装了。

  1. # yum localinstall mysql-community-server-5.7.18-1.el6.x86_64.rpm mysql-community-client-5.7.18-1.el6.x86_64.rpm mysql-community-common-5.7.18-1.el6.x86_64.rpm  mysql-community-libs-5.7.18-
  2. 1.el6.x86_64.rpm
  3. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. Loaded plugins: fastestmirror, refresh-packagekit, security
  5. Setting up Local Package Process
  6. Examining mysql-community-server-5.7.18-1.el6.x86_64.rpm: mysql-community-server-5.7.18-1.el6.x86_64
  7. Marking mysql-community-server-5.7.18-1.el6.x86_64.rpm to be installed
  8. Loading mirror speeds from cached hostfile
  9. * base: mirrors.163.com
  10. * extras: mirrors.cn99.com
  11. * updates: mirrors.163.com
  12. Examining mysql-community-client-5.7.18-1.el6.x86_64.rpm: mysql-community-client-5.7.18-1.el6.x86_64
  13. Marking mysql-community-client-5.7.18-1.el6.x86_64.rpm to be installed
  14. Examining mysql-community-common-5.7.18-1.el6.x86_64.rpm: mysql-community-common-5.7.18-1.el6.x86_64
  15. Marking mysql-community-common-5.7.18-1.el6.x86_64.rpm to be installed
  16. Examining mysql-community-libs-5.7.18-1.el6.x86_64.rpm: mysql-community-libs-5.7.18-1.el6.x86_64
  17. Marking mysql-community-libs-5.7.18-1.el6.x86_64.rpm to be installed
  18. Resolving Dependencies
  19. --> Running transaction check
  20. ---> Package mysql-community-client.x86_64 0:5.7.18-1.el6 will be installed
  21. ---> Package mysql-community-common.x86_64 0:5.7.18-1.el6 will be installed
  22. ---> Package mysql-community-libs.x86_64 0:5.7.18-1.el6 will be installed
  23. ---> Package mysql-community-server.x86_64 0:5.7.18-1.el6 will be installed
  24. --> Finished Dependency Resolution
  25. Dependencies Resolved
  26. ==================================================================================================================================
  27. Package                         Arch            Version               Repository                                            Size
  28. ==================================================================================================================================
  29. Installing:
  30. mysql-community-client          x86_64          5.7.18-1.el6          /mysql-community-client-5.7.18-1.el6.x86_64          100 M
  31. mysql-community-common          x86_64          5.7.18-1.el6          /mysql-community-common-5.7.18-1.el6.x86_64          2.5 M
  32. mysql-community-libs            x86_64          5.7.18-1.el6          /mysql-community-libs-5.7.18-1.el6.x86_64            8.9 M
  33. mysql-community-server          x86_64          5.7.18-1.el6          /mysql-community-server-5.7.18-1.el6.x86_64          769 M
  34. Transaction Summary
  35. ==================================================================================================================================
  36. Install       4 Package(s)
  37. Total size: 880 M
  38. Installed size: 880 M
  39. Is this ok [y/N]: y
  40. Downloading Packages:
  41. Running rpm_check_debug
  42. Running Transaction Test
  43. Transaction Test Succeeded
  44. Running Transaction
  45. Installing : mysql-community-common-5.7.18-1.el6.x86_64                                                                     1/4
  46. Installing : mysql-community-libs-5.7.18-1.el6.x86_64                                                                       2/4
  47. Installing : mysql-community-client-5.7.18-1.el6.x86_64                                                                     3/4
  48. Installing : mysql-community-server-5.7.18-1.el6.x86_64                                                                     4/4
  49. Verifying  : mysql-community-server-5.7.18-1.el6.x86_64                                                                     1/4
  50. Verifying  : mysql-community-libs-5.7.18-1.el6.x86_64                                                                       2/4
  51. Verifying  : mysql-community-common-5.7.18-1.el6.x86_64                                                                     3/4
  52. Verifying  : mysql-community-client-5.7.18-1.el6.x86_64                                                                     4/4
  53. Installed:
  54. mysql-community-client.x86_64 0:5.7.18-1.el6                    mysql-community-common.x86_64 0:5.7.18-1.el6
  55. mysql-community-libs.x86_64 0:5.7.18-1.el6                      mysql-community-server.x86_64 0:5.7.18-1.el6
  56. Complete!

12. 最后检查,已经安装成功

  1. # rpm -qa|grep mysql
  2. mysql-community-client-5.7.18-1.el6.x86_64
  3. mysql-community-libs-5.7.18-1.el6.x86_64
  4. mysql-community-common-5.7.18-1.el6.x86_64
  5. mysql-community-server-5.7.18-1.el6.x86_64

13. 安装完成,但是启动的时候遇到了问题:

  1. # service mysqld restart
  2. Stopping mysqld:                                           [  OK  ]
  3. Initializing MySQL database:  2017-07-11T15:23:50.462866Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
  4. 2017-07-11T15:23:50.465315Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
  5. 2017-07-11T15:23:50.465365Z 0 [ERROR] Aborting
  6. [FAILED]

14. 百度的解决方法(是由于之前老版本的数据库已经占用这个文件夹,需要清空,或者在/etc/my.cnf中重新指定--datadir

保证 --datadir目录为空。 /usr/local/var/mysql 这个目录


15. 启动成功

  1. # cd /var/lib/mysql
  2. # ls
  3. auto.cnf  ib_buffer_pool  ibdata1  ib_logfile0  ib_logfile1
  4. # rm *
  5. rm: remove regular file `auto.cnf‘? y
  6. rm: remove regular file `ib_buffer_pool‘? y
  7. rm: remove regular file `ibdata1‘? y
  8. rm: remove regular file `ib_logfile0‘? y
  9. rm: remove regular file `ib_logfile1‘? y

# service mysqld restart

  1. Stopping mysqld:                                           [  OK  ]
  2. Initializing MySQL database:                               [  OK  ]
  3. Installing validate password plugin:                       [  OK  ]
  4. Starting mysqld:                                           [  OK  ]

# ps -ef|grep mysql

  1. root      4533     1  0 23:25 pts/0    00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysql
  2. mysql     4727  4533  4 23:25 pts/0    00:00:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
  3. root      4762  3752  0 23:25 pts/0    00:00:00 grep mysql

16. 然而启动的过程中,又遇到一些问题,密码不知道了,重置密码

  1. # mysql -u root
  2. ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO)
  3. [root@test mysql]# mysql -u root -p
  4. Enter password:
  5. ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)

编辑mysql配置文件/etc/my.cnf,在[mysqld]这个条目下加入 skip-grant-tables 保存退出后重启mysql

# vi /etc/my.cnf

  1. [root@test mysql]# service mysqld restart
  2. Stopping mysqld:                                           [  OK  ]
  3. Starting mysqld:                                           [  OK  ]

# mysql

  1. Welcome to the MySQL monitor.  Commands end with ; or \g.
  2. Your MySQL connection id is 4
  3. Server version: 5.7.18 MySQL Community Server (GPL)
  4. Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
  5. Oracle is a registered trademark of Oracle Corporation and/or its
  6. affiliates. Other names may be trademarks of their respective
  7. owners.
  8. Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
  9. mysql> show databases;
  10. +--------------------+
  11. | Database           |
  12. +--------------------+
  13. | information_schema |
  14. | mysql              |
  15. | performance_schema |
  16. | sys                |
  17. +--------------------+
  18. 4 rows in set (0.00 sec)

设置密码,然后删除/etc/my.cnf中的 skip-grant-tables

再次重启mysql

  1. mysql> use mysql;
  2. Database changed

--.给root用户设置新密码: 

5.7版本之前:

  1. mysql> update user set password=password("新密码") where user="root";
  2. Query OK, 1 rows affected (0.01 sec)
  3. Rows matched: 1 Changed: 1 Warnings: 0

在5.7版本之后,mysql数据库下已经没有password这个字段了,password字段改成了authentication_string。

  1. update mysql.user set authentication_string=PASSWORD(‘oracle‘) where User=‘root‘;
  1. mysql> flush privileges;
  2. Query OK, 0 rows affected (0.00 sec)

---退出mysql,重启然后重新登录

  1. # service mysqld restart
  2. Stopping mysqld:                                           [  OK  ]
  3. Starting mysqld:                                           [  OK  ]

# mysql -uroot -poracle

  1. mysql: [Warning] Using a password on the command line interface can be insecure.
  2. Welcome to the MySQL monitor.  Commands end with ; or \g.
  3. Your MySQL connection id is 5
  4. Server version: 5.7.18
  5. Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
  6. Oracle is a registered trademark of Oracle Corporation and/or its
  7. affiliates. Other names may be trademarks of their respective
  8. owners.
  9. Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
  10. mysql>




本文出自 “小小狗窝” 博客,请务必保留此出处http://hsbxxl.blog.51cto.com/181620/1947164

Mysql 卸载 安装 全过程

标签:mysql   install   安装   

人气教程排行