Caused by: java.sql.SQLException: Access denied for user 'dell-pc'@'xxxxx' (using password: YES)
今天遇到一個非常坑的異常。
在做SSM專案整合的時候,遇到了上面這個異常,我一看連線資料庫的username
怎麼變成了 dell-pc
,然而jdbc.properties
:
username=root
password=123456
spring配置為:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:property-placeholder location="classpath:jdbc.properties"/>
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${driver}"/>
<property name="jdbcUrl" value="${url}"/>
<property name="user" value="${username}"/>
<property name="password" value="${password}"/>
<property name="maxPoolSize" value="30"/>
<property name="minPoolSize" value="10"/>
<property name="autoCommitOnClose" value="false"/>
<property name="checkoutTimeout" value="0"/>
<property name="acquireRetryAttempts" value="2"/>
</bean>
其中<property name="user" value="${username}"/>
在設定的時候也能自動顯示username的值為root,一直報異常真頭疼。
後來我發現了兩種解決方案
第一種:直接把username通通改成name
第二種:<context:property-placeholder location="classpath:jdbc.properties"/>
後新增屬性system-properties-mode=”FALLBACK”:<context:property-placeholder location="classpath:jdbc.properties" system-properties-mode="FALLBACK"/>
系統預設為system-properties-mode=”ENVIRONMENT” 意思就是從系統環境中去讀取,把電腦名當做mysql的使用者名稱,修改之後,執行成功。
相關文章
- java.sql.SQLException: Access denied for user ‘root‘@‘localhost‘ (using password: YES)JavaSQLExceptionlocalhost
- 啟動報錯:Access denied for user 'root'@'localhost' (using password:YES)localhost
- 【MySQL】---1045-Access denied for user 'root'@'localhost'(using password :YES)MySqllocalhost
- ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password:YES)Errorlocalhost
- Access denied for user 'root'@'localhost' (using password: NO)localhost
- ERROR 1045 (28000): Access denied for user 'root'@'127.0.0.1' (using password: YES)Error127.0.0.1
- #1045 - Access denied for user 'root'@'localhost' (using password: NO)localhost
- SpringBoot中yml配置java.sql.SQLException: Access denied for user ‘root‘@‘localhost‘ (using password: NOSpring BootJavaSQLExceptionlocalhost
- vue專案中連線MySQL時,報錯ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost' (using password:YES)VueMySqlErrorlocalhost
- Linux錯誤 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)LinuxErrorlocalhost
- MySQL系列:Docker安裝 MySQL提示錯誤:Access denied for user'root'@'localhost' (using password:yes)MySqlDockerlocalhost
- mysql 1045, "Access denied for user 'root'@'localhost' (using password: NO)"MySqllocalhost
- MYSQL解決error: 'Access denied for user 'root'@'localhost' (using password:MySqlErrorlocalhost
- ERROR 1045: Access denied for user: 'root@localhost' (Using password: NO)Errorlocalhost
- mac os x 安裝mysql遇到 Access denied for user ‘root‘@‘localhost‘ (using password: YES)的解決方法MacMySqllocalhost
- linux安裝MySQL出現ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)LinuxMySqlErrorlocalhost
- Navicat遠端連線MySQL 提示1045 - Access denied for user 'root'@'223.74.158.192'(using password:YES)MySql
- 報錯”ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: NO)”Errorlocalhost
- SQLSTATE[HY000] [1045] Access denied for user ‘root‘@‘localhost‘ (using password: YES)”錯誤的隱藏解決辦法SQLlocalhost
- 解決Mysql:ERROR 1045 (28000):Access denied for user ‘root‘@‘localhost‘ (using password: NO)的方法MySqlErrorlocalhost
- MySQL 8.0.13 密碼問題 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)MySql密碼Errorlocalhost
- ERROR 1045 (28000): using password: YESError
- User Get 'Access Denied' with Excel Service WebPartExcelWeb
- Access denied for user 'default'@'%' to database 'shop'報錯Database
- ubuntu mysql Access denied for user root@localhostUbuntuMySqllocalhost
- 解決mysql“Access denied for user 'root'@'localhost'”MySqllocalhost
- ERROR 1045 (28000): Access denied for userError
- Access denied for user ‘root‘@‘localhost‘問題的解決localhost
- Hive JDBC:Permission denied: user=anonymous, access=EXECUTE, inode=”/tmp”HiveJDBC
- ERROR 1045 (28000): Access denied for user 'root'@'localhost'Errorlocalhost
- Error 1045(28000) Access Denied for user 'root'@'localhost'Errorlocalhost
- Mysql 5.7 CentOS Access denied for user 'root'@'localhost'解決方式MySqlCentOSlocalhost
- Mysql:ERROR 1045 (28000): Access denied for user 'root'@'localhost'MySqlErrorlocalhost
- 解決mysql"Access denied fot user 'root'@'localhost'"問題MySqllocalhost
- Permission denied:user=xxx,access=WRITE,inode=xxx
- mysql ERROR 1045 (28000): Access denied for user解決方法MySqlError
- ERROR 1044 (42000): Access denied for user 'root'@'%' to databaseErrorDatabase
- Httplistener Access DeniedHTTP