使用PuTTY以root身份登录
1.确保服务器系统处于最新状态
[root@localhost ~]# yum -y update
显示如下内容说明无需更新
[root@izbp1acp86oa3j33d188jrz ~]# yum -y update
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
No packages marked for update
2.重启服务器
[root@localhost ~]# reboot
3.首先检查是否已经安装,如果已经安装先删除以前版本,以免安装不成功
[root@localhost ~]# php -v
或
[root@localhost ~]# rpm -qa | gerp mysql
或
[root@localhost ~]# yum list installed | grep mysql
出现以下内容说明没安装mysql:
[root@izbp1acp86oa3j33d188jrz ~]# php -v
-bash: php: command not found
[root@izbp1acp86oa3j33d188jrz ~]# rpm -qa | gerp mysql
-bash: gerp: command not found
[root@izbp1acp86oa3j33d188jrz ~]# yum list installed | grep mysql
[root@izbp1acp86oa3j33d188jrz ~]#
4.下载MySql安装包
我选择了第一个安装包
[root@izbp1acp86oa3j33d188jrz ~]# rpm -ivh http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
Retrieving http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
warning: /var/tmp/rpm-tmp.xfoYUs: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql57-community-release-el7-8 ################################# [100%]
5.安装MySql
[root@localhost ~]# yum install -y mysql-server
或
[root@localhost ~]# yum install mysql-community-server
[root@izbp1acp86oa3j33d188jrz ~]# yum install -y mysql-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(‘Abc123!_’);
12.开启远程登录,授权root远程登录
mysql>GRANT ALL PRIVILEGES ON . TO ‘root’@’%’ IDENTIFIED BY ‘a123456!’ WITH GRANT OPTION;
13.命令立即执行生效
mysql>flush privileges;
14.配置阿里云网关
PS:其他命名:
检查并且显示Apache相关安装包
[root@localhost ~]# rpm -qa | grep mysql
删除MySql
[root@localhost ~]# yum remove -y mysql mysql mysql-server mysql-libs compat-mysql51
或
[root@localhost ~]# rpm -e mysql-community-libs-5.7.20-1.el7.x86_64 --nodeps
或
[root@localhost ~]# yum -y remove mysql-community-libs-5.7.20-1.el7.x86_64
查看MySql相关文件
[root@localhost ~]# find / -name mysql
重启MySql服务
[root@localhost ~]# service mysqld restart
查看MySql版本
[root@localhost ~]# yum repolist all | grep mysql
查看当前的启动的 MySQL 版本
[root@localhost ~]# yum repolist enabled | grep mysql
通过Yum来安装MySQL,会自动处理MySQL与其他组件的依赖关系
[root@localhost ~]# yum install mysql-community-server
查看MySQL安装目录
[root@localhost ~]# whereis mysql
启动MySQL服务
[root@localhost ~]# systemctl start mysqld
查看MySQL服务状态
[root@localhost ~]# systemctl status mysqld
关闭MySQL服务
[root@localhost ~]# systemctl stop mysqld
测试MySQL是否安装成功
[root@localhost ~]# mysql
查看MySql默认密码
[root@localhost ~]# grep ‘temporary password’ /var/log/mysqld.log
查看所有数据库
mysql>show databases;
退出登录数据库
mysql>exit;
查看所有数据库用户
mysql>SELECT DISTINCT CONCAT(‘User: ‘’’,user,’’’@’’’,host,’’’;’) AS query FROM mysql.user;