Tag Archives: database

[Solved] Windows Redis Error: Could not create server TCP listening socket 127.0.0.1:6379: bind…

An error occurred when redis was started under Windows Environment: could not create server TCP listening socket 127.0.0.1:6379: bind: the operation completed successfully.

Problem Description:
When redis is started in the windows environment today, an error is reported:

Solution:
① run command: redis-cli.exe

② Exit Redis

③ Run the command: redis-server.exe redis.windows.conf

Start successfully!

[Solved] MYSQL Connect Error: Communications link failure

 

org.apache.ibatis.exceptions.PersistenceException: 
### Error updating database.  Cause: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
### The error may exist in mappers/UserMapper.xml
### The error may involve com.chunqiu.mybatis.mapper.UserMapper.insertUser
### The error occurred while executing an update
### Cause: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

When we report the first few lines of error information as shown in the figure above, we can try to exclude common errors on the Internet as below:
1. MySQL data service is not enabled
2. serverTimezone parameter
3. wait_timeout settings

If the error is still reported, check whether there is this line after the error message
Caused by: javax.net.ssl.SSLHandshakeException

Caused by: javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
	at sun.security.ssl.HandshakeContext.<init>(HandshakeContext.java:171)
	at sun.security.ssl.ClientHandshakeContext.<init>(ClientHandshakeContext.java:106)
	at sun.security.ssl.TransportContext.kickstart(TransportContext.java:238)
	at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:410)
	at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:389)
	at com.mysql.cj.protocol.ExportControlled.performTlsHandshake(ExportControlled.java:316)
	at com.mysql.cj.protocol.StandardSocketFactory.performTlsHandshake(StandardSocketFactory.java:188)
	at com.mysql.cj.protocol.a.NativeSocketConnection.performTlsHandshake(NativeSocketConnection.java:99)
	at com.mysql.cj.protocol.a.NativeProtocol.negotiateSSLConnection(NativeProtocol.java:352)
	... 55 more

Solution:
add the parameter usessl = false to the URL

jdbc:mysql://xxx.xxx.xxx.xxx/db?useSSL=false

Cause:
Communications link failure
Caused by: javax.net.ssl
Before MySQL 5.7, the security was low and there were test libraries that any user could connect to, so the official version 5.7 increased the privacy protection. The default value of useSSL = true was used to prevent arbitrary changes to the database. In version 8.0, SSL is still retained and the default value is true, so just set “?useSSL= false” and you’re done!

[Solved] redis-server.exe Flashback Error: QForkMasterInit: system error caught. error code=0x000005af, message=Virtual

If you don’t change any configuration one day and somehow open the redis server to flash back, you can enter the redis-server directory in the command line and enter redis-server.exe redis.windows.conf command to view the error information

If an error is reported as follows

QForkMasterInit: system error caught. error code=0x000005af, message=VirtualAllocEx failed

It means that you have not set the maximum memory of redis

Open redis.windows.conf with Notepad

Add the code below to the last line.

maxmemory 268435456
maxheap 314572800

[Solved] Worker 1 failed executing transaction ‘ANONYMOUS‘ at master log mall-mysql-bin.000001, end_log_pos

A problem encountered while configuring MySQL master-slave server in Docker.

The following error:

Coordinator stopped because there were error(s) in the worker(s). The most recent failure being: Worker 1 failed executing transaction ‘ANONYMOUS’ at master log mall-mysql-bin.000001, end_log_pos 2251. See error log and/or performance_schema.replication_applier_status_by_worker table for more details about this failure or others, if any.

Based on the hints given in the error message, execute in the mysql client to view the detailed error message.

select * from performance_schema.replication_applier_status_by_worker;

Worker 1 failed executing transaction ‘ANONYMOUS’ at master log
mall-mysql-bin.000001, end_log_pos 889; Error ‘Can’t create database
‘t1’; database exists’ on query. Default database: ‘t1’. Query:
‘create database t1’


Reasons:
1. The password policy problem of MySQL8, change the configuration file and use the policy of the previous version.
Execute these two commands in MySQL host client.

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
ALTER USER 'slave'@'%' IDENTIFIED WITH mysql_native_password BY 'root';

Add a line to my.cnf that aligns MySQL8 with MySQL5.7 password authentication.

default_authentication_plugin=mysql_native_password

After the master and slave have changed this configuration, restart the master and slave.
(Each line of configuration in my.cnf file must remember to check if there are spaces at the end of the line. If there are spaces, delete them.)

docker restart mysql-master(Your own mysql host container name)

docker ps

docker restart mysql-slave(Your own mysql slave container name)

docker ps

2. My understanding is that the table already exists does not mean that your slave already exists. It means that the table already exists on the host before you configure the slave, so this problem will be reported.

Execute the following command on the slave MySQL client.

stop slave;

reset master;

Go to MySQL master and delete the database added by your own test.

drop database Add the database for your own testing;

show master status;

According to the values of File and Position of mysql-master, change the master_log_file and master_log_pos of the following command.

change master to master_host=‘192.168.159.200’, master_user=‘slave’,
master_password=‘root’, master_port=3307,
master_log_file=‘mall-mysql-bin.000002’, master_log_pos=331,
master_connect_retry=30;

After the change, execute this command on mysql-slave;

start slave;

show slave status\G

If you find that both Slave_IO_Running and Slave_SQL_Running show Yes, the MySQL master-slave configuration is successful.

As long as one of them is not Yes, it is something like Connecting or No, it means that the configuration is not successful.

After configuring the master-slave, create a new database and table on mysql-master, insert the data, and then go to the slave to verify that the data is synchronized over.

mysql-master


mysql-slave

So far, the installation of MySQL master-slave in docker is completed.

[Solved] pymysql.err.OperationalError: (1045, “Access denied for user ‘root‘@‘192.168.118.44‘

Error: pymysql.err OperationalError: (1045, “Access denied for user ‘root’@‘192.168.118.44’ (using password: YES)”)

Possible problems:
1. Firewall blocking,
Solution: log in to the server and turn off the firewall

systemctl stop firewalld.service

2. User empowerment (the root user I use here)
Solution: log in to the MySQL database for empowerment

grant all privileges on *.* to 'root'@'%' identified by 'password';
flush privileges;

3. Check whether the password is entered incorrectly

[Solved] Redis error: NOAUTH Authentication required.

1. Development environment

redis

2. Redis reports an error: NOAUTH Authentication required.

1. Set your password and open redis.window.conf file, search requirepass to view your password

2. For those without a password, there is a situation that can cause this error. Redis is running in the background. End redis in the background of the task manager and restart it

Hive: How to Solve dearby database initialization error

Error Messages:

Metastore connection URL:     jdbc:derby:;databaseName=metastore_db;create=true
Metastore Connection Driver :     org.apache.derby.jdbc.EmbeddedDriver
Metastore connection User:     APP
Starting metastore schema initialization to 3.1.0
Initialization script hive-schema-3.1.0.derby.sql
 
Error: FUNCTION 'NUCLEUS_ASCII' already exists. (state=X0Y68,code=30000)
org.apache.hadoop.hive.metastore.HiveMetaException: Schema initialization FAILED! Metastore state would be inconsistent !!
Underlying cause: java.io.IOException : Schema script failed, errorcode 2
Use --verbose for detailed stacktrace.
*** schemaTool failed ***

 

Solution:

Go to share/common/lib/guava-27.0-jre.jar in hadoop
and Replace the lib/guava-27.0-jre.jar file in hive.

[Solved] dynamic-datasource can not find primary datasource

Error reporting details

When using mybatis plus multiple data sources, the startup message cannot find the master data source

com.baomidou.dynamic.datasource.exception.CannotFindDataSourceException: dynamic-datasource can not find primary datasource
	at com.baomidou.dynamic.datasource.DynamicRoutingDataSource.determinePrimaryDataSource(DynamicRoutingDataSource.java:91) ~[dynamic-datasource-spring-boot-starter-3.5.1.jar:3.5.1]
	at com.baomidou.dynamic.datasource.DynamicRoutingDataSource.getDataSource(DynamicRoutingDataSource.java:120) ~[dynamic-datasource-spring-boot-starter-3.5.1.jar:3.5.1]
	at com.baomidou.dynamic.datasource.DynamicRoutingDataSource.determineDataSource(DynamicRoutingDataSource.java:78) ~[dynamic-datasource-spring-boot-starter-3.5.1.jar:3.5.1]
	at com.baomidou.dynamic.datasource.ds.AbstractRoutingDataSource.getConnection(AbstractRoutingDataSource.java:48) ~[dynamic-datasource-spring-boot-starter-3.5.1.jar:3.5.1]
......

Solution:

① The dependency of multiple data sources is introduced, but multiple data sources are not used

<!--This is the dependent version I use-->
<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>dynamic-datasource-spring-boot-starter</artifactId>
    <version>3.5.1</version>
</dependency>

<!--document-->
<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>dynamic-datasource-spring-boot-starter</artifactId>
    <version>${version}</version>
</dependency>

Multi data source usage: use @ds to switch data sources.

@DS can be annotated on methods or classes, and there is a proximity principle that annotations on methods take precedence over annotations on classes.

annotation result
no @DS Default data source
@DS(“databaseName”) databaseName can be a group name or the name of a specific library

② Multiple data sources are used but the main data source is not specified

spring:
  datasource:
    dynamic:
      primary: master # Set the default data source or data source group, the default value is master
      strict: false #Strictly match the datasource, default false. true does not match the specified datasource throw an exception, false uses the default datasource
      datasource:
        master:
          url: jdbc:mysql://xx.xx.xx.xx:3306/dynamic
          username: root
          password: 123456
          driver-class-name: com.mysql.jdbc.Driver # This configuration can be omitted for SPI support since 3.2.0
        slave_1:
          url: jdbc:mysql://xx.xx.xx.xx:3307/dynamic
          username: root
          password: 123456
          driver-class-name: com.mysql.jdbc.
        slave_2:
          url: ENC(xxxxxx) # Built-in encryption, please check the detailed documentation for use
          username: ENC(xxxxxxxxxx)
          password: ENC(xxxxxxxxxx)
          driver-class-name: com.mysql.jdbc.
       #...... omit
       #The above will configure a default library master, a group slave with two sub-banks slave_1,slave_2

③ Check carefully if there is any alignment in the configuration

# Correct format
spring:
  datasource:
    dynamic:
      strict: false
      primary: one
      datasource:
        one:
          driver-class-name: com.mysql.cj.jdbc.Driver
          url: jdbc:mysql://localhost:3306/demo?allowMultiQueries=true&zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&useSSL=false
          username: root
          password: 123456
        two:
          driver-class-name: com.mysql.cj.jdbc.Driver
          url: jdbc:mysql://localhost:3306/demo1?allowMultiQueries=true&zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&useSSL=false
          username: root
          password: 123456

 

[Solved] Flyway Error: Detected applied migration not resolved locally:2 and the execution script error

I preface

Flyway is used in actual development. Let’s briefly introduce flyway

1. Flyway introduction

Flyway is an open source database version management tool. It can be easily used in the command line or introduced in Java applications to manage our database version.

In a project or product, it is difficult to clarify the business at the beginning and design the database table well, so the data table will also iterate continuously in the iteration cycle. Using flyway in Java applications can be used to iterate the database table structure quickly and effectively, and ensure that the data tables are consistent when deployed to the test environment or production environment.

Please refer to flyway’s official documents for details

https://flywaydb.org/documentation/

2. Flyway dependency package

<dependency>
    <groupId>org.flywaydb</groupId>
    <artifactId>flyway-core</artifactId>
    <version>7.9.2</version>
</dependency>

3. Benefits of using flyway

In multi person development projects, we are used to using SVN or git to version control the code. The main purpose is to solve the problems of code conflict and version fallback in multi person development.

II Problem analysis

1. Flyway reports an error: detected applied migration not resolved locally:2

When using flyway for system management, my program reported such errors

1.1 problem analysis:

Reported error: Application migration not detected locally resolved

The reason for this problem is:

1. because the imported database contains flyway_schema_history table, so the local runtime version inconsistent error,

2. I migrated a version 2 sql, then I deleted it, and when I ran it again for the second time, I couldn’t find the V2__orange_cms file that I migrated before.

1.2 Solution
Special Note: Must be in test environment and local environment

1. mvn flyway:clean, this step will clear the existing data.

2. Ensure that the configuration file is open for flyway.

3. Start the project, complete the initialization of the flyway_schema_history table, backup the flyway_schema_history table after the startup is complete

4. Import the data, at this time the flyway_schema_history table will be updated to the version of the imported data

5. After the successful import, delete the flyway_schema_history table and replace it with the backup flyway_schema_history table

6. Start the application again, Success!

 

2. Script execution error

2.1 problem analysis

The general meaning of the error message: when flyway is opened in my project configuration file, it will explode: the execution of SQL is abnormal, and the “XXX” table cannot be found

This is a problem that has bothered me for a long time. I don’t know where my program and configuration are wrong

Error reason: because our flyway is based on the version of database mysql5.7, but my local database version is mysql5.5, the error “cannot find XXX table” is always reported when starting flyway configuration for database initialization

2.2 problem solving

Upgrade our database version, which is greater than or equal to our development database version. Due to the twists and turns in the road of upgrading the database, we suggest that you learn from it: more detailed

https://blog.csdn.net/m0_49284219/article/details/121972531

Open our flyway configuration after the database upgrade

Start the program to see if our project can start successfully

 

H2 memory database Oracle mode page error: rg.springframework.dao.InvalidDataAccessResourceUsageException: could not prepar

I. Cause analysis:

1:When we use hibernate’s NativeQuery for paging, the underlying will use limit or rownum, and which paging method is determined by the dialect of different databases, the following will explain the h2 oracle pattern using NativeQuery for paging when the problem is solved org. InvalidDataAccessResourceUsageException: could not prepare statement; SQL [SELECT * limit ?] SQLGrammarException: could not prepare statement
We will find that h2’s oracle schema uses the limit method for paging, but using limit for paging will report an error
2:h2 paging method
Open h2’s dialect class H2Dialect, we can find that h2’s paging method is using limit

3: Oracle paging mode
open the dialect class of Oracle according to different Oracle versions

we will find that the bottom layer of Oracle is rownum for paging

II. Problem-solving
1: since we only solve the paging problem now, here we create a custom dialect class TestH2Dialect, Inherited from H2Dialect

2: because our custom dialect class inherits from H2Dialect, we don’t need to pay attention to other dialect problems. We just need to rewrite the paging method to solve the above problems. Here we have taken oracle12 as an example
Create TestH2Dialect to customize dialect

public class TestH2Dialect extends H2Dialect {

    private static final TestOracle12LimitHandler LIMIT_HANDLER = new TestOracle12LimitHandler() ;

    @Override
    public LimitHandler getLimitHandler() {
        return LIMIT_HANDLER;
    }

}

Create Oracle paging processing class

public class TestOracle12LimitHandler extends AbstractLimitHandler {
    public boolean bindLimitParametersInReverseOrder;
    public boolean useMaxForLimit;
    public static final TestOracle12LimitHandler INSTANCE = new TestOracle12LimitHandler();

    TestOracle12LimitHandler() {
    }

    @Override
    public String processSql(String sql, RowSelection selection) {
        boolean hasFirstRow = LimitHelper.hasFirstRow(selection);
        boolean hasMaxRows = LimitHelper.hasMaxRows(selection);
        return !hasMaxRows ?sql : this.processSql(sql, this.getForUpdateIndex(sql), hasFirstRow);
    }
    @Override
    public String processSql(String sql, QueryParameters queryParameters) {
        RowSelection selection = queryParameters.getRowSelection();
        boolean hasFirstRow = LimitHelper.hasFirstRow(selection);
        boolean hasMaxRows = LimitHelper.hasMaxRows(selection);
        if (!hasMaxRows) {
            return sql;
        } else {
            sql = sql.trim();
            LockOptions lockOptions = queryParameters.getLockOptions();
            if (lockOptions != null) {
                LockMode lockMode = lockOptions.getLockMode();
                switch(lockMode) {
                    case UPGRADE:
                    case PESSIMISTIC_READ:
                    case PESSIMISTIC_WRITE:
                    case UPGRADE_NOWAIT:
                    case FORCE:
                    case PESSIMISTIC_FORCE_INCREMENT:
                    case UPGRADE_SKIPLOCKED:
                        return this.processSql(sql, selection);
                    default:
                        return this.processSqlOffsetFetch(sql, hasFirstRow);
                }
            } else {
                return this.processSqlOffsetFetch(sql, hasFirstRow);
            }
        }
    }

    private String processSqlOffsetFetch(String sql, boolean hasFirstRow) {
        int forUpdateLastIndex = this.getForUpdateIndex(sql);
        if (forUpdateLastIndex > -1) {
            return this.processSql(sql, forUpdateLastIndex, hasFirstRow);
        } else {
            this.bindLimitParametersInReverseOrder = false;
            this.useMaxForLimit = false;
            String offsetFetchString;
            if (hasFirstRow) {
                offsetFetchString = " offset ?rows fetch next ?rows only";
            } else {
                offsetFetchString = " fetch first ?rows only";
            }

            int offsetFetchLength = sql.length() + offsetFetchString.length();
            return (new StringBuilder(offsetFetchLength)).append(sql).append(offsetFetchString).toString();
        }
    }

    private String processSql(String sql, int forUpdateIndex, boolean hasFirstRow) {
        this.bindLimitParametersInReverseOrder = true;
        this.useMaxForLimit = true;
        String forUpdateClause = null;
        boolean isForUpdate = false;
        if (forUpdateIndex > -1) {
            forUpdateClause = sql.substring(forUpdateIndex);
            sql = sql.substring(0, forUpdateIndex - 1);
            isForUpdate = true;
        }

        int forUpdateClauseLength;
        if (forUpdateClause == null) {
            forUpdateClauseLength = 0;
        } else {
            forUpdateClauseLength = forUpdateClause.length() + 1;
        }

        StringBuilder pagingSelect;
        if (hasFirstRow) {
            pagingSelect = new StringBuilder(sql.length() + forUpdateClauseLength + 98);
            pagingSelect.append("select * from ( select row_.*, rownum rownum_ from ( ");
            pagingSelect.append(sql);
            pagingSelect.append(" ) row_ where rownum <= ?) where rownum_ > ?");
        } else {
            pagingSelect = new StringBuilder(sql.length() + forUpdateClauseLength + 37);
            pagingSelect.append("select * from ( ");
            pagingSelect.append(sql);
            pagingSelect.append(" ) where rownum <= ?");
        }

        if (isForUpdate) {
            pagingSelect.append(" ");
            pagingSelect.append(forUpdateClause);
        }

        return pagingSelect.toString();
    }

    private int getForUpdateIndex(String sql) {
        int forUpdateLastIndex = sql.toLowerCase(Locale.ROOT).lastIndexOf("for update");
        int lastIndexOfQuote = sql.lastIndexOf("'");
        if (forUpdateLastIndex > -1) {
            if (lastIndexOfQuote == -1) {
                return forUpdateLastIndex;
            } else {
                return lastIndexOfQuote > forUpdateLastIndex ?-1 : forUpdateLastIndex;
            }
        } else {
            return forUpdateLastIndex;
        }
    }
    @Override
    public final boolean supportsLimit() {
        return true;
    }
    @Override
    public boolean bindLimitParametersInReverseOrder() {
        return this.bindLimitParametersInReverseOrder;
    }
    @Override
    public boolean useMaxForLimit() {
        return this.useMaxForLimit;
    }
}

3. Modify the dialect class used in the configuration file

to

III. summary
if you encounter other dialect problems later, you can use the same method to solve them

[Solved] Error 4 opening dom ASM/Self in 0x8283c00

Installing Oracle RAC 19.3.0.0 on RHEL 7.9, in the run root.sh script step of the installation GI, it runs normally on the first node, but Error 4 opening dom ASM/Self in 0x8283c00 occurs when running the root.sh script on the second node

Root.sh script executed successfully in node 1

Problem running root.sh script on node 2

Creating /etc/oratab file...
Entries will be added to the /etc/oratab file as needed by
Database Configuration Assistant when a database is created
Finished running generic part of root script.
Now product-specific root actions will be performed.
Relinking oracle with rac_on option
Using configuration parameter file: /u01/app/19.0.0/grid/crs/install/crsconfig_params
The log of current session can be found at:
  /u01/app/grid/crsdata/momdb2/crsconfig/rootcrs_momdb2_2022-06-19_11-05-10AM.log
2022/06/19 11:05:13 CLSRSC-594: Executing installation step 1 of 19: 'SetupTFA'.
2022/06/19 11:05:14 CLSRSC-594: Executing installation step 2 of 19: 'ValidateEnv'.
2022/06/19 11:05:14 CLSRSC-363: User ignored prerequisites during installation
2022/06/19 11:05:14 CLSRSC-594: Executing installation step 3 of 19: 'CheckFirstNode'.
2022/06/19 11:05:14 CLSRSC-594: Executing installation step 4 of 19: 'GenSiteGUIDs'.
2022/06/19 11:05:14 CLSRSC-594: Executing installation step 5 of 19: 'SetupOSD'.
2022/06/19 11:05:14 CLSRSC-594: Executing installation step 6 of 19: 'CheckCRSConfig'.
2022/06/19 11:05:15 CLSRSC-594: Executing installation step 7 of 19: 'SetupLocalGPNP'.
2022/06/19 11:05:16 CLSRSC-594: Executing installation step 8 of 19: 'CreateRootCert'.
2022/06/19 11:05:16 CLSRSC-594: Executing installation step 9 of 19: 'ConfigOLR'.
2022/06/19 11:05:23 CLSRSC-594: Executing installation step 10 of 19: 'ConfigCHMOS'.
2022/06/19 11:05:23 CLSRSC-594: Executing installation step 11 of 19: 'CreateOHASD'.
2022/06/19 11:05:24 CLSRSC-594: Executing installation step 12 of 19: 'ConfigOHASD'.
2022/06/19 11:05:24 CLSRSC-330: Adding Clusterware entries to file 'oracle-ohasd.service'
2022/06/19 11:05:35 CLSRSC-4002: Successfully installed Oracle Trace File Analyzer (TFA) Collector.
2022/06/19 11:06:01 CLSRSC-594: Executing installation step 13 of 19: 'InstallAFD'.
2022/06/19 11:06:27 CLSRSC-594: Executing installation step 14 of 19: 'InstallACFS'.
2022/06/19 11:07:02 CLSRSC-594: Executing installation step 15 of 19: 'InstallKA'.
2022/06/19 11:07:03 CLSRSC-594: Executing installation step 16 of 19: 'InitConfig'.
2022/06/19 11:07:10 CLSRSC-594: Executing installation step 17 of 19: 'StartCluster'.
2022/06/19 11:11:03 CLSRSC-343: Successfully started Oracle Clusterware stack
2022/06/19 11:11:03 CLSRSC-594: Executing installation step 18 of 19: 'ConfigNode'.
2022/06/19 11:11:11 CLSRSC-594: Executing installation step 19 of 19: 'PostConfig'.
2022/06/19 11:11:26 CLSRSC-325: Configure Oracle Grid Infrastructure for a Cluster ... succeeded
***Error 4 opening dom ASM/Self in 0x8283c00
Domain name to open is ASM/Self 
Error 4 opening dom ASM/Self in 0x8283c00***

According to MOS: 19C: While Executing Root.sh on Remote Nodes HIT UNEXPECTED “ERROR 4 OPENING DOM ASM/SELF IN 0x57f7d60” (Doc ID 2571719.1) description, this issue has no effect on the installation and can be ignored