1、MySQL 被 Oracle 收购后,CentOS 的镜像仓库中提供的默认的数据库也变为了 MariaDB

2、下载mysql的repo源  MySQL :: Download MySQL Yum Repositoryhttps://dev.mysql.com/downloads/repo/yum/

wget  https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm

3、安装yum源

rpm -Uvh /home/mysql80-community-release-el7-3.noarch.rpm

ll /etc/yum.repos.d/  可以看到新增的repo:

-rw-r--r--. 1 root root 1664 Nov 23  2018 CentOS-Base.repo

-rw-r--r--. 1 root root 1309 Nov 23  2018 CentOS-CR.repo

-rw-r--r--. 1 root root  649 Nov 23  2018 CentOS-Debuginfo.repo

-rw-r--r--. 1 root root  314 Nov 23  2018 CentOS-fasttrack.repo

-rw-r--r--. 1 root root  630 Nov 23  2018 CentOS-Media.repo

-rw-r--r--. 1 root root 1331 Nov 23  2018 CentOS-Sources.repo

-rw-r--r--. 1 root root 5701 Nov 23  2018 CentOS-Vault.repo

-rw-r--r--. 1 root root  951 Oct  3  2017 epel.repo

-rw-r--r--. 1 root root 1050 Oct  3  2017 epel-testing.repo

-rw-r--r--. 1 root root 2076 Apr 25 01:35 mysql-community.repo

-rw-r--r--. 1 root root 2108 Apr 25 01:35 mysql-community-source.repo

4、安装mysql

yum install mysql-community-server

提示错误:

mysql-community-server-8.0.34-1.el7.x86_64.rpm 的公钥尚未安装
失败的软件包是:mysql-community-server-8.0.34-1.el7.x86_64
GPG 密钥配置为:file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

两种解决方法:MySQL :: MySQL 8.0 Reference Manual :: 2.1.4.4 Signature Checking Using RPMicon-default.png?t=N6B9https://dev.mysql.com/doc/refman/8.0/en/checking-rpm-signature.html

a. 

rpm --checksig mysql-community-server-8.0.34-1.el8.x86_64.rpm

gpg --export -a 3a79bd29 > 3a79bd29.asc

rpm --import 3a79bd29.asc

b.

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

5、启动

systemctl start  mysqld

查看状态

systemctl status mysqld

6、查找root的临时密码

grep "password" /var/log/mysqld.log

7、登录

mysql -uroot -p

输入初始密码,此时不能做任何事情,必须修改密码才能正常使用

8、修改默认密码

ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';

9、查看完整的初始密码规则

show variables like 'validate_password%';

修改规则

set global validate_password.policy=0;

set global validate_password.length=1;

10、每次 yum 操作都会自动更新,需要把这个repo卸载掉  ???

yum -y remove mysql57-community-release-el7-10.noarch

or

rm -f /etc/yum.repos.d/mysql-community.repo

rm -f /etc/yum.repos.d/mysql-community-source.repo

yum clean

11、授权远程登录

grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'identified by '123456' with grant option' at line 1

解决方法:8.0版本在给新用户授权时有变化,分三次执行

create user 'root'@'%' identified by '123456';

grant all privileges on *.* to 'root'@'%' with grant option;

flush privileges;

12、查看mysql的字符集

show variables like 'character_set%';

支持中文,修改字符集为utf-8

vim /etc/my.cnf

------------------------------------------------------------------------------------

[client]

port=3306

socket=/var/lib/mysql/mysql.sock

default-character-set=utf8

[mysqld]

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

user=mysql

# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

character-set-server=utf8

[mysql]

no-auto-rehash

default-character-set=utf8

[mysqld_safe]

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

----------------------------------------------------------------------------------------

How to support full Unicode in MySQL databases · Mathias Bynensicon-default.png?t=N6B9https://mathiasbynens.be/notes/mysql-utf8mb4

13、mysql just listen on ipv6's port 3306 , not a ipv4's port 3306

vim /etc/my.cnf

添加 bind-address=0.0.0.0

14、防火墙开放端口3306

firewall-cmd --zone=public --add-port=3306/tcp --permanent

firewall-cmd --reload

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐