安裝MySQL5.6

這里介紹一下為什么會(huì)用數(shù)據(jù)庫(kù)也殖,主要做什么用

一兔沃、卸載Mariadb

從 CentOS 7 系統(tǒng)開(kāi)始滔韵,MariaDB 成為 yum 源中默認(rèn)的數(shù)據(jù)庫(kù)安裝包际看。在 CentOS 7 及以上的系統(tǒng)中使用 yum 安裝 MySQL 包將無(wú)法使用 MySQL。您可以選擇使用完全兼容的 MariaDB盖高,或依照本文介紹配置來(lái)繼續(xù)使用 MySQL慎陵。

查看安裝了mariadb相關(guān)的模塊

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

然后進(jìn)行卸載

[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

會(huì)提示有依賴(lài)于這的安裝包,那么就強(qiáng)制卸載喻奥,不查檢依賴(lài):

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

將所有的mariadb安裝包都刪除席纽,然后再次鍵入 rpm -qa | grep mariadb 查看是否卸載成功

二、卸載MySQL

為了防止重裝撞蚕,建議先卸載润梯,可以操作以下命令

查看yum是否安裝過(guò)mysql

yum list installed mysql*

查看mysql安裝了哪些東西

rpm -qa | grep -i mysql

開(kāi)始卸載,(這里只列兩條甥厦,應(yīng)該是卸載上面查詢(xún)出來(lái)的結(jié)果7拿!)

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相關(guān)目錄

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

刪除mysql相關(guān)目錄(后面的地址刀疙,替換成查詢(xún)返回的地址舶赔,有多條,順序執(zhí)行 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(如果不刪除這個(gè)文件谦秧,會(huì)導(dǎo)致新安裝的mysql無(wú)法生存新密碼竟纳,導(dǎo)致無(wú)法登錄)

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

三、安裝MySQL

大家都知道油够,centos自帶的repo是不會(huì)自動(dòng)更新每個(gè)軟件的最新版本蚁袭,所以無(wú)法通過(guò)yum方式安裝MySQL的高級(jí)版本征懈。所以石咬,即使我使勁用yum -y install mysql
mysql-server mysql-devel,也是沒(méi)有人會(huì)鳥(niǎo)我的卖哎。
所以鬼悠,正確的安裝mysql5姿勢(shì)是要先安裝帶有可用的mysql5系列社區(qū)版資源的rpm包

  1. rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm 先安裝帶有可用mysql5系列社區(qū)版資源的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.*" 查看當(dāng)前可用的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删性,一般來(lái)說(shuō),只要安裝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 加入開(kāi)機(jī)啟動(dòng)
[root@localhost ~]# systemctl enable mysqld
  1. systemctl start mysqld 啟動(dòng)mysql服務(wù)進(jìn)程
[root@localhost ~]# systemctl start mysqld
  1. systemctl list-unit-files 驗(yàn)證是否加入開(kāi)機(jī)啟動(dòng)列表中
[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

查詢(xún)文件運(yùn)行所在地址蹬挺,直接用下面的命令

[root@localhost ~]# which mysql
/usr/bin/mysql
  1. mysql_secure_installation 重置密碼
[root@localhost ~]# mysql_secure_installation                      [設(shè)置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                                                            [是否設(shè)置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                                                       [刪除匿名用戶(hù)]
 ... 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遠(yuǎn)程登錄](méi)
 ... 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數(shù)據(jù)庫(kù)]
 - 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                                                  [刷新權(quán)限]
 ... 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安裝版本號(hào)
[root@localhost ~]# mysql -V
mysql  Ver 14.14 Distrib 5.6.41, for Linux (x86_64) using  EditLine wrapper
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市它掂,隨后出現(xiàn)的幾起案子巴帮,更是在濱河造成了極大的恐慌,老刑警劉巖虐秋,帶你破解...
    沈念sama閱讀 218,036評(píng)論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件榕茧,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡客给,警方通過(guò)查閱死者的電腦和手機(jī)用押,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,046評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門(mén),熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)靶剑,“玉大人蜻拨,你說(shuō)我怎么就攤上這事∽” “怎么了缎讼?”我有些...
    開(kāi)封第一講書(shū)人閱讀 164,411評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)坑匠。 經(jīng)常有香客問(wèn)我休涤,道長(zhǎng),這世上最難降的妖魔是什么笛辟? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,622評(píng)論 1 293
  • 正文 為了忘掉前任功氨,我火速辦了婚禮,結(jié)果婚禮上手幢,老公的妹妹穿的比我還像新娘捷凄。我一直安慰自己,他們只是感情好围来,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,661評(píng)論 6 392
  • 文/花漫 我一把揭開(kāi)白布跺涤。 她就那樣靜靜地躺著,像睡著了一般监透。 火紅的嫁衣襯著肌膚如雪桶错。 梳的紋絲不亂的頭發(fā)上,一...
    開(kāi)封第一講書(shū)人閱讀 51,521評(píng)論 1 304
  • 那天胀蛮,我揣著相機(jī)與錄音院刁,去河邊找鬼。 笑死粪狼,一個(gè)胖子當(dāng)著我的面吹牛退腥,可吹牛的內(nèi)容都是我干的任岸。 我是一名探鬼主播,決...
    沈念sama閱讀 40,288評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼狡刘,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼享潜!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起嗅蔬,我...
    開(kāi)封第一講書(shū)人閱讀 39,200評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤剑按,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后澜术,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體吕座,經(jīng)...
    沈念sama閱讀 45,644評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,837評(píng)論 3 336
  • 正文 我和宋清朗相戀三年瘪板,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了吴趴。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 39,953評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡侮攀,死狀恐怖锣枝,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情兰英,我是刑警寧澤撇叁,帶...
    沈念sama閱讀 35,673評(píng)論 5 346
  • 正文 年R本政府宣布,位于F島的核電站畦贸,受9級(jí)特大地震影響陨闹,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜薄坏,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,281評(píng)論 3 329
  • 文/蒙蒙 一趋厉、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧胶坠,春花似錦君账、人聲如沸。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 31,889評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至闻牡,卻和暖如春净赴,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背罩润。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 33,011評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工玖翅, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,119評(píng)論 3 370
  • 正文 我出身青樓烧栋,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親拳球。 傳聞我的和親對(duì)象是個(gè)殘疾皇子审姓,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,901評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容