lower\u case\u table\u names=1不允许启动mysql

u5rb5r59  于 2021-06-18  发布在  Mysql
关注(0)|答案(5)|浏览(380)

我已经在ubuntu18.04上安装了mysql社区服务器8.013,我有以下问题。我想设置lower\u case\u table\u names=1,以便在我的数据库中有不区分大小写的表名。我编辑了/etc/mysql/mysql.conf.d/mysqld.cnf并在[mysqld]下添加了以下行

lower_case_table_names=1

现在mysqld.cnf如下

[mysqld]
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
datadir         = /var/lib/mysql
log-error       = /var/log/mysql/error.log
lower_case_table_names=1

我用停止mysql服务器

sudo service mysql stop

然后我试着用

sudo service mysql start

但我得到以下错误

Job for mysql.service failed because the control process exited with error code.
See "systemctl status mysql.service" and "journalctl -xe" for details.

我试过了

systemctl status mysql.service

我得到了以下信息

christoph@christoph-Latitude-E6530:/etc/init.d$ systemctl status mysql.service
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Thu 2018-11-01 16:38:14 EET; 24s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 6681 ExecStart=/usr/sbin/mysqld (code=exited, status=1/FAILURE)
  Process: 6642 ExecStartPre=/usr/share/mysql-8.0/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
 Main PID: 6681 (code=exited, status=1/FAILURE)
   Status: "SERVER_BOOTING"
    Error: 2 (No such file or directory)

Νοε 01 16:38:12 christoph-Latitude-E6530 systemd[1]: Starting MySQL Community Server...
Νοε 01 16:38:14 christoph-Latitude-E6530 systemd[1]: mysql.service: Main process exited, code=exited, status=1/FAILURE
Νοε 01 16:38:14 christoph-Latitude-E6530 systemd[1]: mysql.service: Failed with result 'exit-code'.
Νοε 01 16:38:14 christoph-Latitude-E6530 systemd[1]: Failed to start MySQL Community Server.

使用journalctl-xe我得到了以下信息

-- The result is RESULT.
Νοε 01 17:32:00 christoph-Latitude-E6530 sudo[2526]: pam_unix(sudo:session): session closed for user root
Νοε 01 17:32:04 christoph-Latitude-E6530 wpa_supplicant[743]: wlp3s0: WPA: Group rekeying completed with 4c:5e:0c:7a:95:cf [GTK=CCMP]
Νοε 01 17:32:08 christoph-Latitude-E6530 gnome-shell[1565]: Some code accessed the property 'discreteGpuAvailable' on the module 'appDisplay'. That property w
Νοε 01 17:32:08 christoph-Latitude-E6530 gnome-shell[1565]: Some code accessed the property 'WindowPreviewMenuItem' on the module 'windowPreview'. That proper
lines 1349-1371/1371 (END)
Νοε 01 17:31:58 christoph-Latitude-E6530 systemd[1]: Starting MySQL Community Server...
-- Subject: Unit mysql.service has begun start-up
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- Unit mysql.service has begun starting up.
Νοε 01 17:31:58 christoph-Latitude-E6530 audit[2593]: AVC apparmor="STATUS" operation="profile_replace" info="same as current profile, skipping" profile="unconfined" name="/usr/sbin/mysqld" pid=2593 comm=
Νοε 01 17:31:58 christoph-Latitude-E6530 kernel: kauditd_printk_skb: 28 callbacks suppressed
Νοε 01 17:31:58 christoph-Latitude-E6530 kernel: audit: type=1400 audit(1541086318.959:39): apparmor="STATUS" operation="profile_replace" info="same as current profile, skipping" profile="unconfined" name
Νοε 01 17:32:00 christoph-Latitude-E6530 systemd[1]: mysql.service: Main process exited, code=exited, status=1/FAILURE
Νοε 01 17:32:00 christoph-Latitude-E6530 systemd[1]: mysql.service: Failed with result 'exit-code'.
Νοε 01 17:32:00 christoph-Latitude-E6530 systemd[1]: Failed to start MySQL Community Server.
-- Subject: Unit mysql.service has failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- Unit mysql.service has failed.

我还尝试使用

sudo service mysql start --initialize lower_case_table_names=1

正如这里所描述的,mysql 8.0.12中的小写\u table \u names设置,但是我仍然得到相同的错误,mysql根本没有启动
如果我运行以下命令

sudo vi /var/log/mysql/error.log

我得到以下错误的原因

Different lower_case_table_names settings for server ('1') and data dictionary ('0').
Data Dictionary initialization failed.

你知道为什么会这样吗?怎么解决?

ct2axkht

ct2axkht1#

为了在mysql 8.0和linux中实现这一点,请遵循以下步骤
0)备份mysql架构,然后使用

mysqldump  -h localhost -u root -p mysql > /home/username/dumps/mysqldump.sql

然后停止使用mysql

sudo service mysql stop

1) 移动或删除/var/lib/mysql目录。这将删除所有数据库!!!!

mv /var/lib/mysql /tmp/mysql

2) 创建一个新的/var/lib/mysql目录,并使mysql user成为所有者

mkdir /var/lib/mysql
chown -R mysql:mysql /var/lib/mysql
chmod 750 /var/lib/mysql

3) 编辑/etc/mysql/mysql.conf.d/mysqld.cnf并在[mysqld]后面添加以下行

lower_case_table_names=1

4) 使用以下命令初始化mysql
mysqld--defaults file=/etc/mysql/my.cnf--initialize lower\u case\u table\u names=1--user=mysql--console
使用默认文件的实际位置更改默认文件。有关mysql初始化的详细信息,请参见:https://dev.mysql.com/doc/refman/8.0/en/data-directory-initialization-mysqld.html
5) (可选)重复

chown -R mysql:mysql /var/lib/mysql
chmod 750 /var/lib/mysql

如果/var/lib/mysql中文件的所有者不是mysql
6) 使用启动mysql

sudo service mysql start

7) 如果一切正常,请使用

mysql -u root -p

通过运行这个查询

SHOW VARIABLES where Variable_name like 'lower%';

你会得到

'lower_case_table_names', '1'

8) 使用步骤0中创建的转储还原mysql架构。
9) 执行mysql\u upgrade创建sys schema

ulydmbyx

ulydmbyx2#

我也有同样的问题。
我编辑了/etc/mysql/conf.d/mysql.cnf文件(不是/etc/mysql/mysql.conf.d/mysqld.cnf文件。)
我在[mysqld]行下面插入小写的\u table \u names=1(在下面的[mysqld]行下面没有行。
然后我使用sudo服务mysql restart重新启动mysql
它解决了我的问题。

lskq00tm

lskq00tm3#

请转到下面的位置并添加以下代码
位置-cd/etc/mysql/mysql.conf.d/
那么 sudo vim mysqld.cnf 接下来,在[mysqld]下面添加

lower_case_table_names=1
nxowjjhe

nxowjjhe4#

您需要重新创建mysql数据目录。根据https://dev.mysql.com/doc/refman/8.0/en/identifier-case-sensitivity.html lower_case_table_names 只能在初始化服务器时配置。
你可以用这个脚本https://github.com/igrmk/ubuntu-reinit-mysql.
请注意,您的数据将被销毁!所以在运行之前先创建一个备份。

llycmphe

llycmphe5#

我在新安装的ubuntu server 20.04和MySQL8.0.20(没有需要关心的现有数据库-因此,如果您有重要数据,那么您应该在执行此操作之前将其备份/导出到其他地方)上进行了此操作:
所以。。。我用提升权限做了所有事情:

sudo su

安装mysql(如果尚未安装):

apt-get install mysql-server

备份配置文件,卸载,删除所有数据库和mysql相关数据:

cp /etc/mysql/mysql.conf.d/mysqld.cnf /etc/mysql/mysql.conf.d/mysqld.cnf.backup
service mysql stop
apt-get --purge autoremove mysql-server
rm -R /var/lib/mysql

还原保存的配置文件,编辑该文件(在[mysqld]行下添加一行):

cp /etc/mysql/mysql.conf.d/mysqld.cnf.backup /etc/mysql/mysql.conf.d/mysqld.cnf
vim /etc/mysql/mysql.conf.d/mysqld.cnf

...
lower_case_table_names=1
...

重新安装mysql(保留配置文件),配置其他设置:

apt-get install mysql-server
service mysql start
mysql_secure_installation
mysql

SHOW VARIABLES LIKE 'lower_case_%';
exit

相关问题