# 查看虚拟机默认自带数据库,并删除
rpm -qa|grep mariadb
----------------------
mariadb-libs-5.5.68-1.el7.x86_64
----------------------
yum -y remove mariadb-libs-5.5.68-1.el7.x86_64
# mysql 安装
cd /opt
mkdir download
cd download
# 下载mysql rpm源
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
-------------------------
mysql-community-release-el7-5.noarch.rpm
-------------------------
# 备用rpm源,若mysql-community-release-el7-5.noarch.rpm出现不兼容
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
wget http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
# rpm 安装
rpm -ivh mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql57-community-release-el7-10.noarch.rpm
# 安装mysql服务
yum -y install mysql-server
# 查看安装后的资源
rpm -qa|grep mysql
-------------------------
mysql-community-release-el7-5.noarch
mysql-community-libs-5.6.51-2.el7.x86_64
mysql-community-server-5.6.51-2.el7.x86_64
mysql-community-client-5.6.51-2.el7.x86_64
mysql-community-common-5.6.51-2.el7.x86_64
-------------------------
# 字符集配置
#安装vim
yum -y install vim
vim /etc/my.cnf
--------------------------------
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
[mysqld]
#skip-grant-tables
character-set-client-handshake=FALSE
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
--------------------------------
# 检查Mysql服务状态
systemctl status mysql
# 启动mysql服务
systemctl start mysql
--------------------------------
Active: active (running) since Mon 2022-07-04 11:10:15 CST; 1s ago
--------------------------------
# 进入Mysql控制台
#首次访问
mysql 回车进入
#查看默认系统库:mysql不可少
show databases;
------------------------
information_schema
mysql ⭐
performance_schema
------------------------
use mysql;
select host,user,password from user;
update user set password=password('123');
grant all on *.* to root@'%' identified by '123';
flush privileges;
#ctrl+c 退出mysql
systemctl restart mysql
systemctl status mysql
#登录mysql
mysql -u root -p #回车,再输入密码123