mysql大小写不敏感允许创建没有显式声明函数/存储过程 参数配置

内容目录

配置一个运行环境的时候java启动显示表找不到,原来需要大小写不敏感
导入数据库的时候发现
ERROR 1418 (HY000) at line 3898: This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled (you might want to use the less safe log_bin_trust_function_creators variable)
需要允许创建没有显式声明为确定性或指定 SQL 数据读取性质的函数/存储过程。

所以

在 MySQL 的配置文件 my.cnf 中添加这些配置项,可以调整 MySQL 的行为。这些选项各自有不同的作用:

  1. lower_case_table_names=1:控制表名的大小写敏感性。
  2. log_bin_trust_function_creators=1:允许创建没有显式声明为确定性或指定 SQL 数据读取性质的函数/存储过程。
  3. event_scheduler=1:启用事件调度器(Event Scheduler),允许 MySQL 定期执行事件。

如何编辑 my.cnf 文件

  1. 打开 my.cnf 文件进行编辑
    使用 vi 编辑器打开 MySQL 配置文件 /etc/my.cnf

    sudo vi /etc/my.cnf
  2. 添加配置项
    在文件中的 [mysqld] 部分(MySQL Server 配置部分)添加以下行:

    [mysqld]
    lower_case_table_names=1
    log_bin_trust_function_creators=1
    event_scheduler=1

    确保在 [mysqld] 部分下添加这些配置项,以便它们应用于 MySQL 服务。你可以将这些配置项放置在文件的末尾或其他 [mysqld] 配置项之后。

  3. 保存并退出

    • vi 中输入 Esc 键,然后输入 :wq 保存并退出。
    • 如果你不确定是否具有写入权限,可以使用 sudo 权限来确保你有权限编辑该文件。
  4. 重启 MySQL 服务
    配置文件修改后,需要重启 MySQL 服务以应用更改:

    sudo service mysql restart

    或者使用:

    sudo systemctl restart mysql

    重启服务后,新配置将生效。

配置项解释

  • lower_case_table_names=1

    • 该选项设置为 1 表示表名在磁盘上存储为小写,但在 MySQL 中不区分大小写。
    • 在 Windows 系统上通常默认为 1,因为 Windows 文件系统是大小写不敏感的。在 Linux 系统上默认为 0,意味着大小写敏感。
    • 设置为 1 可以避免在不同操作系统之间迁移数据库时出现的大小写问题。
  • log_bin_trust_function_creators=1

    • 允许用户创建存储函数和存储过程,即使这些函数和过程没有指定为 DETERMINISTICNO SQLREADS SQL DATA
    • 这种设置在开发环境中很常见,但在生产环境中需要谨慎使用,因为它可能会带来复制一致性问题。
  • event_scheduler=1

    • 启用事件调度器功能。启用后,可以在 MySQL 中使用 CREATE EVENT 语句调度定时任务。
    • 常用于定时执行某些任务,比如数据清理或定期备份。

通过这些配置,可以增强 MySQL 数据库的灵活性和功能性,但在应用到生产环境之前,需要对每个选项的影响有充分了解。

英文版本

Here is how you can edit the my.cnf file and what each of the configurations you mentioned does:

  1. lower_case_table_names=1: Controls case sensitivity of table names.
  2. log_bin_trust_function_creators=1: Allows the creation of stored functions or procedures that do not explicitly declare determinism or SQL data access properties.
  3. event_scheduler=1: Enables the event scheduler, which allows MySQL to execute scheduled events.

How to Edit the my.cnf File

  1. Open my.cnf for editing: Use the vi editor to open the MySQL configuration file /etc/my.cnf:

    sudo vi /etc/my.cnf
  2. Add the configuration options: Locate the [mysqld] section (the section for MySQL Server settings) and add the following lines:

    [mysqld]
    lower_case_table_names=1
    log_bin_trust_function_creators=1
    event_scheduler=1

    Make sure these lines are under the [mysqld] section so they apply to the MySQL service. You can place these lines at the end of the file or right after other [mysqld] configuration settings.

  3. Save and exit:

    • In vi, press the Esc key, then type :wq and press Enter to save and exit.
    • If you are not sure if you have write permissions, use sudo to ensure you can edit the file.
  4. Restart the MySQL service: After modifying the configuration file, restart the MySQL service to apply the changes:

    sudo service mysql restart

    Or use:

    sudo systemctl restart mysql

    Restarting the service will apply the new settings.

Explanation of Configuration Options

  • lower_case_table_names=1:

    • Setting this to 1 means table names are stored on disk in lowercase but comparisons are case-insensitive in MySQL.
    • This is typically set to 1 on Windows, where the file system is case-insensitive, and 0 on Linux, where the file system is case-sensitive.
    • Using 1 helps avoid case-sensitivity issues when migrating databases between different operating systems.
  • log_bin_trust_function_creators=1:

    • Allows users to create stored functions and procedures without explicitly marking them as DETERMINISTIC, NO SQL, or READS SQL DATA.
    • This setting is commonly used in development environments but should be used cautiously in production because it can lead to replication consistency issues.
  • event_scheduler=1:

    • Enables the event scheduler. With this enabled, you can use the CREATE EVENT statement to schedule tasks to run at specific times.
    • This is useful for automating tasks such as data cleanup or regular backups.

Using these settings can enhance the flexibility and functionality of your MySQL database, but it’s important to understand the implications, especially when applying them to a production environment.

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注