如何在阿里云centos7安装mysql8数据库
一、安装mysql
1. mysql官网查找仓库源镜像,选择downloads
https://www.mysql.com/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 #开机不自启动