mysql拒绝访问root用户_Linux部署MySql数据库(超简单)

本文介绍了如何在Linux系统中安装MySQL 5.7.31,包括更新YUM源、安装MySQL、配置MySQL服务、设置root用户密码和安全性,以及远程访问MySQL数据库的步骤。在安全配置中,强调了修改root用户密码、删除匿名用户、禁止root远程登录和删除test库等操作。
摘要由CSDN通过智能技术生成

MySQL:5.7.31(免安装包 直接命令下载))

本示例中,MySQL相关安装路径说明如下:

配置文件:/etc/my.cnf

数据存储:/var/lib/mysql

命令文件:/usr/bin和/usr/sbin


步骤一:准备环境

使用账号密码 登入SSH(Xsell)远程连接工具。

步骤二:安装MySQL

1.运行以下命令更新YUM源。(可自行选择 8.0)

rpm -Uvh http:// dev.mysql.com/get/mysql 57-community-release-el7-9.noarch.rpm

2.运行以下命令安装MySQL。

yum -yinstallmysql-community-server

9ef88e16a4aa7c5db6366c7c0b2acb41.png


图一

3.运行以下命令查看MySQL版本号。

mysql -V

返回结果如下,表示MySQL安装成功。

mysql Ver14.14Distrib5.7.31,forLinux (x86_64)usingEditLinewrapper (版本号不同有变)

步骤三:配置MySQL

1.运行以下命令启动MySQL服务。

systemctlstartmysqld

2.运行以下命令设置MySQL服务开机自启动。

systemctlenablemysqld

3.运行以下命令查看/var/log/mysqld.log文件,获取并记录root用户的初始密码。

grep'temporary password'/var/log/mysqld.log

执行​命令结果示例如下。

2020-04-08T08:12:07.893939Z1[Note] Atemporarypasswordisgeneratedforroot@localhost: xvlo1lZs7>uI

4.运行下列命令对MySQL进行安全性配置。

mysql_secure_installation

4.1.重置root用户的密码。

Enterpasswordforuserroot: #输入上一步获取的root用户初始密码The'validate_password'pluginisinstalledontheserver.The subsequent steps will runwiththe existingconfigurationofthe plugin.Usingexistingpasswordforroot.Estimated strengthofthepassword:100Change thepasswordforroot ? ((Press y|YforYes,anyother keyforNo) : Y #是否更改root用户密码,输入YNewpassword: #输入新密码,长度为8至30个字符,必须同时包含大小写英文字母、数字和特殊符号。特殊符号可以是()` ~!@#$%^&*-+=|{}[]:;‘<>,.?/Re-enternewpassword: #再次输入新密码Estimated strengthofthepassword:100Doyou wishtocontinuewiththepasswordprovided?(Press y|YforYes,anyother keyforNo) : Y #是否继续操作,输入Y

4.2.删除匿名用户账号。

Bydefault, a MySQL installation has an anonymoususer, allowing anyonetologintoMySQLwithouthavingtohave auseraccount createdforthem. Thisisintendedonlyfortesting,andtomake the installation go abitsmoother. You should remove thembeforemovingintoa production environment.Remove anonymous users? (Press y|YforYes,anyother keyforNo) : Y #是否删除匿名用户,输入YSuccess.

4.3禁止root账号远程登录。

Disallowrootloginremotely?(Pressy|YforYes,anyotherkeyforNo):Y#禁止root远程登录,输 入YSuccess.

4.4删除test库以及对test库的访问权限

Removetestdatabaseandaccesstoit?(Pressy|YforYes,anyotherkeyforNo):Y#是否删除test库和对它的访问权限,输入Y-Droppingtestdatabase...Success.

4.5重新加载授权表。

Reloadprivilegetablesnow?(Pressy|YforYes,anyotherkeyforNo):Y#是否重新加载授权表,输入YSuccess.Alldone!

步骤四:远程访问MySQL数据库

在ECS实例上,创建远程登录MySQL的账号。

运行以下命令后,输入root用户的密码登录MySQL

1.在ECS实例上,创建远程登录MySQL的账号 运行以下命令后,输入root用户的密码登录MySQL

mysql -uroot -p

2.依次运行以下命令创建远程登录MySQL的账号。示例账号为zyj、密码为123456

mysql>grantallon*.*to'zyj'@'%'IDENTIFIEDBY'123456'; #使用root替换zyj,可设置为允许root账号远程登录。mysql> flushprivileges;

如有疑问欢迎留言~~~~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值