MySQL is not able to solve the problem of native access based on localhost

Source: Internet
Author: User

Introduction: In the local access to the database, the general use of localhost, 127.0.0.1来 for database access, but I have encountered these days only through 127.0.0.1来 access, but not based on localhost to access, very strange .....

Environment Introduction

Centos 7, Mariadb 10.2 Tomcat 8, Java War app

Problem performance

Connection information such as localhost:3306 was used in the database connection, but during the start of the service, the connection database error message was reported:

Java.sql.SQLException:Access denied for user ' bladestone ' @ ' localhost ' (using Password:yes)
at COM. MySQL.jdbc.SQLError.createSQLException (sqlerror.java:1078)
At Com.mysql.jdbc.MysqlIO.checkErrorPacket (mysqlio.java:4237)
At Com.mysql.jdbc.MysqlIO.checkErrorPacket (mysqlio.java:4169)
At Com.mysql.jdbc.MysqlIO.checkErrorPacket (mysqlio.java:928)
At Com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication (mysqlio.java:1750)
At Com.mysql.jdbc.MysqlIO.doHandshake (mysqlio.java:1290)
At Com.mysql.jdbc.ConnectionImpl.coreConnect (connectionimpl.java:2493)
At Com.mysql.jdbc.ConnectionImpl.connectOneTryOnly (connectionimpl.java:2526)
At Com.mysql.jdbc.ConnectionImpl.createNewIO (connectionimpl.java:2311)
At Com.mysql.jdbc.ConnectionImpl. (connectionimpl.java:834)
At Com.mysql.jdbc.JDBC4Connection. (jdbc4connection.java:47)
At Sun.reflect.GeneratedConstructorAccessor62.newInstance (Unknown Source)
At Sun.reflect.DelegatingConstructorAccessorImpl.newInstance (delegatingconstructoraccessorimpl.java:45)
At Java.lang.reflect.Constructor.newInstance (constructor.java:526)
At Com.mysql.jdbc.Util.handleNewInstance (util.java:411)
At Com.mysql.jdbc.ConnectionImpl.getInstance (connectionimpl.java:416)
At Com.mysql.jdbc.NonRegisteringDriver.connect (nonregisteringdriver.java:347)
At Com.alibaba.druid.filter.FilterChainImpl.connection_connect (filterchainimpl.java:142)
At Com.alibaba.druid.filter.stat.StatFilter.connection_connect (statfilter.java:211)
At Com.alibaba.druid.filter.FilterChainImpl.connection_connect (filterchainimpl.java:136)
At Com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection (druidabstractdatasource.java:1271)
At Com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection (druidabstractdatasource.java:1325)
At Com.alibaba.druid.pool.druiddatasource$createconnectionthread.run (druiddatasource.java:1215)
[Com.alibaba.druid.pool.druiddatasource]create Connection Error

However, switching to 127.0.0.1 can be accessed normally, and the problem is on localhost.

Analysis process

Ping localhost

This command can be accessed normally, in other words, localhost is a correct domain name and can be parsed correctly.
Later, in retrospect, the following command was used to authorize access:

Grant all privileges in zhouzdb . * to ' Zhouz ' @ ' percent ' identified by ' 1234 ';

The trailing '% ' is a wildcard character to match the IP address, but can it match the special domain name of localhost? Verify that you know:

Grant all privileges in zhouzdb . * to ' Zhouz ' @ ' locahost ' identified by ' 1234 ';

Revisit MySQL locally and the results were successfully accessed. The result proves that:% cannot match localhost this special domain address information, need to add additional settings.

Summarize

In the analysis process here, one of the questions that is taken for granted is whether the wildcard can match the problem of localhost, which was thought to be from the outset, but in fact it is not. Because of this erroneous assumption, the result has taken a lot of time to analyze the problem, and the detour is very worthwhile to ponder.

http://www.woaipu.com/shops/zuzhuan/61406
http://nanning.xjwy.cn/f/bencandy.php?fid=43&id=117777
http://nanning.xjwy.cn/f/bencandy.php?fid=43&id=117890
http://nanning.xjwy.cn/f/bencandy.php?fid=43&id=117994
http://nanning.xjwy.cn/f/bencandy.php?fid=43&id=118376

MySQL is not able to solve the problem of native access based on localhost

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.