CentOS安装Mysql

0 检查相关信息

CentOS默认的是mariadb,需要先检查是否安装了mariadb,如果已安装则需要先卸载。

1
2
3
4
rpm -qa | grep mysql
rpm -qa | grep mariadb
rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64
rpm -qa | grep mariadb

1 安装MySQL官方源

下载yum repo。我的系统是centos 7.9,想安装mysql5.7

1
2
wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
yum -y install mysql57-community-release-el7-11.noarch.rpm

导入密钥:

1
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

2 安装MySQL服务器

1
yum -y install mysql-community-server

安装完成,启动服务,并查看状态

1
2
systemctl start mysqld.service
systemctl status mysqld.service

找到初始密码,登录数据库

1
2
grep "password" /var/log/mysqld.log
mysql -uroot -p

3 配置

修改mysql配置文件vim /etc/my.cnf

1
2
3
4
5
6
7
8
9
10
11
12
13
[mysqld]
port=23306
max_connections=200
max_connect_errors=10
character-set-server=utf8
default-storage-engine=INNODB

[mysql]
default-character-set=utf8

[client]
port=23306
default-character-set=utf8