centos7服务器安装 mysql

一、下载

官网:https://dev.mysql.com/downloads/mysql/

二、安装

1.查看有没有需要卸载的SQL包,一般系统的mariadb是自带的,需要卸载

rpm -qa | grep mysqlrpm -qa | grep mariadb

例如:安装过MySQL

使用如下命令卸载

rpm -e mysql-community-libs-8.1.0-1.el8.x86_64 --nodeps

2.解压与rpm安装

解压

tar xvf mysql-8.1.0-1.el7.x86_64.rpm-bundle.tar 

安装

rpm -ivh mysql-community-common-8.1.0-1.el7.x86_64.rpm rpm -ivh mysql-community-client-plugins-8.1.0-1.el7.x86_64.rpm rpm -ivh mysql-community-libs-8.1.0-1.el7.x86_64.rpm rpm -ivh mysql-community-client-8.1.0-1.el7.x86_64.rpm rpm -ivh mysql-community-icu-data-files-8.1.0-1.el7.x86_64.rpmrpm -ivh mysql-community-server-8.1.0-1.el7.x86_64.rpm --nodeps

显示需要依赖的,直接用–nodeps参数

3、登录配置

启动

systemctl start mysqldsystemctl enable mysqld

获取密码

cat /var/log/mysqld.log | grep password

登录

mysql -u root -p

修改密码

alter user 'root'@'localhost' identified with mysql_native_password by 'Ljh@new2024';

刷新权限

flush privileges;

配置远程登录

use mysql;select host, user from user;update user set host = '%' where user = 'root';select host, user from user;flush privileges;

三、用Navicat验证