转自:https://yq.aliyun.com/articles/285398
阿里云ECS服务器CentOS7上安装MySql服务
----------------------------------------------
使用root登录
1.确保服务器系统处于最新状态
[root@localhost ~]# yum -y update
如果显示以下内容说明已经更新完成
Replaced:
grub2.x86_64 1:2.02-0.64.el7.centos grub2-tools.x86_64 1:2.02-0.64.el7.centos
Complete!
2.重启服务器
[root@localhost ~]# reboot
3.首先检查是否已经安装,如果已经安装先删除以前版本,以免安装不成功
[root@localhost ~]# php -v
或
[root@localhost ~]# rpm -qa | gerp mysql
或
[root@localhost ~]# yum list installed | grep mysql
如果显示以下内容说明没有安装服务
-bash: gerp: command not found
4.下载MySql安装包
[root@localhost ~]# rpm -ivh http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
或
[root@localhost ~]# rpm -ivh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
5.安装MySql
[root@localhost ~]# yum install -y mysql-server
或
[root@localhost ~]# yum install mysql-community-server
如果显示以下内容说明安装成功
Complete!
6.设置开机启动Mysql
[root@localhost ~]# systemctl enable mysqld.service
7.检查是否已经安装了开机自动启动
[root@localhost ~]# systemctl list-unit-files | grep mysqld
如果显示以下内容说明已经完成自动启动安装
mysqld.service enabled
8.设置开启服务
[root@localhost ~]# systemctl start mysqld.service
9.查看MySql默认密码
[root@localhost ~]# grep 'temporary password' /var/log/mysqld.log
10.登陆MySql,输入用户名和密码
[root@localhost ~]# mysql -uroot -p
11.修改当前用户密码
mysql>SET PASSWORD = PASSWORD('你的密码');
12.开启远程登录,授权root远程登录
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '你的密码' WITH GRANT OPTION;
13.命令立即执行生效
mysql>flush privileges;