简体   繁体   English

MySQL 8.0.12 中的lower_case_table_names 设置

[英]lower_case_table_names Settings in MySQL 8.0.12

I've just compiled the version MySQL 8.0.12 in a Ubuntu 16.0.4.我刚刚在 Ubuntu 16.0.4 中编译了 MySQL 8.0.12 版本。

After following the instructions in the website and making the following my.cnf file:按照网站中的说明制作以下 my.cnf 文件后:

[mysqld]
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
port=3306
log-error=/usr/local/mysql/data/localhost.localdomain.err
user=mysql
secure_file_priv=/usr/local/mysql/mysql-files
local_infile=OFF

log_error = /var/log/mysql/error.log

# Remove case sensitive in table names
lower_case_table_names=1

I get the following error:我收到以下错误:

2018-08-11T19:45:06.461585Z 1 [ERROR] [MY-011087] [Server] Different lower_case_table_names settings for server ('1') and data dictionary ('0').

What should I change so that data dictionary is aligned to server settings?我应该更改什么才能使数据字典与服务器设置保持一致?

So far, I can get it to work with a workaround (I originally posted on askubuntu ): by re-initializing MySQL with the new value for lower_case_table_names after its installation.到目前为止,我可以通过一种变通方法(我最初发布在askubuntu 上)使其工作:通过在安装后使用lower_case_table_names的新值重新初始化 MySQL。 The following steps apply to a new installation.以下步骤适用于新安装。 If you have already data in a database, export it first to import it back later:如果数据库中已有数据,请先将其导出以便稍后将其导入:

  1. Install MySQL:安装 MySQL:
     sudo apt-get update sudo apt-get install mysql-server -y
  2. Stop the MySQL service:停止 MySQL 服务:
     sudo service mysql stop
  3. Delete the MySQL data directory:删除 MySQL 数据目录:
     sudo rm -rf /var/lib/mysql
  4. Recreate the MySQL data directory (yes, it is not sufficient to just delete its content):重新创建 MySQL 数据目录(是的,仅删除其内容是不够的):
     sudo mkdir /var/lib/mysql sudo chown mysql:mysql /var/lib/mysql sudo chmod 700 /var/lib/mysql
  5. Add lower_case_table_names = 1 to the [mysqld] section in /etc/mysql/mysql.conf.d/mysqld.cnf .添加lower_case_table_names = 1[mysqld]在部分/etc/mysql/mysql.conf.d/mysqld.cnf
  6. Re-initialize MySQL with --lower_case_table_names=1 :使用--lower_case_table_names=1重新初始化 MySQL:
     sudo mysqld --defaults-file=/etc/mysql/my.cnf --initialize --lower_case_table_names=1 --user=mysql --console
  7. Start the MySQL service:启动 MySQL 服务:
     sudo service mysql start
  8. Retrieve the new generated password for MySQL user root :为 MySQL 用户root检索新生成的密码:
     sudo grep 'temporary password' /var/log/mysql/error.log
  9. Change the password of MySQL user root either by:通过以下任一方式更改 MySQL 用户root的密码:
     sudo mysql -u root -p
    and executing:并执行:
     ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPa$$w0rd';
    afterwards, OR by calling the "hardening" script anyway:之后,或者无论如何调用“强化”脚本:
     sudo mysql_secure_installation

After that, you can verify the lower_case_table_names setting by entering the MySQL shell:之后,您可以通过输入 MySQL shell 来验证lower_case_table_names设置:

sudo mysql -u root -p

and executing:并执行:

SHOW VARIABLES LIKE 'lower_case_%';

Expected output:预期输出:

+------------------------+-------+
| Variable_name          | Value |
+------------------------+-------+
| lower_case_file_system | OFF   |
| lower_case_table_names | 1     |
+------------------------+-------+

根据此链接,lower_case_table_names 应与 --initialize 选项一起设置。

I've just compiled the version MySQL 8.0.12 in a Ubuntu 16.0.4.我刚刚在Ubuntu 16.0.4中编译了MySQL 8.0.12版本。

After following the instructions in the website and making the following my.cnf file:按照网站上的说明并制作以下​​my.cnf文件后:

[mysqld]
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
port=3306
log-error=/usr/local/mysql/data/localhost.localdomain.err
user=mysql
secure_file_priv=/usr/local/mysql/mysql-files
local_infile=OFF

log_error = /var/log/mysql/error.log

# Remove case sensitive in table names
lower_case_table_names=1

I get the following error:我收到以下错误:

2018-08-11T19:45:06.461585Z 1 [ERROR] [MY-011087] [Server] Different lower_case_table_names settings for server ('1') and data dictionary ('0').

What should I change so that data dictionary is aligned to server settings?我应该更改什么以使数据字典与服务器设置保持一致?

MySQL Documentation says MySQL 文档说

lower_case_table_names can only be configured while initializing the server. lower_case_table_names 只能在初始化服务器时配置。 Changing the lower_case_table_names setting after the server is initialized is prohibited.禁止在服务器初始化后更改lower_case_table_names 设置。

https://dev.mysql.com/doc/refman/8.0/en/identifier-case-sensitivity.html https://dev.mysql.com/doc/refman/8.0/en/identifier-case-sensitive.html

To fix this issue,为了解决这个问题,

  1. Just take the backup of the existing db Schema using the following command inside bin folder (/usr/local/mysql/bin) ./mysqldump -uroot -p password > dump.sql只需在 bin 文件夹 (/usr/local/mysql/bin) ./mysqldump -uroot -p password > dump.sql 中使用以下命令备份现有的 db Schema

  2. Once the backup is taken delete the existing data folder in Mysql Home(/usr/local/mysql/) using the command rm -rf data备份完成后,使用命令rm -rf data删除 Mysql Home(/usr/local/mysql/) 中的现有数据文件夹

  3. Now add the configuration as " lower_case_table_names=1 " in my.cnf under MYSQLD section (/etc/my.cnf)现在在MYSQLD 部分(/etc/my.cnf) 下的 my.cnf 中添加配置为“ lower_case_table_names=1

  4. Now Initialize the data directory using the following command inside bin directory (/usr/local/mysql/bin)现在在bin目录(/usr/local/mysql/bin)中使用以下命令初始化数据目录

For Secure mode ./mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql --console对于安全模式./mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql --console

For Insecure mode ./mysqld --defaults-file=/etc/my.cnf --initialize-insecure --user=mysql --console对于不安全模式./mysqld --defaults-file=/etc/my.cnf --initialize-insecure --user=mysql --console

  1. Once the data directory initialized, For Insecure mode repeat the Installation again and For Secure mode use the root password which is initialized during the run time of data directory Initialization.一旦数据目录初始化,对于不安全模式,再次重复安装,对于安全模式,使用在数据目录初始化运行时初始化的 root 密码。

  2. Now import the existing dump file inside the Mysql Server using the command inside (/usr/local/mysql/bin) directory现在使用 (/usr/local/mysql/bin) 目录中的命令导入 Mysql Server 中的现有转储文件

./mysql -uroot -p password < file.sql ./mysql -uroot -p 密码 <file.sql

The best way to prevent this problem is : At first add防止此问题的最佳方法是:首先添加

[mysqld]
lower_case_table_names=1

then start mysql service for first time.然后第一次启动mysql服务。

But anyway if you have started the server already,to solve your problem:但无论如何,如果你已经启动了服务器,来解决你的问题:

1.stop mysql: 1.停止mysql:

systemctl stop  mysql

2.clean data directory or change the default, the following is for new installations , if you have data in your database BACK UP them beforehand 2.clean数据目录或更改默认,以下是新安装的,如果你在你的数据库备份他们有事先的数据

rm -rf /var/lib/mysql

3.Insert lower_case_table_names = 1 in your my.cnf: 3.在你的my.cnf中插入lower_case_table_names = 1:

[mysqld]
lower_case_table_names=1

4.Start again 4.重新开始

systemctl start mysqld

I've just compiled the version MySQL 8.0.12 in a Ubuntu 16.0.4.我刚刚在Ubuntu 16.0.4中编译了MySQL 8.0.12版本。

After following the instructions in the website and making the following my.cnf file:按照网站上的说明并制作以下​​my.cnf文件后:

[mysqld]
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
port=3306
log-error=/usr/local/mysql/data/localhost.localdomain.err
user=mysql
secure_file_priv=/usr/local/mysql/mysql-files
local_infile=OFF

log_error = /var/log/mysql/error.log

# Remove case sensitive in table names
lower_case_table_names=1

I get the following error:我收到以下错误:

2018-08-11T19:45:06.461585Z 1 [ERROR] [MY-011087] [Server] Different lower_case_table_names settings for server ('1') and data dictionary ('0').

What should I change so that data dictionary is aligned to server settings?我应该更改什么以使数据字典与服务器设置保持一致?

如果现在有人遇到这个问题,如果你已经初始化了 mysql,这意味着你已经启动并运行了它,然后发生了这个错误,只需在 my.ini 文件中注释掉这一行。

lower_case_table_names=

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM