安装 Mysql

环境信息

  • Centos 7 kernel 5.4
  • Mysql Server 5.7

Mysql Server 安装步骤

yum 方式安装

安装 MySQL 5.7 的 yum 源

yum localinstall -y http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm

如果因为源冲突,类似如下错误

Processing Conflict: mysql80-community-release-el7-2.noarch conflicts mysql57-community-release

可以卸载旧的 yum 源安装包,重新安装

$ rpm -qa | grep mysql
mysql80-community-release-el7-2.noarch

$ yum remove mysql80-community-release-el7-2

$ yum localinstall -y http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm

检查 yum 源中的 mysql-community-server 信息

$ yum info mysql-community-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: download.cf.centos.org
* elrepo: reflector.westga.edu
* epel: coresite.mm.fcix.net
* extras: download.cf.centos.org
* updates: download.cf.centos.org
Available Packages
Name : mysql-community-server
Arch : x86_64
Version : 5.7.40
Release : 1.el7
Size : 178 M
Repo : mysql57-community/x86_64
Summary : A very fast and reliable SQL database server

安装 mysql-community-server

yum install -y mysql-community-server

启动 mysql server

配置 mysql server 开机启动,同时启动服务

systemctl enable mysqld --now

MySQL5.7 会为 root 用户随机生成一个临时密码,密码记录在日志 /var/log/mysqld.log

grep 'temporary password' /var/log/mysqld.log 
2022-11-02T06:09:54.520945Z 1 [Note] A temporary password is generated for root@localhost: ZQc6OCFidi:g

使用临时密码登陆,修改密码,临时密码登陆后不能做任何操作,必须先更改密码

mysql
ALTER USER 'root'@'localhost' IDENTIFIED BY 'WadgyWwRdgDNEb+5Pw==';

Mariadb 安装

环境信息

  • Mariadb 5.5
yum install -y mariadb-server

安装后启动,默认密码为空,登陆后使用以下命令修改密码

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('your_password');