Centos7安装Mysql
登陆服务器
1、安装wget
yum -y install wget
2、下载mysql包(version:5.7)
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
3、安装
安装mysql
yum -y install mysql57-community-release-el7-10.noarch.rpm
安装mysql server
yum -y install mysql-community-server
如果出现下面这种情况
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
4、启动
启动mysql服务
systemctl start mysqld.service
查看mysql服务状态
systemctl status mysqld.service
停止mysql服务
systemctl stop mysqld.service
5、登陆
获取mysql临时密码
grep 'temporary password' /var/log/mysqld.log
使用临时密码登陆
mysql -uroot -p
设置密码策略、更新密码
set global validate_password_policy=LOW;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'admin'
6、配置
6.1、允许远程访问
关闭防火墙
sudo systemctl disable firewalld
登陆数据库
mysql -uroot -p
查看登陆限制
use mysql;
select Host,User from user;
更改设置
update user set Host='%' where User='root';
flush privileges;
select Host,User from user;
6.2、开机自启
touch /etc/systemd/system/mysqld.service
cd /etc/systemd/system
vim mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/usr/sbin/mysqld
LimitNOFILE = 5000
systemctl start mysqld