Files
one-click-shell/mysql80-yum-install/README.md
2022-04-15 09:11:59 +08:00

90 lines
1.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 安装 Mysql
### 脚本描述
```
centos8 使用 yum 安装 MySQL8.0 并启动
```
### 脚本内容
[mysql80-yum-install.sh](mysql80-yum-install.sh)
```shell
#!/bin/bash
# '\033[字背景颜色;字体颜色m字符串\033[0m'
GREENCOLOR='\033[1;32m'
NC='\033[0m'
DOWNLOAD_DIR="/usr/src"
SOURCE_DIR="http://repo.mysql.com/mysql80-community-release-el8-3.noarch.rpm"
echo "===================================================="
printf "${GREENCOLOR} MySQL's install begin ${NC} \n"
echo "===================================================="
# 安装 MySQL
# 如果安装过 MySQL, 先卸载
yum -y remove mysql
# 进入目录
cd $DOWNLOAD_DIR
# 下载 MySQL 包
wget $SOURCE_DIR
# 安装 MySQL 的 yum 源
rpm -ivh mysql80-community-release-el8-3.noarch.rpm
# 安装 MySQL
yum -y install mysql-server
# 启动 MySQL
systemctl start mysqld
systemctl status mysqld
echo "===================================================="
printf "${GREENCOLOR} MySQL's install finish ${NC} \n"
cat /var/log/mysqld.log | grep 'temporary password'
echo "===================================================="
```
### 执行
```shell
bash mysql80-yum-install.sh
```
### 如何修改 root 密码?
1、首先查看初始化的密码。
```sh
# 查看初始密码
cat /var/log/mysql/mysqld.log
```
2、用初始密码登录 MySQL然后修改 root 的密码。
```sql
ALTER user 'root'@'localhost' IDENTIFIED BY 'duiying*D123';
```
3、刷新权限。
```sql
FLUSH PRIVILEGES;
```
4、允许其他主机连接 MySQL。
```sql
use mysql;
update user set host = '%' where user = 'root';
FLUSH PRIVILEGES;
```
### 如何设置 MySQL 开机自启动?
```sh
# 编辑文件
vim /etc/rc.log
# 在尾部新增下面这行
service mysqld start
```