Category Archives: MySQL

[SQL ERROR] SQL Error: could not execute statement & query did not return a unique result: 2; nested excepti

Error message:

Operation failed, could not execute statement; SQL [n/a]; nested exception is org.hibernate.exception.DataExcepti

The reason is the limitation of database field length!!

It is also possible that this table field does not exist. It mainly depends on SQL   There are entity class mappings and table structures

Operation failed, query did not return a unique result: 2; nested exception is javax.

This is the interface originally returned an object, but two pieces of data were queried in the database

[Solved] C# connecting to MySQL database reports an error

C# is fine when calling mysql.data.dll to connect to the local database, but it reports an error when connecting to the mysql server on a remote Linux server
Error log, current connection string
System.Security.Authentication.AuthenticationException: Authentication to host ‘xxx.xxx.xxx.xx’ failed.
at MySql.Data.Common.Ssl.StartSSL(Stream& baseStream, Encoding encoding, String connectionString)
at MySql.Data.MySqlClient.NativeDriver.Open()
at MySql.Data.MySqlClient.Driver.Open()
at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)
at MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection()
at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()
at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()
at MySql.Data.MySqlClient.MySqlPool.GetConnection()
at MySql.Data.MySqlClient.MySqlConnection.Open()

<add key="dbString" value="server=localhost;port=3306;user=root;password=root; database=id3net" />

If the host does not support SSL connection, then SSL connection will not be used

Solution: add sslmode = none after the connection string.

<add key="dbString" value="server=localhost;port=3306;user=root;password=root; database=id3net;SslMode=none" />

[ERROR] [FATAL] InnoDB: Table flags are 0 in the data dictionary but the flags in file ./ibdata

Docker failed to start the container after installing mysql. Check the MySQL container log and find:

[ERROR] [FATAL] InnoDB: Table flags are 0 in the data dictionary but the flags in file ./ibdata1 are 0x4800!

Query all containers

docker ps -a

Delete container

docker rm CONTAINER ID;  #CONTAINER ID is the actual container number

If so, be sure to delete the external mount directory.

Restart mysql. I installed version 5.7 of MySQL

docker run -p 3306:3306 --name mysql \
-v /mydata/mysql/log:/var/log/mysql \
-v /mydata/mysql/data:/var/lib/mysql \
-v /mydata/mysql/conf:/etc/mysql \
-e MYSQL_ROOT_PASSWORD=root \
-d mysql:5.7

Enter the container external mount profile

vim /mydata/mysql/conf/my.conf

Insert the following. Copy the following contents. After entering the file through the previous operation, press keyboard I to enter the insertion state, shift + insert to paste the contents, ESC to exit the insertion mode,: WQ save and exit

[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
skip-name-resolve

Restart MySQL

docker restart mysql

Dbeaver connects hive to solve the problem that hive custom UDF functions cannot be used in SQL queries in dbeaver

1. Emergence of problems

Today, connect hive with dbeaver and test several SQL executed on the hive client yesterday. There are custom UDF, udtf, udaf, etc. in the SQL, but when the execute button is pressed in dbeaver, an error is reported, saying that it is an invalid function. But it has been registered as a permanent function in hive and has been run. How can it be invalid in dbeaver?

2. Settle

1.Put the create permanent function statement executed at the hive command line into Dbeaver and execute it again

(1) The statement to create a permanent function is as follows:

create function testudf as 'test.CustomUDF' using jar 'hdfs://cls:8020/user/hive/warehouse/testudf/TESTUDF.jar';

3.Cause (not carefully verified)

1. Because my hive client uses hive commands to connect and register functions, and because Dbeaver connects to hive with hiveserver2 service, which is beeline connection. It is said that hive client registration hiveserver2 cannot be used.
2. In the actual operation process, when I execute the instruction to register the permanent function in Dbeaver, the execution result reports that the function already exists, and it will be fine when I execute the sql statement again. So I think it’s possible that the function information was refreshed, because the function was reported to be invalid at the beginning of the execution, indicating that the sql was also executed.

[Solved] Access denied for user ‘root‘@‘localhost‘ (using password: YES)

1. Find the my.ini file in the MySQL installation directory, and add a line of skip grant tables.

2. Press win, then enter CMD, and right-click to run in administrator mode.

3. Enter the command: net stop Mysql to stop the service first. Next, enter net start Mysql to start the service.

4. After MySQL – uroot – P, enter directly, and then enter.

5. Use MySQL select the MySQL library and execute it. Update user set password = password (“123456”) where user = ‘root’;

6. After the above operations are successful, find the my.ini file in the MySQL installation directory, and then delete skip grant tables.

7. After the above operations are completed, enter the command: net stop Mysql to stop the service first. Next, enter net start Mysql to start the service.

[Solved] mysqli::__construct(): Server sent charset (255) unknown to the client. Please, report to the developers in

This problem is caused by too low PHP version + too high MYSQL version

MYSQL8.0+ version introduces a new character set utf8mb4 

Change the old utf8 alias to utf8mb3

The old PHP’s MYSQLND module does not include the new character set

 

So there will be

The solution is simple, just upgrade to a new PHP version

Official https://bugs.php.net/bug.php?id=74461

Written

 

[2018-05-02 12:13 UTC] [email protected]

[2018-05-02 17:37 UTC] macleo at outlook dot com

So the 7.0+ version is basically OK

 

 

 

[Solved] ERROR 2002 (HY000): Can’t connect to local MySQL server through socket’/var/lib/mysql/mysql.sock’ (2)

Sometimes, when we use “mysql”, “mysqladmin”, “mysqldump” and other commands to manage the database, the server throws an error similar to the following:

1. Error on-site restoration:
Below we connect in three ways, and then observe the prompt error message:

  • 1. Use the “mysql” command directly without the host name parameter;
  • 2. Use the “mysql -h localhost” command with the host name “localhost” parameter;
  • 3. Use the “mysql -h 127.0.0.1” command with the host name “127.0.0.1” parameter.

1. [root@lam7 opt]# mysql
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket’/

var/lib/mysql/mysql.sock ‘ (2) 2. [root@lam7 opt]# mysql -h localhost
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket’/var/lib/mysql/mysql.sock’ (2)

[root@lam7 opt]# mysql -h 127.0.0.1 (This method can be used to enter MariaDB, you can ignore this problem after entering)
Welcome to the MariaDB monitor. Commands end with; or \g.
Your MariaDB connection id is 244
Server version: 10.1.19-MariaDB Source distribution

Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.

Type’help;’ or’\h’ for help. Type’\c’ to clear the current input statement.

 

3. [root@lam7 opt]# mysql -h 127.0.0.1 (PS: Some users also have this problem)
ERROR 1045 (28000): Access denied for user’root’@’localhost’ (using password: NO)

Through the above experiment, it can be seen that the first two methods can produce errors in the title, and the third method of connection will not produce errors in the title (the third method here produces an error of denying access due to password problems. information)

2. Analysis of the cause of the error:
   This is because the host name parameter we use to connect to the database is “localhost”, or the host name parameter is not used, and the server uses “localhost” as the host name by default. When the hostname parameter is “localhost” to connect to the mysql server, the mysql client will think it is connecting to the machine, so it will try to connect in socket file mode (socket file connection method is more efficient than “ip: port” method) At this time, according to the path of the configuration file “/etc/mysql.cnf”, if the corresponding socket file is not found, this error will be triggered.

3. Preparation before repairing the fault:
1. Check whether the mysql service is running:
  Since the “socket” file is created when the mysql service is running, if it prompts “ERROR 2002 (HY000): Can’t connect to local MySQL server through socket'” ***’ (2)”, the “socket” file cannot be found. The first thing we need to confirm is whether the mysql service is running.

#1: Is the port open?

[root@lam7 opt]# lsof -i:3306
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld 57436 mysql 17u IPv6 160456 0t0 TCP *:mysql (LISTEN)

#2: Is the mysqld service running (Xiaoqi uses centos7 here, so it will prompt to use “/bin/systemctl status mysqld.service”)

[root@lam7 opt]# service mysqld status
Redirecting to /bin/systemctl status mysqld.service
mysqld.service
Loaded: not-found (Reason: No such file or directory)
Active: inactive (dead)

#3: If mariaDB, check whether the service is running in the same way:

[root@lam7 opt]# service mariadb status
Redirecting to /bin/systemctl status mariadb.service
mariadb.service-MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled)
Active: inactive ( dead)

#4mysqld service is running (this status is the normal operation of mysql service)

[root@lam7 opt]# service mariadb status
Redirecting to /bin/systemctl status mariadb.service
● mariadb.service-MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled)
Active: active (running) since two 2016-11-22 20:09:01 CST; 10min ago

2. Determine the correct location of the “socket” file: After
  confirming that the mysql service is running normally, the only cause of this error is that the path of the “socket” file is incorrect. We can use the “find” command or the “lsof” command to determine the socket file The correct path:

[root@lam7 opt]# lsof -c mysqld|grep sock$
lsof: WARNING: can’t stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs
Output information may be incomplete.
mysqld 57436 mysql 18u unix 0xffff88000b55f440 0t0 160457 /opt/lampp/var/mysql/mysql.sock

[root@lam7 opt]# find / -name’*.sock’
/storage/db/mysql/mysql.sock

Fourth, the troubleshooting method:
Solution 1:
  Modify the “/etc/my.cnf” configuration file, find “mysql.default_socket” under the “[MySQL]” item in the /etc/php.ini file, and set its value to point to The correct mysql service socket file is enough, add the “[client]” option and the “[mysql]” option in the configuration file, and use the “socket” parameter value under these two options, and the “[mysqld]” option under The “socket” parameter value points to the same socket file path. as follows: 

[mysqld]
datadir=/storage/db/mysql
socket=/storage/db/mysql/mysql.sock
… omit n rows

[client]
default-character-set=utf8
socket=/storage/db/mysql/mysql. sock

[mysql]
default-character-set=utf8
socket=/storage/db/mysql/mysql.sock

After modification, restart the mysqld service to solve this problem.

Solution 2: (Little Seven is a problem solved by this method)
  Use the “ln -s /storage/db/mysql/mysql.sock /var/lib/mysql/mysql.sock” command to set the correct socket file location, This problem can be solved by soft linking to the path location of the socket file indicating the error:

[root@lam7 opt]# ls /var/lib/mysql/mysql.sock
ls: Cannot access /var/lib/mysql/mysql.sock: No such file or directory

[root@lam7 opt]# ln -s /storage/db/mysql/mysql.sock /var/lib/mysql/mysql.sock
[root@lam7 opt]# ls /var/lib/mysql/mysql.sock
/var /lib/mysql/mysql.sock

[Solved] Error while trying to retrieve text for error ORA-01019

This problem involves problems caused by 64-bit oracle services and 32-bit clients.

The environment is as follows: win8.1 + 64-bit oracle 11.1 as the server, the client uses 32-bit programs and does not support 64-bit oracle clients, so the 32-bit 10.2 instantclient package is used.

Problem phenomenon: Cannot connect to oracle server, plsql and sqlplus are connected normally, error while trying to retrieve text for error ORA-01019 is reported when the program is connected.

The description of this error in the Oracle documentation is:

ORA-01019: unable to allocate memory in the user
Cause: The user side memory allocator returned error.

Action: Increase the processes heap size or switch to the old set of calls.

 

Solution:

The reason for this problem seems to be that ODBC does not use the driver provided by Oracle, but uses the driver provided by the system other than ORACLE_HOME. Obviously it is not a memory issue. So solve the first step:

1. Add ORACLE_HOME to the environment variable to point to the 64-bit installation directory instead of the instantclient directory. I think this step can let windows use the matching file to drive

   After doing the first step, and then connecting again, the error message becomes an error that memory cannot be allocated. Then the second step

2. Replace 10.2 Instantclinet package with 11.1 matching 32-bit instantclient package

    After changing, the connection is normal.

 

Both tns_admin and path in the environment variables can point to the location path of the 32-bit instantclient package.

MYSQL Slave is not configured or failed to initialize properly. You must at least set –server-id

1.Background of the problem

When creating the MySQL replication link from the node, because the virtual machine is copied from a template, the server ID is the same.

2. Solutions
# edit/etc/my.cnf
vi /etc/my.cnf

# Add the following 2 lines of code
# server-id here, as long as it is not the same, my mysql master node is 1, here I set it to 2
log-bin=mysql-bin
server-id=2

#restart mysql

systemctl restart mysql

[Solved] Anaconda Error: pyqt can’t use QSqlDatabase to connect to MySQL

1. Problem description

Generally speaking, pyqt can connect to MySQL database in the following format:

self.DB = QSqlDatabase.addDatabase('QMYSQL')
self.DB.setDatabaseName("school_club") # Enter the data table you want to access
self.DB.setHostName('localhost')
self.DB.setPort(3306)
self.DB.setUserName('root')
self.DB.setPassword('') # Enter the password for your own database

However, sometimes the connection fails, and debug can’t point out the error clearly. Errors can be found in the following ways.

Method 1: check the driver attached to pyqt

print(QSqlDatabase.drivers())

If ‘qmmysql’ and ‘qmysql3’ are found missing in the driver, it indicates that the error is driver missing. You can use this method to solve the problem. Because under normal conditions, the output should be as follows:

['QSQLITE', 'QMYSQL', 'QMYSQL3', 'QODBC', 'QODBC3', 'QPSQL', 'QPSQL7']

Method 2: print error information

print(self.DB.lastError().text())

This method can also get the specific part of the connection error.

2. How to solve the lack of qmmysql driver?

The author’s pyqt is installed in Anaconda environment, so the folder path to be found by the driver is special.

The general idea is to add two DLL files: qsqlmysql.dll and libmysql.dll in pyqt related folder. At the same time, these two files must be fully matched with the relevant pyqt version.

Step 1: load qsqlmysql.dll

First, open Anaconda prompt, enter the following command line, and adjust the python version to 5.12.1 (only this version comes with qsqlmysql.dll, other versions of this DLL are too difficult to find a matching one)

pip install PyQt5==5.12.1

After this step, qsqlmysql.dll has been successfully installed in the relevant folder.

Step 2: load libmysql.dll

This is relatively easy. First, find the libmysql.dll (this is the default path for MySQL installation, and the user-defined path will be found separately) in the path of C:// program files/MySQL/MySQL server 8.0/bin, and copy it.

Take my computer as an example, paste the file to the following path:

D:\Anaconda\Anaconda\Lib\site-packages\PyQt5\Qt\bin

You can choose the appropriate path according to the relative path of the above path according to the installation location of anaconda.

Restart the programming tool and print again (QSqlDatabase. Drivers()). It is found that ‘qmmysql’ and ‘qmysql3’ have successfully appeared.

[Solved] Critical: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener

Critical: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener

Critical: Error configuring application listener of class org.springframework.web.util.IntrospectorCleanupListener

Critical: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java: 1720 )
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java: 1571 )
    at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java: 506 )
    at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java: 488 )
    at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java: 115 )
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java: 4932 )
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java: 5524 )
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java: 150 )
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java: 1575 )
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java: 1565 )
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

May 10, 2016 9:41:08 am org.apache.catalina.core.StandardContext listenerStart
Critical: Error configuring application listener of class org.springframework.web.util.IntrospectorCleanupListener
java.lang.ClassNotFoundException: org.springframework.web.util.IntrospectorCleanupListener
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java: 1720 )
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java: 1571 )
    at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java: 506 )
    at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java: 488 )
    at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java: 115 )
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java: 4932 )
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java: 5524 )
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java: 150 )
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java: 1575 )
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java: 1565 )
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

 

Solution:

In fact, your jar file is not synchronized to the lib directory of your project (if you are building with Maven), you can try the following method. Right-click the project, click Properties, select Deployment Assembly, and then click the Add button on the right to select Java Build Path After Entries, click the Next button and select your Maven Dependencies to confirm.

 

Cannot resolve classpath entry: e://jar/mysql-connector-java-5.1.17-bin mybatis error in reverse engineering

error: failed: Cannot resolve classpath entry: E:\jar\mysql-connector-java-5.1.17-bin -> [Help 1]

[INFO] Scanning for projects…
[INFO]
[INFO] ————————–< pay-center:demo >—————————
[INFO] Building demo 0.0.1-SNAPSHOT
[INFO] ——————————–[ jar ]———————————
[INFO]
[INFO] — mybatis-generator-maven-plugin:1.3.2:generate (default-cli) @ demo —
[INFO] ————————————————————————
[INFO] BUILD FAILURE
[INFO] ————————————————————————
[INFO] Total time: 1.043 s
[INFO] Finished at: 2021-07-01T10:31:26+08:00
[INFO] ————————————————————————
[ERROR] Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.2:generate (default-cli) on project demo: Execution default-cli of goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.2:generate failed: Cannot resolve classpath entry: E:\jar\mysql-connector-java-5.1.17-bin -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
My generatorConfig.xml file looks like this, showing only the parts.



My generatorConfig.xml file looks like this, showing only the parts.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
        PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
        "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd" >
<generatorConfiguration>


    <!-- Database driver: select the database driver package on your local hard disk-->
    <classPathEntry  location="E:\jar\mysql-connector-java-5.1.17-bin"/>

    <context id="DB2Tables"  targetRuntime="MyBatis3">
        <commentGenerator>
            <property name="suppressDate" value="true"/>
            <!-- Whether to remove automatically generated comments true: yes : false:no -->
            <property name="suppressAllComments" value="true"/>
        </commentGenerator>



This database driver cannot be found problem occurs, go directly to the database driver to delete. The following figure shows the comparison of the two figures
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
        PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
        "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd" >
<generatorConfiguration>

    

    <context id="DB2Tables"  targetRuntime="MyBatis3">
        <commentGenerator>
            <property name="suppressDate" value="true"/>
            <!-- Whether to remove automatically generated comments true: yes : false:no -->
            <property name="suppressAllComments" value="true"/>
        </commentGenerator>