centos 7 安装 mysql

本贴最后更新于 2313 天前,其中的信息可能已经时移世异

1. 下载 yum 包(两种方式)

  • wget 下载
wget 'https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm'

2. 安装软件源

rpm -Uvh mysql57-community-release-el7-11.noarch.rpm

3. 选择安装版本安装

  • 列出版本
$yum repolist all | grep mysql
mysql-cluster-7.5-community/x86_64 MySQL Cluster 7.5 Community   disabled
mysql-cluster-7.5-community-source MySQL Cluster 7.5 Community - disabled
mysql-cluster-7.6-community/x86_64 MySQL Cluster 7.6 Community   disabled
mysql-cluster-7.6-community-source MySQL Cluster 7.6 Community - disabled
!mysql-connectors-community/x86_64 MySQL Connectors Community    enabled:     63
mysql-connectors-community-source  MySQL Connectors Community -  disabled
!mysql-tools-community/x86_64      MySQL Tools Community         enabled:     69
mysql-tools-community-source       MySQL Tools Community - Sourc disabled
mysql-tools-preview/x86_64         MySQL Tools Preview           disabled
mysql-tools-preview-source         MySQL Tools Preview - Source  disabled
mysql55-community/x86_64           MySQL 5.5 Community Server    disabled
mysql55-community-source           MySQL 5.5 Community Server -  disabled
mysql56-community/x86_64           MySQL 5.6 Community Server    disabled
mysql56-community-source           MySQL 5.6 Community Server -  disabled
!mysql57-community/x86_64          MySQL 5.7 Community Server    enabled:    287
mysql57-community-source           MySQL 5.7 Community Server -  disabled
mysql80-community/x86_64           MySQL 8.0 Community Server    disabled
mysql80-community-source           MySQL 8.0 Community Server -  disabled

如果想安装最新版本的,直接使用 yum 命令即可

yum install mysql-community-server

如果想要安装 5.6 版本的,有 2 个方法。命令行支持 yum-config-manager 命令的话,可以使用如下命令:

$ sudo dnf config-manager --disable mysql57-community
$ sudo dnf config-manager --enable mysql56-community
$ yum repolist | grep mysql
mysql-connectors-community/x86_64 MySQL Connectors Community                  36
mysql-tools-community/x86_64      MySQL Tools Community                       47
mysql56-community/x86_64          MySQL 5.6 Community Server                 327

或者直接修改 /etc/yum.repos.d/mysql-community.repo 这个文件

# 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

[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=0 #默认这个是 1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

通过设置 enabled 来决定安装哪个版本。
设置好之后使用 yum 安装即可。

4. 启动 mysql

systemctl start mysqld.service

5. 查看 mysql 运行状态

systemctl status mysqld.service

6. 安装之后是有 root 密码的,但是是随机的, 需要修改

  • 获取 mysql 临时随机密码
grep 'temporary password' /var/log/mysqld.log


这里的密码是 YdsGaxOq>2n!

  • 登录并修改密码
mysql -uroot -pYdsGaxOq>2n!
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';

update user set authentication_string=password('123abc') where user='root';
flush privileges;

7. 授权其他机器登陆

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;

FLUSH  PRIVILEGES;

作者 @ 没有故事的老大爷
在所有不被想起的快乐里,我最喜欢你

  • MySQL

    MySQL 是一个关系型数据库管理系统,由瑞典 MySQL AB 公司开发,目前属于 Oracle 公司。MySQL 是最流行的关系型数据库管理系统之一。

    692 引用 • 535 回帖

相关帖子

欢迎来到这里!

我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。

注册 关于
请输入回帖内容 ...