查看当前目录home/xiaolin 创建mysql文件夹:mkidr mysql
检查系统自带的mysql安装包:rpm -qa | grep mariadb或者rpm -qa | grep mysql
请卸载通过 rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64命令装卸 mariadb
进入mysql文件夹:cd mysql 通过xshell的rz命令进行上传文件,并查看进行解压
tar -xvf mysql-8.0.35-1.el8.x86_64.rpm-bundle.tar
rpm -ivh --nodeps --force mysql-community-common-8.0.35-1.el8.x86_64.rpm
rpm -ivh --nodeps --force mysql-community-libs-8.0.35-1.el8.x86_64.rpm
rpm -ivh --nodeps --force mysql-community-client-8.0.35-1.el8.x86_64.rpm
rpm -ivh --nodeps --force mysql-community-client-plugins-8.0.35-1.el8.x86_64.rpm
rpm -ivh --nodeps --force mysql-community-server-8.0.35-1.el8.x86_64.rpm
通过 rpm -qa | grep mysql 命令查看 mysql 的安装包
通过依次执行以下命令,完成对 mysql 数据库的初始化和相关配置
chown -R mysql:mysql /home/xiaolin/mysql
默认配置文件:/etc/my.cnf
修改数据文件存放目录
datadir=/home/xiaolin/mysql/data
socket=/home/xiaolin/mysql/mysql.sock
log-error=/home/xiaolin/mysql/mysqld.log
添加如下
[client]
port=3307
default-character-set=utf8
socket=/home/xiaolin/mysql/mysql.sock
[mysql]
default-character-set=utf8
socket=/home/xiaolin/mysql/mysql.sock
修改完毕保存并退出
下列命令进行注册并设置安装目录
mysqld --defaults-file=/etc/my.cnf --basedir=/home/xiaolin/mysql/ --datadir=/home/xiaolin/mysql/data --user=mysql --initialize
安装完成启动服务并设置开机启动
systemctl start mysqld.service;
systemctl enable mysqld;
通过 cat /home/xiaolin/mysql/mysqld.log | grep password 命令查看数据库的密码,其中O*zd1R/PgOy4为默认创建的密码。diKS1duuUk?B
用新密码登陆:mysql --u root --p
修改root原始密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Xiaolin2024.';
flush privileges;
通过以下命令,进行root远程访问的授权:
create user 'root'@'%' identified with mysql_native_password by 'Xiaolin2024.';
grant all privileges on *.* to 'root'@'%' with grant option;
flush privileges;
#说明通过命令,创建远程用户进行访问的授权:
#GRANT ALL PRIVILEGES ON *.* TO '用户名'@'%' IDENTIFIED BY '密码';
停止systemctl stop mysqld.service;
启动systemctl start mysqld.service;
重启systemctl restart mysqld.service;
然后使用mysql -u root -p 进行连接测试
通过以下命令,关闭防火墙 firewall
systemctl stop firewalld.service;
systemctl disable firewalld.service;
systemctl mask firewalld.service;