1.安装 wget 命令
yum -y install wget
2.下载mysql源码包
wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
yum localinstall mysql57-community-release-el7-8.noarch.rpm
yum repolist enabled | grep "mysql.*-community.*"
3.修改安装mysql包版本
vi /etc/yum.repos.d/mysql-community.repo
改变默认安装的mysql版本。比如要安装5.6版本,将5.7源的enabled=1改成enabled=0。然后再将5.6源的enabled=0改成enabled=1即可
4.安装mysql
yum install mysql-community-server
5.启动mysql
systemctl start mysqld
6.查看mysql启动状态
systemctl status mysqld
7.查看mysql版本
mysqld --version
8.设置开机启动
systemctl enable mysqld
systemctl daemon-reload
9.找到安装时设置的默认密码
grep 'temporary password' /var/log/mysqld.log
密码日志 : 2018-12-03T14:54:06.651986Z 1 [Note] A temporary password is generated for root@localhost: o9kWqD?i6<SU
密码:o9kWqD?i6<SU
10.输入密码进入mysql命令行
mysql -uroot -p
回车输入 步骤 9 中的密码,进入mysql命令行
11.进入mysql命令行后修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '1234!1234Labcd';
修改后 root 用户密码为 '1234!1234Labcd'
12.刷新权限
FLUSH PRIVILEGES;
13.修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置,如下所示:
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
14.重启mysql
shell> systemctl restart mysqld
15.进入mysql命令行查看编码 (使用 mysql -uroot -p 进入mysql命令行)
show variables like '%character%';
16.添加远程登陆用户
GRANT ALL PRIVILEGES ON *.* TO 'setsuna'@'%' IDENTIFIED BY 'Setsuna_Pisces313!' WITH GRANT OPTION;
'setsuna'@'%' 中'@'%写死的暂时不用管它, 远程用户名为: setsuna 密码为: Setsuna_Pisces313!
17.默认配置文件路径(请根据需求自行修改)
默认配置文件路径:
配置文件:/etc/my.cnf
日志文件:/var/log//var/log/mysqld.log
服务启动脚本:/usr/lib/systemd/system/mysqld.service
socket文件:/var/run/mysqld/mysqld.pid
查看安装目录: show variables like "%char%";
18.设置防火墙
firewall-cmd --zone=public --add-port=3306/tcp --permanent
重启防火墙
firewall-cmd --reload
查看防火墙状态
firewall-cmd --state
网友评论