标签:
为什么要写这篇文章,因为现在在网上找的资料基本都是错误的,或者有错误,看着不爽。
在百度上搜 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
如果有错误,请及时联系,互相学习,互相进步,谢谢。
标签:
原文地址:http://www.cnblogs.com/hmdrzql/p/4654101.html