在弹性云服务器上安装MySQL
使用root登录刚创建的弹性云服务器,然后进行MySQL安装操作:
- 确保服务器系统处于最新状态
yum -y update
如果显示以下内容说明已经更新完成
Replaced:
grub2.x86_64 1:2.02-0.64.el7.centos grub2-tools.x86_64 1:2.02-0.64.el7.centosComplete!
- 重启服务器
reboot
- 首先检查是否已经安装,如果已经安装先删除以前版本,以免安装不成功
php -v
或
rpm -qa | gerp mysql
或
yum list installed | grep mysql
如果显示以下内容说明没有安装服务
-bash: gerp: command not found
- 下载MySQL安装包
rpm -ivh http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
或
rpm -ivh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
- 安装MySQL
yum install -y mysql-server
或
yum install mysql-community-server
如果显示以下内容说明安装成功
Complete!
如果在安装过程中遇到“The GPG keys listed for the “MySQL 5.7 Community Server” repository are already installed but they are not correct for this package.Check that the correct key URLs are configured for this repository.”报错,请先执行:
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
再重新执行本步骤安装命令
- 设置开机启动MySQL
systemctl enable mysqld.service
- 检查是否已经安装了开机自动启动
systemctl list-unit-files | grep mysqld
如果显示以下内容说明已经完成自动启动安装
mysqld.service enabled
- 设置开启服务
systemctl start mysqld.service
- 查看MySQL默认密码
grep 'temporary password' /var/log/mysqld.log
- 登录MySQL,输入用户名和密码
mysql -uroot -p
- 修改当前用户密码
mysql>SET PASSWORD = PASSWORD('Abc123!_');
- 开启远程登录,授权root远程登录
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'a123456!' WITH GRANT OPTION;
- 命令立即执行生效
mysql>flush privileges;