為什么要寫這篇文章,因為現在在網上找的資料基本都是錯誤的,或者有錯誤,看著不爽。
在百度上搜 centos7 mysql 錯的最離譜的就是這篇http://jingyan.baidu.com/article/ce436649fec8533773afd385.html 照著裝了半天裝了是mariadb
后來找了一些文章,發現基本都過時了。
因為直接yum install mysql 是裝不上mysql的!! 而是裝上了mariadb ! 那就是因為默認的倉庫里就是mariadb的包
那yum這么好的工具用不了就?? 當然有解決辦法,我在官網上找到一篇文章叫做“A Quick Guide to Using the MySQL Yum Repository“ 就是教我們如何用yum工具安裝mysql的
首先 將mysql加到yum倉庫中 (我這的命令都是centos7的,其他liunx平臺用啥命令,你們自己搞定哈)
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
結果:
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
結果:
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
這里再多數一句,可以看到先在mysql5.6 是可用的,可我就想裝現在最新版的5.7可咋辦? 是有辦法的。
需要修改文件,執行以下命令
shell > vi /etc/yum.repos.d/mysql-community.repo
會看到
[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 就行了。 我裝啥版本無所謂,這塊我沒有親自去試過,直接安裝默認版本。
上邊所有的工作都做完了,我們終于可以用我們最喜歡的yum來安裝了
shell > yum install mysql-community-server
安裝過程省略,一路按y
成功之后,啟動mysql
shell > service mysqld start
查看mysql 的狀態
shell > service mysqld status
現在還需設置root的密碼,刪除匿名用戶等一些設置,我看其他文章寫的很復雜,其實有一個簡單的命令
shell > mysql_secure_installation
初始密碼為空,直接按回車鍵,然后輸入你想設置的密碼,其他的根據你自己的需求,y或者n
that is all
如果有錯誤,請及時聯系,互相學習,互相進步,謝謝。