Error
Error Code: 3717

MySQL Error 3717: Invalid SRS Attribute Character

📦 MySQL
📋

Description

This error indicates that a Spatial Reference System (SRS) attribute definition contains one or more characters that are not permitted. It typically occurs when defining or altering an SRS, often due to syntax errors, unsupported characters, or incorrect encoding in the attribute's value.
💬

Error Message

Invalid character in attribute %s.
🔍

Known Causes

3 known causes
⚠️
Malformed Syntax
The SRS attribute value contains characters that do not conform to the expected syntax rules for that specific attribute.
⚠️
Unsupported Character Set
Characters used in the attribute value are not supported by the database's configured character set or the SRS definition's requirements.
⚠️
Non-Printable Characters
The attribute value inadvertently includes hidden or non-printable characters, often from copy-pasting, that MySQL considers invalid.
🛠️

Solutions

3 solutions available

1. Sanitize Input Data easy

Cleanse user-provided or external data before inserting or updating it into the database.

1
Identify the specific column that is causing the error. This will be indicated by the `%s` placeholder in the error message. For example, if the error is 'Invalid character in attribute 'email'', the 'email' column is the culprit.
2
Implement input validation and sanitization in your application code. This involves removing or replacing characters that are not allowed in the target column's data type or expected format. Common problematic characters include control characters, non-ASCII characters (depending on your character set), or characters that might be misinterpreted by the database (e.g., quotes, backslashes).
Example (Python with Flask/SQLAlchemy):

from flask import request
from your_app.models import YourModel
from your_app import db

@app.route('/update_record/<int:record_id>', methods=['POST'])
def update_record(record_id):
    record = YourModel.query.get(record_id)
    if record:
        # Sanitize 'description' field before updating
        new_description = request.form.get('description')
        if new_description:
            # Remove control characters and replace with spaces (or remove entirely)
            sanitized_description = ''.join(c for c in new_description if c.isprintable() or c == '\n' or c == '\r')
            record.description = sanitized_description
        db.session.commit()
        return 'Record updated successfully'
    return 'Record not found', 404
3
If you have direct SQL access and need to clean up existing data, you can use SQL functions to replace problematic characters. This is a one-time fix for existing data.
UPDATE your_table SET your_column = REPLACE(your_column, '\x00', ''); -- Example: Remove null characters
UPDATE your_table SET your_column = REPLACE(your_column, '\x01', ''); -- Example: Remove SOH character
UPDATE your_table SET your_column = REGEXP_REPLACE(your_column, '[^[:print:]]', '', 'g'); -- Example: Remove all non-printable characters (MySQL 8.0+)

2. Verify and Adjust Table Character Set and Collation medium

Ensure your table's character set and collation support the characters you intend to store.

1
Determine the character set and collation of the table and column that is causing the error. You can do this using the `SHOW CREATE TABLE` statement.
SHOW CREATE TABLE your_table;
2
Examine the output for the `DEFAULT CHARSET` and `COLLATE` clauses. If these are set to a restrictive character set (e.g., `latin1`) and you are trying to store characters not supported by it (e.g., emojis, certain Asian characters), this will cause the error. Consider changing the character set to `utf8mb4` and a corresponding collation like `utf8mb4_unicode_ci`.
3
If you need to change the character set and collation, you will need to alter the table. This can be a complex operation for large tables and may require downtime. It's often best to do this during a maintenance window.
ALTER TABLE your_table CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
4
After altering the table, you may need to re-import or re-process data that failed due to the character set issue. Ensure that your application's connection to the database also uses the appropriate character set.

3. Review Application's Database Connection Settings easy

Confirm that your application is configured to use the correct character set when connecting to MySQL.

1
Locate the database connection configuration in your application. This might be in a configuration file (e.g., `.env`, `config.php`, `application.properties`) or within your code.
2
Ensure that the connection string or parameters specify the correct character set. If your database tables are using `utf8mb4`, your connection should also be set to `utf8mb4`.
Example (PHP with PDO):
$dsn = "mysql:host=localhost;dbname=your_db;charset=utf8mb4";
$username = 'your_user';
$password = 'your_password';

try {
    $pdo = new PDO($dsn, $username, $password);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
    echo 'Connection failed: ' . $e->getMessage();
    exit();
}
3
For some drivers or frameworks, there might be a specific setting for character set. Consult your application's framework or database connector documentation for details.
🔗

Related Errors

5 related errors