Error
Error Code:
1065
MariaDB Error 1065: Empty Query Submitted
Description
MariaDB Error 1065, 'Query was empty', indicates that the database server received a request to execute an SQL statement, but the provided statement was blank or contained no executable content. This typically occurs when an application or client sends an empty string, or a script attempts to process a non-existent or improperly formed query.
Error Message
Query was empty
Known Causes
4 known causesEmpty SQL String from Application
An application or client program sent an empty string or null value to the MariaDB server as an SQL query.
Blank SQL File Execution
Attempting to execute an SQL script file that is either completely empty or contains only comments and whitespace.
Incorrect Delimiter Usage
When executing multiple statements in a script, an incorrect or missing DELIMITER command can cause subsequent statements to be parsed as empty.
Malformed Query Construction
Dynamic SQL generation in an application might inadvertently produce an empty string due to incorrect variable substitution or conditional logic.
Solutions
3 solutions available1. Identify and Remove Empty Query in Client Application medium
Locate and correct the source of the empty query within your application code.
1
Review your application's code that interacts with MariaDB. Look for places where a query string might be constructed and end up being empty before being sent to the database. This can happen due to conditional logic, missing parameters, or incorrect string concatenation.
2
Add logging or debugging statements around your database query execution. This will help pinpoint the exact line of code that is generating the empty query.
console.log('Executing query:', query);
// or
print('Executing query: ' + query)
3
Ensure that any variables used to build your SQL queries are properly initialized and contain valid SQL statements before they are executed.
4
Test your application thoroughly after making corrections to ensure the error no longer occurs.
2. Check for Accidental Empty Commands in Scripts easy
Verify that no empty lines or unintended commands are present in your SQL scripts.
1
Open the SQL script file that you are using to interact with MariaDB in a text editor.
2
Carefully examine the script for any blank lines that might be interpreted as an empty query by the MariaDB client or server. Sometimes, a line with only whitespace can also cause this issue.
3
Remove any blank lines or lines that contain only whitespace. Ensure that each line that is intended to be a SQL command is a valid SQL statement.
4
If you are using a tool that executes SQL scripts, check its documentation for how it handles empty lines or commands.
3. Configure MariaDB Client to Ignore Empty Queries (Less Recommended) medium
Adjust client configuration to prevent sending empty queries, though addressing the root cause is preferred.
1
This solution is client-specific. For the `mysql` command-line client, you might not have a direct configuration option to *ignore* empty queries. However, you can sometimes control how commands are processed. If you are using a wrapper or a different client, consult its documentation.
2
For programmatic clients (e.g., Python's `mysql.connector`, PHP's `mysqli`), ensure your code explicitly checks if the query string is empty before attempting to execute it.
if query_string:
cursor.execute(query_string)
else:
print('Skipping empty query.')
3
The primary goal should always be to fix the source of the empty query rather than trying to mask it with client-side configurations, as this can hide underlying application logic issues.