Centos7.9 mysql5.7离线部署

本文详细介绍了在CentOS7.9服务器上离线安装MySQL5.7的过程,包括卸载MariaDB、下载并安装、设置环境变量、创建用户和配置文件,以及安全初始化和防火墙配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Centos7.9 mysql5.7离线安装

将Mysql7.5.44下载到本地,利用sftp工具上传到Centos7.9服务器

Linux-x86-x64 通用Mysql5.7.44下载
安装mysql前要先将mariadb卸载掉 yum remove mariadb* -y

tar -zxvf mysql-5.7.44-linux-glibc2.12-x86_64.tar.gz //将mysql压缩包解压
mv mysql-5.7.44-linux-glibc2.12-x86_64 /usr/local/mysql //将以解压mysql包移动到/usr/local并重命名为mysql

将MySQL添加到系统变量
vi /etc/profile

#/etc/profile
export PATH=$PATH:/usr/local/mysql/bin //添加mysql执行文件路径
#
source /etc/profile  //刷新环境变量

创建mysql用户

useradd mysql -M //-M:不创建家目录

初始化MySQL

mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data 

创建my.cnf配置文件
vi /etc/my.cnf

#/etc/my.cnf
[mysqld]
user=mysql
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
server_id=10
socket=/tmp/mysql.sock
[mysql]
socket=/tmp/mysql.sock
#

创建MySQL systemctl守护文件
vi /etc/systemd/system/mysqld.service

#/etc/systemd/system/mysqld.service
[Unit]
Description=mysql.server
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/mysql/support-files/mysql.server start
ExecStop=/usr/local/mysql/support-files/mysql.server stop

[Install]
WantedBy=multi-user.target
#

启动mysql

systemctl start mysqld.service  //开启mysql服务
systemctl enable mysqld.service  //开启开机自启

firewalld 开放mysql服务

firewall-cmd --permanent --add-service=mysql
firewall-cmd --reload  //重启firewalld

初始化mysql配置
mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No:  //默认即可
Please set the password for root here.

New password: //添加密码

Re-enter new password: //再次输入密码
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y  //删除匿名用户
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y //不允许远程根用户登录
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y  //删除测试数据库并访问它
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y //现在重新加载特权表
Success.

All done!

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值