Centos7安装MySQL5.7

mtain 2022年06月10日 34次浏览

1. 安装包下载

下载网址:https://dev.mysql.com/downloads/mysql/5.7.html

Red Hat Enterprise Linux 7 / Oracle Linux 7 (x86, 64-bit), RPM Bundle

mysql-5.7.31-1.el7.x86_64.rpm-bundle.tar

2. 解压安装

tar xf mysql-5.7.31-1.el7.x86_64.rpm-bundle.tar

安装mysql-server顺序(依赖关系)
common–>libs–>client–>server

rpm -ivh mysql-community-common-5.7.31-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.31-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.31-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.31-1.el7.x86_64.rpm
或者
yum localinstall -y  mysql-*.rpm

3. 初始化数据库

# 初始化mysql
# 更改mysql数据库所属于用户及其所属于组
mysqld --initialize
chown mysql:mysql /var/lib/mysql -R

4.设置字符编码和表名不区分大小写

vi /etc/my.cnf
增加
[mysqld]
character-set-server=utf8
lower_case_table_names=1

5. 启动mysql数据库

systemctl start mysqld.service
systemctl enable mysqld.service

grep 'password' /var/log/mysqld.log 

6. 修改数据库密码

必须修改才能使用

mysql -u root -p

set password=password('password');
flush privileges;
grant all privileges on *.* to root@'%' identified by 'password' with grant option;
flush privileges;