一、安装MysqL
1. MysqL官网查找仓库源镜像,选择downloads
2. 找到社区版
3. 选择yum仓库
4. 选择对应版本,点击Download(centos7-->选择linux7)
5. 右键下载链接,获得地址
https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
6. 创建目录并下载MysqL
mkdir -p /usr/dev/MysqL8
cd /usr/dev/MysqL8
wget https://dev.MysqL.com/get/MysqL80-community-release-el7-3.noarch.rpm
如果提示没有wget命令,则需要安装wget
yum install wget
7. 安装MysqL8安装源
rpm -ivh MysqL80-community-release-el7-3.noarch.rpm
8. 安装MysqL服务
yum install MysqL-server
选择y后等待下载完成
如果下载速度慢可更换yum源
备份原yum源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
设置aliyun的yum源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
更新缓存
yum makecache
yum -y update
9. yum安装的MysqL目录
MysqL 目录 | 说明 |
---|---|
/var/lib/MysqL | MysqL数据文件存放路径,可自定义 |
/etc/my.cnf | MysqL配置文件路径 |
/usr/lib64/MysqL | MysqL库文件路径 |
/usr/bin/MysqL* | MysqL二进制可执行文件路径 |
/etc/rc.d/init.d/MysqLd | MysqL服务管理脚本地址 |
/var/log/MysqLd.log | MysqL日志文件路径 |
二、配置MysqL
1. 查看MysqL服务状态
【关闭状态】
2. 启动MysqL服务
systemctl start MysqLd.service
3. 查看初始化密码
tail -f /var/log/MysqLd.log
4. 默认密码登录后修改密码
MysqL -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'mypassword';
5. 创建新用户并授权访问
-- 新增用户
create user 'myuser'@'%' identified with MysqL_native_password by 'mypassword';
-- 授权访问
grant all privileges on *.* to 'myuser'@'%';
-- 刷新授权
flush privileges;
-- 退出root
exit;
6. 设置MysqL开机自启
systemctl enable MysqLd.service
三、常用命令
rpm -qa | grep MysqL #搜索查询 MysqL
pwd #查看当前路径
cd #切换到指定目录
启动和管理MysqL:
systemctl start MysqLd.service #启动
systemctl stop MysqLd.service #关闭
systemctl restart MysqLd.service #重启
systemctl status MysqLd.service #查看状态
systemctl enable MysqLd.service #开机自启动
systemctl disable MysqLd.service #开机不自启动