centos7 安装mysql

方法一

 #查找mysql
 rpm -qa | grep mysql
 #查找mariadb
 rpm -qa |grep mariadb
 #没有则不用卸载,有则卸载
rpm -e --nodeps 名称
  • 把下载好的mysql传至centos7

为了方便管理,我把mysql上传至新创建的mysql目录下;如果不会传送至centos7可以去下载finalshell等连接工具,当然如果自己的本机电脑是Linux系统就不需要

  • 查看是否存在libaio
rpm -qa|grep libaio
#如果没有则进行安装
yum install -y libaio
  • 解压
 tar -xf mysql-8.0.28-1.el7.x86_64.rpm-bundle.tar

在这里插入图片描述

  • 安装(有顺序要求)
rpm -ivh mysql-community-common-8.0.28-1.el7.x86_64.rpm --nodeps --force
rpm -ivh mysql-community-libs-8.0.28-1.el7.x86_64.rpm --nodeps --force
rpm -ivh mysql-community-devel-8.0.28-1.el7.x86_64.rpm --nodeps --force
rpm -ivh mysql-community-libs-compat-8.0.28-1.el7.x86_64.rpm --nodeps --force
rpm -ivh mysql-community-client-8.0.28-1.el7.x86_64.rpm  --nodeps --force
rpm -ivh mysql-community-server-8.0.28-1.el7.x86_64.rpm --nodeps --force
  • 启动MySQL服务
systemctl start mysqld
  • 设置MySQL服务开机自启动。
systemctl enable mysqld
  • 命令查看/var/log/mysqld.log文件,获取并记录root用户的初始密码。
grep 'temporary password' /var/log/mysqld.log

在这里插入图片描述

  • 对MySQL进行安全性配置。
mysql_secure_installation

(1)重置密码

Enter password for user root: #输入已获取的root用户初始密码

The existing password for the user account root has expired. Please set a new password.

New password: #输入新的MySQL密码(密码安全性要求比较高,密码需要有大写字母、小写字母、数字、字符组合,;比如:Qkkf56439!)

Re-enter new password: #重复输入新的MySQL密码
The 'validate_password' component is installed on the server.
The subsequent steps will run with the existing configuration
of the component.
Using existing password for root.
Change the password for root ? ((Press y|Y for Yes, any other key for No) :Y #输入Y选择更新MySQL密码。您也可以输入N不再更新MySQL密码。

New password: #输入新的MySQL密码

Re-enter new password: #重复输入新的MySQL密码

Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) :Y #输入Y确认使用已设置的密码。

(2)删除匿名用户。

By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) :Y #输入Y删除MySQL默认的匿名用户。
Success.

(3)禁止root账号远程登录(出于安全考虑)

Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) :Y #输入Y禁止root远程登录。
Success.

(4)删除test库以及对test库的访问权限。

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) :Y #输入Y删除test库以及对test库的访问权限。
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

(5)重新加载授权表。

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) :Y #输入Y重新加载授权表。
Success.

All done!
  • 远程访问MySQL数据库

(1)登录

  • mysql -uroot -p

(2)创建远程访问账户

mysql> create user 'dmsTest'@'%' identified by '123456'; #创建数据库用户dmsTest,并授予远程连接权限。
mysql> grant all privileges on *.* to 'dmsTest'@'%'; #为dmsTest用户授权数据库所有权限。
mysql> flush privileges; #刷新权限。
  • 6
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小鹿~~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值