文章目录

MySQL问题处理汇总一、MySQL启动异常:error while loading shared libraries: libncurses.so.5: cannot open shared...二、This function has none of DETERMINISTIC, NO SQL.....(you *might* want to use the1.创建函数2.出现问题3.分析问题4.解决问题4.1 查询参数4.2 修改参数值4.3 检查修改结果

5.创建函数5.1 创建函数5.2 执行函数

补充:

三、Select into outfile导出文件ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement1.问题排查1.1 问题介绍1.2 问题分析

2.问题解决2.1 修改my.cnf2.2 重启mysqld2.3 再次导出失败,权限不足2.4 修改用户及用户组2.5 导出成功2.6 查看数据

四、Docker安装MySQL报错:mysqld failed while attempting to check config....mysqld: Can't read dir of '/etc/mysql/conf.d/'...

MySQL问题处理汇总

一、MySQL启动异常:error while loading shared libraries: libncurses.so.5: cannot open shared…

MySQL启动时出现如下日常: 提示加载不到libncurses.so.5

[root@kafka01 bin]# ./mysql -uroot -p

./mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory

方法一:yum安装libncurses.so.5(失败) 但是使用yum安装后,下载的libncurses.so.5在/usr/lib目录下,再次启动MySQL的时候还是会提示加载不到

[root@kafka01 bin]# yum install libncurses.so.5

[root@kafka01 bin]# find / -name 'libncurses*'

/usr/lib/libncursesw.so.5.9

/usr/lib/libncurses++.so.5

/usr/lib/libncurses++.so.5.9

/usr/lib/libncurses++w.so.5

/usr/lib/libncurses++w.so.5.9

/usr/lib/libncurses.so.5

/usr/lib/libncurses.so.5.9

/usr/lib/libncursesw.so.5

/usr/lib64/libncurses.so.6

/usr/lib64/libncurses.so.6.1

/usr/lib64/libncursesw.so.6

/usr/lib64/libncursesw.so.6.1

方法二:将/usr/lib64目录下的libncurses.so.6改为libncurses.so.5(成功)

[root@kafka01 bin]# cp /usr/lib64/libncurses.so.6 /usr/lib64/libncurses.so.5

拓展:如果遇到如下的报错信息,缺少libtinfo.so.5,也可以使用相同的方法处理

[root@kafka01 bin]# ./mysql -uroot -p

./mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory

[root@kafka01 bin]# find / -name 'libtinfo*'

/usr/lib/libtinfo.so.5

/usr/lib/libtinfo.so.5.9

/usr/lib64/libtinfo.so.6

/usr/lib64/libtinfo.so.6.1

[root@kafka01 bin]# cp /usr/lib64/libtinfo.so.6 /usr/lib64/libtinfo.so.5

二、This function has none of DETERMINISTIC, NO SQL…(you might want to use the

log_bin_trust_function_creators

在MySQL中,log_bin_trust_function_creators是一个系统变量,用于控制是否信任二进制日志中创建函数。当该变量的值为0时,MySQL将拒绝在二进制日志中执行创建函数的语句,以提高安全性。但是有时候在操作数据库的时候,可能会遇到log_bin_trust_function_creators错误,这意味着MySQL服务器拒绝了创建函数的请求。

1.创建函数

编写一个函数,实现通过传参查询第n高的工资。

-- 函数

CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT

BEGIN

set N = N - 1;

RETURN (

select ifnull((select distinct Salary from Employee order by Salary desc limit N,1),null)

as getNthHighestSalary

);

END

-- 执行

select getNthHighestSalary(2)

2.出现问题

3.分析问题

这是因为开启了bin-log日志,我们就必须确定函数中以下点:

deterministic 不确定的 no sql 没有SQL语句 reads sql data 只读数据 modifies sql data 修改数据 contains sql 包含SQL语句

因为在function中,只有deterministic ,no sql,reads sql data被支持。所以开启bin-log后必须为function指定参数

4.解决问题

4.1 查询参数

show variables like 'log_bin_trust_function_creators';

4.2 修改参数值

set global log_bin_trust_function_creators = 1;

4.3 检查修改结果

show variables like 'log_bin_trust_function_creators';

5.创建函数

5.1 创建函数

可以看到将参数 log_bin_trust_function_creators值改为1后,可以成功的创建函数

CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT

BEGIN

set N = N - 1;

RETURN (

select ifnull((select distinct Salary from Employee order by Salary desc limit N,1),null)

as getNthHighestSalary

);

END

5.2 执行函数

select getNthHighestSalary(2)

补充:

采用以上方法在数据库重启后还会失效,可以使用以下方法长期有效

root@hadoop_zxy ~]# vim /etc/my.cnf

在最后添加

log_bin_trust_function_creators = 1

三、Select into outfile导出文件ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement

1.问题排查

1.1 问题介绍

通过select … into outfile…导出数据的时候,提示如下问题:

ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement

mysql> select * from zxy into outfile '/zxy/data/mysql/zxy/zxy.txt';

ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement

1.2 问题分析

得知是secure-file-priv参数的影响,通过查询参数的介绍,得知当secure_file_priv指定了导出的位置,也就是只能导出到该目录。但是该参数还有其他配置项:

secure_file_priv=null 不允许导入导出 secure_file_priv=‘path’ 导入导出只能发生在指定的目录 secure_file_priv=‘’ 不对导入导出做限制

mysql> show variables like '%secure%';

+--------------------------+-----------------------+

| Variable_name | Value |

+--------------------------+-----------------------+

| require_secure_transport | OFF |

| secure_auth | ON |

| secure_file_priv | /var/lib/mysql-files/ |

+--------------------------+-----------------------+

3 rows in set (0.00 sec)

2.问题解决

2.1 修改my.cnf

根据业务需要,因为对于数据库来说导入导出数据还是有可能影响数据库安全的。在接受不对导入导出做限制的情况下,可以在配置文件my.cnf中做修改。

# my.cnf文件,在mysqld下添加如下参数即可

[mysqld]

secure_file_priv=''

2.2 重启mysqld

systemctl restart mysqld

2.3 再次导出失败,权限不足

不过现在还是会导出失败,因为导出的目录是root用户root组,mysql没有权限处理:

我希望将表数据导出到/zxy/data/mysql/zxy目录下,但是提示权限不足

mysql> select * from zxy into outfile '/zxy/data/mysql/zxy/zxy.txt';

ERROR 1 (HY000): Can't create/write to file '/zxy/data/mysql/zxy/zxy.txt' (Errcode: 13 - Permission denied)

2.4 修改用户及用户组

[root@zxy mysql]# chown mysql:mysql /zxy/data/mysql/zxy

2.5 导出成功

mysql> select * from zxy into outfile '/zxy/data/mysql/zxy/zxy.txt';

Query OK, 3 rows affected (0.00 sec)

2.6 查看数据

[root@zxy zxy]# ls

zxy.txt

[root@zxy zxy]# cat zxy.txt

1 ZXY 2023-03-10

2 zxy 2023-03-11

3 ZXY 2023-03-12

四、Docker安装MySQL报错:mysqld failed while attempting to check config…mysqld: Can’t read dir of ‘/etc/mysql/conf.d/’…

[ERROR] [Entrypoint]: mysqld failed while attempting to check config command was: mysqld --verbose --help --log-bin-index=/tmp/tmp.Frnt2oibYI mysqld: Can't read dir of '/etc/mysql/conf.d/' (Errcode: 2 - No such file or directory)

1 最初的时候使用如下命令创建容器,但是创建之后通过docker ps查看不到启动的容器

[root@zxy_master mysql01]# docker run -p 33061:3306 --name mysql01 \

> -v /zxy/apps/docker_mysql/mysql01/conf:/etc/mysql \

> -v /zxy/apps/docker_mysql/mysql01/data:/var/lib/mysql \

> -v /zxy/apps/docker_mysql/mysql01/log:/var/log/mysql \

> -e MYSQL_ROOT_PASSWORD=123456 \

> -d mysql:5.7

358163e8d564ff111a41efe06e83798c9518a65300502c12a63776c6a3639a8c

2 通过查看该容器的日志,可以看到主要是因为读取不到/etc/mysql/conf.d/目录

[root@zxy_master apps]# docker logs -f 358163e8d564

2022-12-20 05:46:26+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.40-1.el7 started.

2022-12-20 05:46:26+00:00 [ERROR] [Entrypoint]: mysqld failed while attempting to check config

command was: mysqld --verbose --help --log-bin-index=/tmp/tmp.XeHsvFblmW

mysqld: Can't read dir of '/etc/mysql/conf.d/' (Errcode: 2 - No such file or directory)

mysqld: [ERROR] Fatal error in defaults handling. Program aborted!

3 -v /zxy/apps/docker_mysql/mysql01/conf:/etc/mysql

修改为

-v /zxy/apps/docker_mysql/mysql01/conf:/etc/mysql/conf.d \

[root@zxy_master apps]# docker run -p 33061:3306 --name mysql01 \

> -v /zxy/apps/docker_mysql/mysql01/conf:/etc/mysql/conf.d \

> -v /zxy/apps/docker_mysql/mysql01/data:/var/lib/mysql \

> -v /zxy/apps/docker_mysql/mysql01/log:/var/log/mysql \

> -e MYSQL_ROOT_PASSWORD=123456 \

> -d mysql:5.7

faf2312fd62ad4ebe05ba2cffa9917b47417cfad1f8175912e1e0bc6e089986c

4 再次检查已经启动成功,报错原因主要是没有指定到conf.d目录,导致容器在启动的时候找不到该目录。

[root@zxy_master apps]# docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

faf2312fd62a mysql:5.7 "docker-entrypoint.s…" 3 seconds ago Up 2 seconds 33060/tcp, 0.0.0.0:33061->3306/tcp, :::33061->3306/tcp mysql01

精彩内容

评论可见,请评论后查看内容,谢谢!!!
 您阅读本篇文章共花了: