centos安装mysql5
时间: 2024-09-04 09:03:56 浏览: 148
centos安装MySQL5.pdf
CentOS 安装 MySQL 5.x 的步骤如下:
1. **更新系统**:
首先,确保你的 CentOS 系统是最新的。打开终端并运行:
```
sudo yum update -y
```
2. **添加MySQL官方仓库**:
```bash
sudo tee /etc/yum.repos.d/mysql-community.repo <<EOF
[mysql57-community]
name=MySQL Community Server 5.7 Repository
baseurl=https://mirrors.aliyun.com/repo/epel/x86_64/
gpgkey=https://mirrors.aliyun.com/repo/epel/RPM-GPG-KEY-EPEL-57
gpgcheck=1
enabled=1
priority=90
EOF
```
或者其他可用的镜像源。
3. **安装MySQL**:
更新软件列表并安装 MySQL:
```bash
sudo yum install mysql-community-server -y
```
4. **启动服务并设置开机自启**:
```bash
sudo systemctl start mysqld
sudo systemctl enable mysqld
```
5. **配置MySQL**:
打开安全模式并创建root用户的密码:
```bash
sudo mysqld_safe --skip-grant-tables & sleep 30
mysql -u root
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('your_new_password');
FLUSH PRIVILEGES;
exit
```
6. **启动正常服务**:
关闭安全模式并重启服务:
```bash
sudo killall mysqld_safe
sudo systemctl restart mysqld
```
7. **验证安装**:
登录到MySQL命令行并检查是否成功连接:
```bash
mysql -u root -p
```
阅读全文