安装MySQL5.6

这里介绍一下为什么会用数据库,主要做什么用

一、卸载Mariadb

从 CentOS 7 系统开始,MariaDB 成为 yum 源中默认的数据库安装包。在 CentOS 7 及以上的系统中使用 yum 安装 MySQL 包将无法使用 MySQL。您可以选择使用完全兼容的 MariaDB,或依照本文介绍配置来继续使用 MySQL。

查看安装了mariadb相关的模块

[root@localhost ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.44-2.el7.centos.x86_64

然后进行卸载

[root@localhost ~]# rpm -e mariadb-libs-5.5.44-2.el7.centos.x86_64
error: Failed dependencies:
        libmysqlclient.so.18()(64bit) is needed by (installed) postfix-2:2.10.1-6.el7.x86_64
        libmysqlclient.so.18(libmysqlclient_18)(64bit) is needed by (installed) postfix-2:2.10.1-6.el7.x86_64

会提示有依赖于这的安装包,那么就强制卸载,不查检依赖:

[root@localhost ~]# rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64

将所有的mariadb安装包都删除,然后再次键入 rpm -qa | grep mariadb 查看是否卸载成功

二、卸载MySQL

为了防止重装,建议先卸载,可以操作以下命令

查看yum是否安装过mysql

yum list installed mysql*

查看mysql安装了哪些东西

rpm -qa | grep -i mysql

开始卸载,(这里只列两条,应该是卸载上面查询出来的结果!!)

yum remove mysql-community-common-5.7.20-1.el7.x86_64
yum remove mysql-community-client-5.7.20-1.el7.x86_64

查看是否卸载完成

[root@localhost ~]# rpm -qa | grep -i mysql
[root@localhost ~]#

查找mysql相关目录

[root@localhost ~]# find / -name mysql
/etc/selinux/targeted/active/modules/100/mysql

删除mysql相关目录(后面的地址,替换成查询返回的地址,有多条,顺序执行 rm -rf /*/*/*操作

[root@localhost ~]# rm -rf /etc/selinux/targeted/active/modules/100/mysql
[root@localhost ~]#

删除/etc/my.cnf

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

删除/var/log/mysqld.log(如果不删除这个文件,会导致新安装的mysql无法生存新密码,导致无法登录)

[root@localhost ~]# rm -rf /var/log/mysqld.log

三、安装MySQL

大家都知道,centos自带的repo是不会自动更新每个软件的最新版本,所以无法通过yum方式安装MySQL的高级版本。所以,即使我使劲用yum -y install mysql
mysql-server mysql-devel,也是没有人会鸟我的。
所以,正确的安装mysql5姿势是要先安装带有可用的mysql5系列社区版资源的rpm包

  1. rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm 先安装带有可用mysql5系列社区版资源的rpm包
[root@localhost ~]# rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
Retrieving http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-release-el7-5    ################################# [100%]
  1. yum repolist enabled | grep "mysql.*-community.*" 查看当前可用的mysql安装资源
[root@localhost ~]# yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community/x86_64 MySQL Connectors Community                  65
mysql-tools-community/x86_64      MySQL Tools Community                       69
mysql56-community/x86_64          MySQL 5.6 Community Server                 412
  1. yum -y install mysql-community-server 使用yum的方式安装MySQL,一般来说,只要安装mysql-server和mysql-client
[root@localhost ~]# yum -y install mysql-community-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.6.41-2.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.6.41-2.el7 for package: mysql-community-server-5.6.41-2.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.6.10 for package: mysql-community-server-5.6.41-2.el7.x86_64
--> Processing Dependency: perl(Data::Dumper) for package: mysql-community-server-5.6.41-2.el7.x86_64
--> Processing Dependency: perl(DBI) for package: mysql-community-server-5.6.41-2.el7.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.6.41-2.el7 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.6.10 for package: mysql-community-client-5.6.41-2.el7.x86_64
---> Package mysql-community-common.x86_64 0:5.6.41-2.el7 will be installed
---> Package perl-DBI.x86_64 0:1.627-4.el7 will be installed
--> Processing Dependency: perl(RPC::PlServer) >= 0.2001 for package: perl-DBI-1.627-4.el7.x86_64
--> Processing Dependency: perl(RPC::PlClient) >= 0.2000 for package: perl-DBI-1.627-4.el7.x86_64
---> Package perl-Data-Dumper.x86_64 0:2.145-3.el7 will be installed
--> Running transaction check
---> Package mysql-community-libs.x86_64 0:5.6.41-2.el7 will be installed
---> Package perl-PlRPC.noarch 0:0.2020-14.el7 will be installed
--> Processing Dependency: perl(Net::Daemon) >= 0.13 for package: perl-PlRPC-0.2020-14.el7.noarch
--> Processing Dependency: perl(Net::Daemon::Test) for package: perl-PlRPC-0.2020-14.el7.noarch
--> Processing Dependency: perl(Net::Daemon::Log) for package: perl-PlRPC-0.2020-14.el7.noarch
--> Processing Dependency: perl(Compress::Zlib) for package: perl-PlRPC-0.2020-14.el7.noarch
--> Running transaction check
---> Package perl-IO-Compress.noarch 0:2.061-2.el7 will be installed
--> Processing Dependency: perl(Compress::Raw::Zlib) >= 2.061 for package: perl-IO-Compress-2.061-2.el7.noarch
--> Processing Dependency: perl(Compress::Raw::Bzip2) >= 2.061 for package: perl-IO-Compress-2.061-2.el7.noarch
---> Package perl-Net-Daemon.noarch 0:0.48-5.el7 will be installed
--> Running transaction check
---> Package perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7 will be installed
---> Package perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================
 Package                             Arch               Version                     Repository                     Size
========================================================================================================================
Installing:
 mysql-community-server              x86_64             5.6.41-2.el7                mysql56-community              59 M
Installing for dependencies:
 mysql-community-client              x86_64             5.6.41-2.el7                mysql56-community              19 M
 mysql-community-common              x86_64             5.6.41-2.el7                mysql56-community             257 k
 mysql-community-libs                x86_64             5.6.41-2.el7                mysql56-community             2.0 M
 perl-Compress-Raw-Bzip2             x86_64             2.061-3.el7                 base                           32 k
 perl-Compress-Raw-Zlib              x86_64             1:2.061-4.el7               base                           57 k
 perl-DBI                            x86_64             1.627-4.el7                 base                          802 k
 perl-Data-Dumper                    x86_64             2.145-3.el7                 base                           47 k
 perl-IO-Compress                    noarch             2.061-2.el7                 base                          260 k
 perl-Net-Daemon                     noarch             0.48-5.el7                  base                           51 k
 perl-PlRPC                          noarch             0.2020-14.el7               base                           36 k

Transaction Summary
========================================================================================================================
Install  1 Package (+10 Dependent packages)

Total download size: 82 M
Installed size: 354 M
Downloading packages:
warning: /var/cache/yum/x86_64/7/mysql56-community/packages/mysql-community-common-5.6.41-2.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Public key for mysql-community-common-5.6.41-2.el7.x86_64.rpm is not installed
(1/11): mysql-community-common-5.6.41-2.el7.x86_64.rpm                                           | 257 kB  00:00:00
(2/11): mysql-community-libs-5.6.41-2.el7.x86_64.rpm                                             | 2.0 MB  00:00:00
(3/11): perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64.rpm                                           |  32 kB  00:00:00
(4/11): perl-Compress-Raw-Zlib-2.061-4.el7.x86_64.rpm                                            |  57 kB  00:00:00
(5/11): perl-Data-Dumper-2.145-3.el7.x86_64.rpm                                                  |  47 kB  00:00:00
(6/11): perl-IO-Compress-2.061-2.el7.noarch.rpm                                                  | 260 kB  00:00:00
(7/11): perl-Net-Daemon-0.48-5.el7.noarch.rpm                                                    |  51 kB  00:00:00
(8/11): perl-PlRPC-0.2020-14.el7.noarch.rpm                                                      |  36 kB  00:00:00
(9/11): perl-DBI-1.627-4.el7.x86_64.rpm                                                          | 802 kB  00:00:00
(10/11): mysql-community-client-5.6.41-2.el7.x86_64.rpm                                          |  19 MB  00:00:01
(11/11): mysql-community-server-5.6.41-2.el7.x86_64.rpm                                          |  59 MB  00:00:03
------------------------------------------------------------------------------------------------------------------------
Total                                                                                    17 MB/s |  82 MB  00:00:04
Retrieving key from file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Importing GPG key 0x5072E1F5:
 Userid     : "MySQL Release Engineering <mysql-build@oss.oracle.com>"
 Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
 Package    : mysql-community-release-el7-5.noarch (installed)
 From       : file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
** Found 2 pre-existing rpmdb problem(s), 'yum check' output follows:
2:postfix-2.10.1-6.el7.x86_64 has missing requires of libmysqlclient.so.18()(64bit)
2:postfix-2.10.1-6.el7.x86_64 has missing requires of libmysqlclient.so.18(libmysqlclient_18)(64bit)
  Installing : mysql-community-common-5.6.41-2.el7.x86_64                                                          1/11
  Installing : perl-Data-Dumper-2.145-3.el7.x86_64                                                                 2/11
  Installing : mysql-community-libs-5.6.41-2.el7.x86_64                                                            3/11
  Installing : mysql-community-client-5.6.41-2.el7.x86_64                                                          4/11
  Installing : perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64                                                          5/11
  Installing : perl-Net-Daemon-0.48-5.el7.noarch                                                                   6/11
  Installing : 1:perl-Compress-Raw-Zlib-2.061-4.el7.x86_64                                                         7/11
  Installing : perl-IO-Compress-2.061-2.el7.noarch                                                                 8/11
  Installing : perl-PlRPC-0.2020-14.el7.noarch                                                                     9/11
  Installing : perl-DBI-1.627-4.el7.x86_64                                                                        10/11
  Installing : mysql-community-server-5.6.41-2.el7.x86_64                                                         11/11
  Verifying  : mysql-community-server-5.6.41-2.el7.x86_64                                                          1/11
  Verifying  : mysql-community-client-5.6.41-2.el7.x86_64                                                          2/11
  Verifying  : mysql-community-libs-5.6.41-2.el7.x86_64                                                            3/11
  Verifying  : perl-Data-Dumper-2.145-3.el7.x86_64                                                                 4/11
  Verifying  : mysql-community-common-5.6.41-2.el7.x86_64                                                          5/11
  Verifying  : perl-IO-Compress-2.061-2.el7.noarch                                                                 6/11
  Verifying  : 1:perl-Compress-Raw-Zlib-2.061-4.el7.x86_64                                                         7/11
  Verifying  : perl-Net-Daemon-0.48-5.el7.noarch                                                                   8/11
  Verifying  : perl-DBI-1.627-4.el7.x86_64                                                                         9/11
  Verifying  : perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64                                                         10/11
  Verifying  : perl-PlRPC-0.2020-14.el7.noarch                                                                    11/11

Installed:
  mysql-community-server.x86_64 0:5.6.41-2.el7

Dependency Installed:
  mysql-community-client.x86_64 0:5.6.41-2.el7               mysql-community-common.x86_64 0:5.6.41-2.el7
  mysql-community-libs.x86_64 0:5.6.41-2.el7                 perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7
  perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7                perl-DBI.x86_64 0:1.627-4.el7
  perl-Data-Dumper.x86_64 0:2.145-3.el7                      perl-IO-Compress.noarch 0:2.061-2.el7
  perl-Net-Daemon.noarch 0:0.48-5.el7                        perl-PlRPC.noarch 0:0.2020-14.el7

Complete!
  1. yum list installed mysql* 查看是否安装mysql,检查是否安装完成
root@localhost ~]# yum list installed mysql*
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Installed Packages
mysql-community-client.x86_64                               5.6.41-2.el7                              @mysql56-communitymysql-community-common.x86_64                               5.6.41-2.el7                              @mysql56-communitymysql-community-libs.x86_64                                 5.6.41-2.el7                              @mysql56-communitymysql-community-release.noarch                              el7-5                                     installed
  1. systemctl enable mysqld 加入开机启动
[root@localhost ~]# systemctl enable mysqld
  1. systemctl start mysqld 启动mysql服务进程
[root@localhost ~]# systemctl start mysqld
  1. systemctl list-unit-files 验证是否加入开机启动列表中
[root@localhost ~]# systemctl list-unit-files
...
...
mysql.service                                 enabled
mysqld.service                                enabled
...
  1. ps -ef | grep mysql查看mysql安装路径
[root@localhost ~]# ps -ef | grep mysql
mysql    24362     1  0 11:33 ?        00:00:00 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
mysql    24529 24362  0 11:33 ?        00:00:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
root     24576 23955  0 11:50 pts/0    00:00:00 grep --color=auto mysql

查询文件运行所在地址,直接用下面的命令

[root@localhost ~]# which mysql
/usr/bin/mysql
  1. mysql_secure_installation 重置密码
[root@localhost ~]# mysql_secure_installation                      [设置root密码]



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

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

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

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

Set root password? [Y/n] y                                                            [是否设置root密码]
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!


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

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

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

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

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

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

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

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




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

Thanks for using MySQL!


Cleaning up...
  1. mysql -V 查看mysql安装版本号
[root@localhost ~]# mysql -V
mysql  Ver 14.14 Distrib 5.6.41, for Linux (x86_64) using  EditLine wrapper
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 204,684评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 87,143评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,214评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,788评论 1 277
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,796评论 5 368
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,665评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,027评论 3 399
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,679评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 41,346评论 1 299
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,664评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,766评论 1 331
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,412评论 4 321
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,015评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,974评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,203评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,073评论 2 350
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,501评论 2 343

推荐阅读更多精彩内容