mysql安装包版本:mysql-8.0.29-linux-glibc2.12-x86_64.tar.xz
服务器IP地址:192.168.10.100
mysql服务安装路径:/data/mysql
mysql数据存放路径:/data/mysql/data
一、下载安装包并上传
链接:https://pan.baidu.com/s/1JTCvlH9PcwydjrlVTno8LQ?pwd=ik5g
将安装包下载完成后上传到192.168.10.100的服务器的/data/install目录中
二、解压,修改包安装包名并创建对应数据目录
解压
cd /data/install && tar xcf mysql-8.0.29-linux-glibc2.12-x86_64.tar.xz
mv mysql-8.0.29-linux-glibc2.12-x86_64 ../mysql
创建mysql数据安装目录和日志目录
mkdir /data/mysql/{data,logs}
三、创建用户
为mysql的目录创建对应的用户
groupadd mysql
useradd -g mysql mysql
四、给mysql目录赋予mysql用户组
chown -R mysql.mysql /data/mysql
五、初始化mysql
初始化mysql并保存临时登录密码
cd /data/mysql/bin
./mysqld --user=mysql --basedir=/data/mysql --datadir=/data/mysql/data/ --initialize
六、修改mysql的配置文件
mysql的配置文件在my.cnf
vim /etc/my.cnf
[mysqld]
basedir=/data/mysql
datadir=/data/mysql/data
socket=/tmp/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
character-set-server=UTF8MB4
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
#lower-case-table-names=1
[mysqld_safe]
log-error=/data/mysql/logs/mysql.log
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
七、将mysql服务添加到系统中并授权
添加至系统
cd /data/mysql/
cp -a ./support-files/mysql.server /etc/init.d/mysql
授权
chkconfig --add mysql
八、启动mysql服务
切换至mysql用户并登录:
su - mysql
service mysql start
查看服务状态
ps -ef | grep mysql
netstat -anlp | grep mysql
九、登录mysql数据库中修改密码
登录
cd /data/mysql/bin
./mysql -uroot -p 回车后
输入之前保存的临时密码
修改root用户的密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';
flush privileges; #使新密码生效
修改远程连接并生效
use mysql;
update user set host='%' where user='root'; #修改远程连接
flush privileges; #使配置生效
完成后开通网络策略或关闭防火墙
开放指定端口
firewall-cmd --add-port=8080/tcp --permanent
重载入添加的端口
firewall-cmd --reload
查看指定端口是否已经开放
firewall-cmd --query-port=8080/tcp
移除指定端口
firewall-cmd --permanent --remove-port=8080/tcp
查询开放的端口列表
firewall-cmd --zone=public --list-ports
查看防火墙状态 systemctl status firewalld
开启防火墙 systemctl start firewalld
关闭防火墙 systemctl stop firewalld
重启防火墙 service firewalld start