连接MySQL报错,is not allowed to connect to this MySQL server

这篇具有很好参考价值的文章主要介绍了连接MySQL报错,is not allowed to connect to this MySQL server。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

问题描述:

        本机装的MySQL数据库,本机可以正常连接,其他机器访问报错,is not allowed to connect to this MySQL server,防火墙等其他策略均配置没问题

连接MySQL报错,is not allowed to connect to this MySQL server,Java,MySQL,mysql,数据库,java


 解决方案:

        出现该问题的原因是,MySQL数据库只允许自身所在的本机器连接,不允许远程连接。

1、在MySQL所在服务器上使用命令登录到MySQL数据库中

mysql -u root -p

连接MySQL报错,is not allowed to connect to this MySQL server,Java,MySQL,mysql,数据库,java

2、选择mysql数据库,并查询权限

use mysql;
 
select host from user where user='root';

连接MySQL报错,is not allowed to connect to this MySQL server,Java,MySQL,mysql,数据库,java

可以看到,执行查询语句后得到的数据结果中 host 的值是 localhost

我们执行update语句修改权限

update user set host = '%' where user ='root';

连接MySQL报错,is not allowed to connect to this MySQL server,Java,MySQL,mysql,数据库,java

3、刷新配置

flush privileges;

连接MySQL报错,is not allowed to connect to this MySQL server,Java,MySQL,mysql,数据库,java

再次执行查询权限语句

select host from user where user='root';

连接MySQL报错,is not allowed to connect to this MySQL server,Java,MySQL,mysql,数据库,java

可以看到,已经修改成功

4、最后再次用其他机器连接MySQL数据库,可以连接成功

DBMS: MySQL (版本 5.7.41)
区分大小写: 普通形式=lower, 分隔形式=lower
驱动程序: MySQL Connector/J (版本 mysql-connector-java-8.0.25 (Revision: 08be9e9b4cba6aa115f9b27b215887af40b159e0),JDBC4.2)

Ping: 29毫秒
SSL: yes

连接MySQL报错,is not allowed to connect to this MySQL server,Java,MySQL,mysql,数据库,java


<?xml version="1.0" encoding="UTF-8"?>
 
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at
    http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->
 
<!--
 | This is the configuration file for Maven. It can be specified at two levels:
 |
 |  1. User Level. This settings.xml file provides configuration for a single user,
 |                 and is normally provided in ${user.home}/.m2/settings.xml.
 |
 |                 NOTE: This location can be overridden with the CLI option:
 |
 |                 -s /path/to/user/settings.xml
 |
 |  2. Global Level. This settings.xml file provides configuration for all Maven
 |                 users on a machine (assuming they're all using the same Maven
 |                 installation). It's normally provided in
 |                 ${maven.conf}/settings.xml.
 |
 |                 NOTE: This location can be overridden with the CLI option:
 |
 |                 -gs /path/to/global/settings.xml
 |
 | The sections in this sample file are intended to give you a running start at
 | getting the most out of your Maven installation. Where appropriate, the default
 | values (values used when the setting is not specified) are provided.
 |
 |-->
<settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.0.xsd">
  <!-- localRepository
   | The path to the local repository maven will use to store artifacts.
   |
   | Default: ${user.home}/.m2/repository
  <localRepository>/path/to/local/repo</localRepository>
  -->
 
  <!-- interactiveMode
   | This will determine whether maven prompts you when it needs input. If set to false,
   | maven will use a sensible default value, perhaps based on some other setting, for
   | the parameter in question.
   |
   | Default: true
  <interactiveMode>true</interactiveMode>
  -->
 
  <!-- offline
   | Determines whether maven should attempt to connect to the network when executing a build.
   | This will have an effect on artifact downloads, artifact deployment, and others.
   |
   | Default: false
  <offline>false</offline>
  -->
 
  <!-- pluginGroups
   | This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
   | when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
   | "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
   |-->
  <pluginGroups>
    <!-- pluginGroup
     | Specifies a further group identifier to use for plugin lookup.
    <pluginGroup>com.your.plugins</pluginGroup>
    -->
  </pluginGroups>
 
  <!-- proxies
   | This is a list of proxies which can be used on this machine to connect to the network.
   | Unless otherwise specified (by system property or command-line switch), the first proxy
   | specification in this list marked as active will be used.
   |-->
  <proxies>
    <!-- proxy
     | Specification for one proxy, to be used in connecting to the network.
     |
    <proxy>
      <id>optional</id>
      <active>true</active>
      <protocol>http</protocol>
      <username>proxyuser</username>
      <password>proxypass</password>
      <host>proxy.host.net</host>
      <port>80</port>
      <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
    </proxy>
    -->
  </proxies>
 
  <!-- servers
   | This is a list of authentication profiles, keyed by the server-id used within the system.
   | Authentication profiles can be used whenever maven must make a connection to a remote server.
   |-->
  <servers>
    <!-- server
     | Specifies the authentication information to use when connecting to a particular server, identified by
     | a unique name within the system (referred to by the 'id' attribute below).
     |
     | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
     |       used together.
     |
    <server>
      <id>deploymentRepo</id>
      <username>repouser</username>
      <password>repopwd</password>
    </server>
    -->
 
    <!-- Another sample, using keys to authenticate.
    <server>
      <id>siteServer</id>
      <privateKey>/path/to/private/key</privateKey>
      <passphrase>optional; leave empty if not used.</passphrase>
    </server>
    -->
  </servers>
 
  <!-- mirrors
   | This is a list of mirrors to be used in downloading artifacts from remote repositories.
   |
   | It works like this: a POM may declare a repository to use in resolving certain artifacts.
   | However, this repository may have problems with heavy traffic at times, so people have mirrored
   | it to several places.
   |
   | That repository definition will have a unique id, so we can create a mirror reference for that
   | repository, to be used as an alternate download site. The mirror site will be the preferred
   | server for that repository.
   |-->
  <mirrors>
    <!-- mirror
     | Specifies a repository mirror site to use instead of a given repository. The repository that
     | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
     | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
     |
    <mirror>
      <id>mirrorId</id>
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://my.repository.com/repo/path</url>
    </mirror>
     -->
    <mirror>
      <id>maven-default-http-blocker</id>
      <mirrorOf>external:http:*</mirrorOf>
      <name>Pseudo repository to mirror external repositories initially using HTTP.</name>
      <url>http://0.0.0.0/</url>
      <blocked>true</blocked>
    </mirror>
  </mirrors>
 
  <!-- profiles
   | This is a list of profiles which can be activated in a variety of ways, and which can modify
   | the build process. Profiles provided in the settings.xml are intended to provide local machine-
   | specific paths and repository locations which allow the build to work in the local environment.
   |
   | For example, if you have an integration testing plugin - like cactus - that needs to know where
   | your Tomcat instance is installed, you can provide a variable here such that the variable is
   | dereferenced during the build process to configure the cactus plugin.
   |
   | As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles
   | section of this document (settings.xml) - will be discussed later. Another way essentially
   | relies on the detection of a system property, either matching a particular value for the property,
   | or merely testing its existence. Profiles can also be activated by JDK version prefix, where a
   | value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'.
   | Finally, the list of active profiles can be specified directly from the command line.
   |
   | NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact
   |       repositories, plugin repositories, and free-form properties to be used as configuration
   |       variables for plugins in the POM.
   |
   |-->
  <profiles>
    <!-- profile
     | Specifies a set of introductions to the build process, to be activated using one or more of the
     | mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/>
     | or the command line, profiles have to have an ID that is unique.
     |
     | An encouraged best practice for profile identification is to use a consistent naming convention
     | for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc.
     | This will make it more intuitive to understand what the set of introduced profiles is attempting
     | to accomplish, particularly when you only have a list of profile id's for debug.
     |
     | This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo.
    <profile>
      <id>jdk-1.4</id>
      <activation>
        <jdk>1.4</jdk>
      </activation>
      <repositories>
        <repository>
          <id>jdk14</id>
          <name>Repository for JDK 1.4 builds</name>
          <url>http://www.myhost.com/maven/jdk14</url>
          <layout>default</layout>
          <snapshotPolicy>always</snapshotPolicy>
        </repository>
      </repositories>
    </profile>
    -->
 
    <!--
     | Here is another profile, activated by the system property 'target-env' with a value of 'dev',
     | which provides a specific path to the Tomcat instance. To use this, your plugin configuration
     | might hypothetically look like:
     |
     | ...
     | <plugin>
     |   <groupId>org.myco.myplugins</groupId>
     |   <artifactId>myplugin</artifactId>
     |
     |   <configuration>
     |     <tomcatLocation>${tomcatPath}</tomcatLocation>
     |   </configuration>
     | </plugin>
     | ...
     |
     | NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to
     |       anything, you could just leave off the <value/> inside the activation-property.
     |
    <profile>
      <id>env-dev</id>
      <activation>
        <property>
          <name>target-env</name>
          <value>dev</value>
        </property>
      </activation>
      <properties>
        <tomcatPath>/path/to/tomcat/instance</tomcatPath>
      </properties>
    </profile>
    -->
  </profiles>
 
  <!-- activeProfiles
   | List of profiles that are active for all builds.
   |
  <activeProfiles>
    <activeProfile>alwaysActiveProfile</activeProfile>
    <activeProfile>anotherAlwaysActiveProfile</activeProfile>
  </activeProfiles>
  -->
</settings>

1。 改表法。可能是你的帐号不允许从远程登陆,只能在localhost。这个时候只要在localhost的那台电脑,登入mysql后,更改 "mysql" 数据库里的 "user" 表里的 "host" 项,从"localhost"改称"%"

Sql代码 复制代码

   1. mysql -u root -pvmwaremysql>use mysql; 

   2. mysql>update user set host = '%' where user = 'root'; 

   3. mysql>select host, user from user; 

2. 授权法。例如,你想myuser使用mypassword从任何主机连接到mysql服务器的话。

Sql代码 复制代码

  1. GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH

      GRANT OPTION;  

  2.FLUSH   PRIVILEGES; 文章来源地址https://www.toymoban.com/news/detail-595808.html

到了这里,关于连接MySQL报错,is not allowed to connect to this MySQL server的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包赞助服务器费用

相关文章

  • MySQL连接时出现Host ‘::1‘ is not allowed to connect to this MySQL server

    MySQL连接时出现Host ‘::1‘ is not allowed to connect to this MySQL server

    报错原因 之前想着要提高一下连接速度,所以在my.ini中加入了:skip-name-resolve,当时的数据库root账号设置的登录权限是%,因此没有出现连接错误,这次因为是新建数据库,root账号的登录权限默认是localhost,所以就出现了这个问题 当skip-name-resolve被开启后,MySQL就不会进行D

    2024年02月05日
    浏览(9)
  • 连接MySQL出现Host is not allowed to connect to this MySQL server 解决方法

    连接MySQL出现Host is not allowed to connect to this MySQL server 解决方法

    翻译: ‘不允许主机连接到此MySQL服务器’ (意思是本地账号连接可以登录,但是远程登陆不行 进入mysql 输入数据库密码 不知道密码可以去查 输入该命令行后看 root@localhost:后的内容就是密码 进入后依次输入下列命令行 最后退出mysql

    2024年02月16日
    浏览(12)
  • MySQL登录报错1130:1130 Host ***.***.***.*** is not allowed to connect to this MySQL server

    MySQL登录报错1130:1130 Host ***.***.***.*** is not allowed to connect to this MySQL server

    一、问题发现 ​ 从Navicat登录MySQL时报错:1130 Host . . . is not allowed to connect to this MySQL server ​ 原因分析:报错信息表示需要连接的数据库不允许其他主机进行访问,这是因为MySQL的系统数据库mysql中的user表没有配置远程访问主机的登录信息,只有localhost本地登录的信息(如下

    2024年02月13日
    浏览(10)
  • Mysql报错:1130-host ... is not allowed to connect to this MySql server如何处理

    Mysql报错:1130-host ... is not allowed to connect to this MySql server如何处理

    PS:如果出现报错,忽略即可:ERROR 1130: Host ‘192.168.10.173’ is not allowed to connect to this MySQL ERROR 1062 (23000): Duplicate entry ‘%-root’ for key ‘PRIMARY’ 忽略即可

    2024年02月15日
    浏览(12)
  • Navicat连接MySQL数据库提示(1130-host ... is not allowed to connect to this MySql server)

    Navicat连接MySQL数据库提示(1130-host ... is not allowed to connect to this MySql server)

    问题原因:所连接的用户帐号没有远程连接的权限,只能在本机(localhost)登录权限。 1.关闭防火墙或者防火墙打开某端口 2.修改数据库表 将 mysql 数据库里的 user 表里的 host 项,从 “localhost” 改成 “%”  3.进行授权

    2024年02月01日
    浏览(13)
  • Mysql远程登录报错:Host ‘192.168.137.1‘ is not allowed to connect to this MySQL server

          连接失败是因为数据库没有对指定的ip的服务器地址的连接进行授权,许哦一需要先进行授权。  1. 改表  先登录登录数据库:mysql -u root -p  2.授权 第一步:root用户登录;mysqlmysql -u root -p rootpassword; 第二步:赋予权限; 第三步:刷新数据库; 一定要执行 (1)授权myuse

    2024年02月10日
    浏览(8)
  • 解决1130-Host‘ ‘is not allowed to connect to this MySQL server,实现远程连接本地数据库

    解决1130-Host‘ ‘is not allowed to connect to this MySQL server,实现远程连接本地数据库

    在使用Navicat远程连接本地数据库时,遇到了这样一个问题, 我使用 本地主机的地址,连接本地的数据库,报错host ‘’ is not allowed to connect to this mysql server。 上网上查了一下资料,原来自己安装在本地的mysql默认时不允许进行远程登陆,如果想要远程访问本地的数据库需要修

    2024年02月11日
    浏览(12)
  • Host is not allowed to connect to this MySQL server

    Host is not allowed to connect to this MySQL server

    问题:win10 系统上运行node,运行提示:Host is not allowed to connect to this MySQL server。 在windows10上面装完MySQL8.0.28,发现本地可以使用Navicat进行连接 ,但是在vue项目中调用node接口连接mysql却报错Host is not allowed to connect to this MySQL server 这个错误其实就是我们的MySQL不允许远程登录,所

    2024年02月13日
    浏览(12)
  • Host is not allowed to connect to this MySQL server解决方法

    Host is not allowed to connect to this MySQL server解决方法

    这个错误,其实就是我们安装的MySQL不允许远程登录,解决方法如下: 1. 在装有MySQL的机器上登录MySQL mysql -u root -p密码,执行如下命令: 该结果表示是当前的root用户限制在当前的ip内访问的,需要修改他的访问域。 2. 执行命令: 3.执行 FLUSH PRIVILEGES 或者重启 MySQL 即可;

    2024年02月04日
    浏览(12)
  • Host is not allowed to connect to this MySQL server的解决办法

    Host is not allowed to connect to this MySQL server的解决办法

    首先我们在学习Java时,我们链接的MySql里面没有数据,我们也不知道有些什么数据,于是我们会有一种办法来继续进行我们代码的编写。 1.第一步是我的电脑必须要和我想使用的那个人的电脑处在同一个局域网下,例如学生在学校里面可以两台电脑同时连上学校的校园网;我

    2024年02月11日
    浏览(10)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包