centos7安装mysql

本文详细介绍在CentOS系统中安装与配置MySQL5.7的全过程,包括下载与安装yum源、安装mysql服务、启动与管理服务、修改默认密码、设置远程登录、配置字符集及开启3306端口等关键步骤。

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

1、下载yum源
wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
2、安装yum源
yum localinstall mysql57-community-release-el7-8.noarch.rpm
3、
yum repolist enabled | grep “mysql.-community.”
4、安装mysql服务
yum install mysql-community-server
5、启动mysql服务
systemctl start mysqld
6、查看mysql服务状态
systemctl status mysqld
7、开机启动
systemctl enable mysqld
systemctl daemon-reload
8、查看mysql的临时密码
grep 'temporary password' /var/log/mysqld.log


配置文件:/etc/my.cnf
日志文件:/var/log//var/log/mysqld.log
服务启动脚本:/usr/lib/systemd/system/mysqld.service
socket文件:/var/run/mysqld/mysqld.pid

9、修改my.cnf配置文件
vi /etc/my.cnf
添加 (如果不需要密码策略,禁用密码策略)
validate_password = off
添加
character_set_server = utf8
init_connect = ‘SET NAMES utf8’

10、重启mysql服务
systemctl restart mysqld
11、登录mysql
mysql -uroot -p
密码就是(8)查出来的密码(grep 'temporary password' /var/log/mysqld.log)
12、使用mysql库
use mysql
13、修改密码
SET PASSWORD = PASSWORD('your new password');
14、使远程可以登录mysql
update user set host = '%' where user ='root'
15、查看结果
select host, user from user;
16、退出
quit
17、查看防火墙配置
service iptables status
如果看不到,那么系统的防火墙使用的是firewalld
systemctl status firewalld
18、开放3306端口
firewall-cmd --add-port=3306/tcp --permanent
19、重启防火墙
firewall-cmd --reload

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值