為什么要寫這篇文章,因?yàn)楝F(xiàn)在在網(wǎng)上找的資料基本都是錯(cuò)誤的,或者有錯(cuò)誤,看著不爽。
在百度上搜 centos7 mysql 錯(cuò)的最離譜的就是這篇http://jingyan.baidu.com/article/ce436649fec8533773afd385.html 照著裝了半天裝了是mariadb
后來找了一些文章,發(fā)現(xiàn)基本都過時(shí)了。
因?yàn)橹苯觵um install mysql 是裝不上mysql的!! 而是裝上了mariadb ! 那就是因?yàn)槟J(rèn)的倉(cāng)庫(kù)里就是mariadb的包
那yum這么好的工具用不了就?? 當(dāng)然有解決辦法,我在官網(wǎng)上找到一篇文章叫做“A Quick Guide to Using the MySQL Yum Repository“ 就是教我們?nèi)绾斡脃um工具安裝mysql的
首先 將mysql加到y(tǒng)um倉(cāng)庫(kù)中 (我這的命令都是centos7的,其他liunx平臺(tái)用啥命令,你們自己搞定哈)
shell > wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
shell > rpm -ivh mysql-community-release-el7-5.noarch.rpm
然后再在命令行里輸入
shell > yum repolist all | grep mysql
結(jié)果:
mysql-connectors-community/x86_64 MySQL Connectors Community enabled: 14
mysql-connectors-community-source MySQL Connectors Community - So disabled
mysql-tools-community/x86_64 MySQL Tools Community enabled: 19
mysql-tools-community-source MySQL Tools Community - Source disabled
mysql55-community/x86_64 MySQL 5.5 Community Server disabled
mysql55-community-source MySQL 5.5 Community Server - So disabled
mysql56-community/x86_64 MySQL 5.6 Community Server enabled: 154
mysql56-community-source MySQL 5.6 Community Server - So disabled
mysql57-community-dmr/x86_64 MySQL 5.7 Community Server Deve disabled
mysql57-community-dmr-source MySQL 5.7 Community Server Deve disabled
一堆disabled,只看enable的,可以輸入命令
shell > yum repolist enabled | grep mysql
結(jié)果:
mysql-connectors-community/x86_64 MySQL Connectors Community 14
mysql-tools-community/x86_64 MySQL Tools Community 19
mysql56-community/x86_64 MySQL 5.6 Community Server 154
這里再多數(shù)一句,可以看到先在mysql5.6 是可用的,可我就想裝現(xiàn)在最新版的5.7可咋辦? 是有辦法的。
需要修改文件,執(zhí)行以下命令
shell > vi /etc/yum.repos.d/mysql-community.repo
會(huì)看到
[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql-tools-community]
name=MySQL Tools Community
baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
# Enable to use MySQL 5.5
[mysql55-community]
name=MySQL 5.5 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.5-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
# Enable to use MySQL 5.6
[mysql56-community]
name=MySQL 5.6 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
# Note: MySQL 5.7 is currently in development. For use at your own risk.
# Please read with sub pages: https://dev.mysql.com/doc/relnotes/mysql/5.7/en/
[mysql57-community-dmr]
name=MySQL 5.7 Community Server Development Milestone Release
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
我們只需要把5.7的enabled 改成1 把5.6的enabled改成0 就行了。 我裝啥版本無所謂,這塊我沒有親自去試過,直接安裝默認(rèn)版本。
上邊所有的工作都做完了,我們終于可以用我們最喜歡的yum來安裝了
shell > yum install mysql-community-server
安裝過程省略,一路按y
成功之后,啟動(dòng)mysql
shell > service mysqld start
查看mysql 的狀態(tài)
shell > service mysqld status
現(xiàn)在還需設(shè)置root的密碼,刪除匿名用戶等一些設(shè)置,我看其他文章寫的很復(fù)雜,其實(shí)有一個(gè)簡(jiǎn)單的命令
shell > mysql_secure_installation
初始密碼為空,直接按回車鍵,然后輸入你想設(shè)置的密碼,其他的根據(jù)你自己的需求,y或者n
that is all
如果有錯(cuò)誤,請(qǐng)及時(shí)聯(lián)系,互相學(xué)習(xí),互相進(jìn)步,謝謝。