Tag Archives: SQL

[Solved] 01654 error: the index cannot be extended through 8

The existing solution attempts failed:

1. The table space is insufficient.

2. Rebuild the index or merge the index

Solution 3: delete the index directly without a large amount of data

drop index index-name;

There may be table locking problems:
step one:

 select  session_id from v$locked_object;

Step two:

 select  sid,serial#,username,osuser from v$session where sid = 545;

Step three:

alter system kill session '545,36043';

#The Sid and session here need to be modified according to their own requirements

[Linux Docker Mirror] MYSQL Run sql Script Error: Failed to open file ‘/home/mydatabase.sql‘, error: 2

Failed to open file ‘/ home/mydatabase. SQL’, error: 2 when running SQL script in docker image MySQL in Linux

Today, an error occurred when using docker in centos7 to start MySQL and run SQL script files. The error information is as follows:

mysql> source /home/mydatabase.sql;
ERROR: 
Failed to open file '/home/mydatabase.sql', error: 2

After checking the Internet, the cause of the error should be the problem of path matching. The default path is the installation path of MySQL, so MySQL can only access all directories and files under its source directory. The solution is to directly specify the SQL script file to run when logging in. The specific steps are as follows:
first log in to MySQL and create the database to be used. The name of the database I created is Mydatabase1

root@4994c041aa3a: mysql -uroot -p 
Enter password: 

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.36 MySQL Community Server (GPL)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database mydatabase1;

Exit MySQL and log in again by running SQL script files

# Here mydatabase1 is the database created in the first step, and the file after'<' is the path of the sql script file to be run
root@4994c041aa3a: mysql -uroot -p mydatabase1 < /home/mydatabase.sql

log in again and find that the file has run successfully

root@4994c041aa3a: mysql -uroot -p 
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.36 MySQL Community Server (GPL)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| mydatabase1        |
| sys                |
+--------------------+
5 rows in set (0.00 sec)

mysql> use mydatabase1;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed

mysql> show tables;
+-----------------------------+
|    Tables_in_mydatabase1    |
+-----------------------------+
| t_disk                      |
| t_crl                       |
| t_menu                      |
| t_user                      |
+-----------------------------+
4 rows in set (0.00 sec)

Supplement:

# Docker start MySQL command under CentOS7
docker pull mysql:5.7
docker run -tid --name mysql -e MYSQL_ROOT_PASSWORD=root -p 3306:3306 mysql:5.7
docker exec -it mysql /bin/bash
mysql -uroot -p
Enter password:

Exception occurred when Django created app: from exc ^ syntaxerror: invalid syntax

Execute command Python   manage.py   startapp   Myjango

  App reports an error: file “manage. Py”, line 16) from exc ^ syntax error: invalid syntax

reason:

Python 3 is installed, but Python is used for execution

solve:

Change Python to python3 and execute the above command

python3 manage.py   startapp   myjango

[Solved] java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corres

0. Foreword: this error is an error reported by using mybatis in the spring boot project to query a piece of data in the database according to the ID value

1. Error message

2021-11-14 15:37:38.168 ERROR 9936 --- [nio-8086-exec-7] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException: 
### Error querying database.  Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
### The error may exist in file [E:\smallTools\idea\code\spring\springboot-new-2021_11_09\springboot-new-mybatis\target\classes\mybatis\mapper\BookMapper.xml]
### The error may involve com.feng.mybatis.mapper.BookMapper.getBookById-Inline
### The error occurred while setting parameters
### SQL: select * from book where id={#id}
### Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1] with root cause

java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120) ~[mysql-connector-java-8.0.27.jar:8.0.27]

2. Mapper.xml file content

<select id="getBookById" parameterType="com.feng.mybatis.bean.Book">
        select * from book where id={#id}
</select>

3. Error reason: the SQL statement is written incorrectly. It should be where id = #{id}

<select id="getBookById" parameterType="com.feng.mybatis.bean.Book">
        select * from book where id=#{id}
</select>

java.sql.SQLRecoverableException: IO Error: Connection reset

I wrote an executable jar package to execute on Linux, connected to Oracle 11g database and obtained database data. It was always the card owner. When it timed out, it ran out with an error message. The server could be restarted several times, and it was stuck later.

Execute jar package statement

/root/jdk1.8.0_ 181/bin/java -jar GetJdbc-1.0-SNAPSHOT.jar

java.sql.SQLRecoverableException: IO Error: Connection reset
        at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:421)
        at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:531)
        at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:221)
        at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
        at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:503)
        at java.sql.DriverManager.getConnection(DriverManager.java:664)
        at java.sql.DriverManager.getConnection(DriverManager.java:247)
        at com.iwhalecloud.jdbc.utils.GetDataSource.getConnection(GetDataSource.java:27)
        at com.iwhalecloud.jdbc.execute.DistinguishDataSource.oracleQuery(DistinguishDataSource.java:78)
        at com.iwhalecloud.jdbc.execute.DistinguishDataSource.dataHandle(DistinguishDataSource.java:34)
        at com.iwhalecloud.jdbc.main.MainProgram.main(MainProgram.java:26)
Caused by: java.net.SocketException: Connection reset
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:115)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:155)
        at oracle.net.ns.DataPacket.send(DataPacket.java:199)
        at oracle.net.ns.NetOutputStream.flush(NetOutputStream.java:211)
        at oracle.net.ns.NetInputStream.getNextPacket(NetInputStream.java:227)
        at oracle.net.ns.NetInputStream.read(NetInputStream.java:175)
        at oracle.net.ns.NetInputStream.read(NetInputStream.java:100)
        at oracle.net.ns.NetInputStream.read(NetInputStream.java:85)
        at oracle.jdbc.driver.T4CSocketInputStreamWrapper.readNextPacket(T4CSocketInputStreamWrapper.java:122)
        at oracle.jdbc.driver.T4CSocketInputStreamWrapper.read(T4CSocketInputStreamWrapper.java:78)
        at oracle.jdbc.driver.T4CMAREngine.unmarshalUB1(T4CMAREngine.java:1179)
        at oracle.jdbc.driver.T4CMAREngine.unmarshalSB1(T4CMAREngine.java:1155)
        at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:279)
        at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:186)
        at oracle.jdbc.driver.T4CTTIoauthenticate.doOAUTH(T4CTTIoauthenticate.java:366)
        at oracle.jdbc.driver.T4CTTIoauthenticate.doOAUTH(T4CTTIoauthenticate.java:752)
        at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:359)
        ... 10 more
close
Exception in thread "main" java.lang.NullPointerException
        at com.iwhalecloud.jdbc.execute.DistinguishDataSource.oracleQuery(DistinguishDataSource.java:80)
        at com.iwhalecloud.jdbc.execute.DistinguishDataSource.dataHandle(DistinguishDataSource.java:34)
        at com.iwhalecloud.jdbc.main.MainProgram.main(MainProgram.java:26)

Find an effective solution on the Internet and add a parameter – DJava. Security. EGD = file:/dev /../dev/urandom

The execution statement is as follows

/root/jdk1.8.0_ 181/bin/java -jar -Djava.security.egd=file:/dev/../dev/urandom GetJdbc-1.0-SNAPSHOT.jar

[Solved] SQL Error: Method queryTotal execution error of sql

In a connection query, there is no problem with the query in the MySQL query tool. It is pasted into the mapper.xml file in the project, but the runtime reports mybatisplusexception: error: method querytotal execution error of SQL:

 SELECT
        ANY_VALUE(e.id)  AS "id",
        ANY_VALUE(e.project_no) AS "projectNo",
        ANY_VALUE(sampleIn.sample_id)  AS "fieldNumber",
        ANY_VALUE(e.subject_no) AS "laboratoryNumber",
        ANY_VALUE(e.type) AS "type",
        ANY_VALUE(d.sampling_location) AS "location",
        ANY_VALUE(sampleIn.in_quantity)   AS "inquatity",
        ANY_VALUE(sampleIn.create_date)  AS "createDate",
        ANY_VALUE(sys_user.name)  AS "createUser",          
        ANY_VALUE(s. project_no)  AS "projectNoName",
        ANY_VALUE(s.subject_name)   AS "subjectName",
        ANY_VALUE(sd.name) AS "saveCondition",
        ANY_VALUE(sa.location) AS "location",
        ANY_VALUE(DATE_FORMAT(sa.shelf_life,'%Y-%m-%d'))AS"shelfLife"
        FROM labcode e
        LEFT JOIN labprojects s ON e.project_no = s.id
        LEFT JOIN labprojectplan n ON s.id = n.project_no        
        LEFT JOIN labprojectplan_field d ON n.id = d. lab_project_plan_id  AND e.serial_number = d.serial_number AND e.letter_code =d.letter_code    
        LEFT JOIN labsubjectsample sa ON e.id =sa.laboratory_number
        LEFT JOIN laboratorysamplein sampleIn ON sampleIn.code_id = e.id
        LEFT JOIN sys_user ON sampleIn.create_user=sys_user.user_id
        LEFT JOIN sys_dict sd ON sd.code = sa.save_condition
        WHERE 1 = 1
        AND s.is_delete = 0
        AND e.is_delete=0
        AND e.subject_no LIKE '%B'
        AND e.type=3
       
        GROUP BY e.id     
        ORDER BY ANY_VALUE(sampleIn.create_date) DESC

After going online to search, it was confirmed that it was the problem of where conditions, so they were eliminated one by one, and finally locked on several is_delete fields, which are of char type in the database. The database query tool supports direct use of 0 and 1 to query, and MyBatis needs to contact the database Keep consistent in the middle, and finally, change the where part to

WHERE 1 = 1
        AND s.is_delete = '0'
        AND e.is_delete='0'
        AND e.subject_no LIKE '%B'
        AND e.type='3'

Problem-solving

This exception is basically the problem of where conditions, and type mismatch is only one of them. Other problems include condition null value, keyword conflict with framework and so on. As long as you are careful when writing code, think more about avoiding exceptions, be patient when problems occur, check them one by one, and be good at summarizing after problems are solved, you can accumulate experience and grow gradually on the way of writing code.

Invalid column reference when using round in hive



Group by must be added to the hive query SQL, otherwise the column col in the selection list is invalid because it is not included in the aggregate function or group by clause.

Generally speaking, count , round should be regarded as aggregate functions without group by
however, hive does not consider the use of round as an aggregate function. The fields used should be added to group by, and the fields used in round should be added to group by
otherwise, an error is reported invalid column reference

An error occurs when pymysql uses% d to pass in parameters

Error:

When using pymysql, an error occurs when using% d to pass parameters in the SQL statement. As shown in the figure:

Error information: typeerror:% d format: a number is required, not str

Cause of problem:

         When a parameter of type int is passed in, it is converted to a parameter of type str. Therefore, the solution is to change% d into% s, pass in int type, and it can still be executed.

Modified:

Data of type int passed in:

Can execute successfully

Solution:

          When data of type int is passed in, the parameter is still passed with% s.

How to Solve DB2 uses Limit Error

preface

Prepare DB2 to use a simple limit query, and the result reports an error
Baidu has a wave. The previous articles are of no use at all, but they still report errors
later, we finally found a correct one and recorded a wave.

Text

SQL sample for DB2:

select * from sname.usertable fetch first 10 rows only

DB2 uses fetch first 10 rows only to return the first 10 rows of data
MySQL uses limit 10 to return the first 10 rows of data
Oracle uses rownum & lt= 10 returns the first 10 rows of data.

MYSQL Use cmd to change root password error: ERROR 1064 (42000): You have an error in your SQL syntax; check the manual tha

MYSQL Use cmd to change root password error:ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘(“123456”) where user = “root”‘ at line 1

Prompt for SQL syntax error
Change the password with another command

ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';

Modified successfully