MySQL常见报错汇总
1>.ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
报错原因:
在MySQL的配置文件中未指定“--secure-file-priv”参数的默认值,而改参数的功能就是确定使用SELECT ... INTO语句时将查询的结果保存到本地文件中,如果未指定则不可以使用该功能。
解决方案:
既然知道原因所在,我们需要做2个操作,第一步是修改配置文件,如下所示。第二步就是重启MySQL服务使得配置生效~
[root@node110 ~]# cat /etc/my.cnf | grep secure_file_priv secure_file_priv=/yinzhengjie/backup [root@node110 ~]# [root@node110 ~]# /etc/init.d/mysql.server restart Shutting down MySQL... SUCCESS! Starting MySQL. SUCCESS! [root@node110 ~]#
2>.ERROR 1 (HY000): Can't create/write to file '/yinzhengjie/backup/student.bak' (OS errno 13 - Permission denied)
报错原因:
根据报错的提示信息大家不难判断,这是由于权限不足导致!
解决方案:
既然知道的报错的原因,解决起来就很轻松了,比如改目录分配相应的权限,一种比较暴力的方法就是给该目录分配最高权限。如下所示:(当然你也可以只给启动mysql服务的用户分配ACL权限~)
[root@node110 backup]# pwd /yinzhengjie/backup [root@node110 backup]# [root@node110 yinzhengjie]# ll total 12 drwxr-xr-x. 2 root root 4096 Jan 26 15:08 backup drwxr-xr-x. 2 root root 4096 Jan 23 06:04 download drwxr-xr-x. 3 root root 4096 Jan 23 06:04 softwares [root@node110 yinzhengjie]# chmod 777 backup -R [root@node110 yinzhengjie]# [root@node110 yinzhengjie]# [root@node110 yinzhengjie]# ll total 12 drwxrwxrwx. 2 root root 4096 Jan 26 15:08 backup drwxr-xr-x. 2 root root 4096 Jan 23 06:04 download drwxr-xr-x. 3 root root 4096 Jan 23 06:04 softwares [root@node110 yinzhengjie]#
3>.ERROR 1418 (HY000): 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)
报错原因:
根据上面的提示,想必大家猜的已经八九不离十来,这是我们开启了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指定一个参数。
解决方案:
在MySQL中创建函数时出现上述错误的解决方法,如下:
mysql> SHOW VARIABLES LIKE 'log_bin'; #在MySQL8.0中,log_bin被打开了,在MySQL5.7之前的版本是关闭状态的! +---------------+-------+ | Variable_name | Value | +---------------+-------+ | log_bin | ON | +---------------+-------+ 1 row in set (0.00 sec) mysql> mysql> SHOW VARIABLES LIKE '%trust%'; +---------------------------------+-------+ | Variable_name | Value | +---------------------------------+-------+ | log_bin_trust_function_creators | OFF | +---------------------------------+-------+ 1 row in set (0.00 sec) mysql> mysql> set global log_bin_trust_function_creators=TRUE; #由于开启了log_bin功能,因此我们需要将创建函数的功能手动开启 Query OK, 0 rows affected (0.00 sec) mysql> mysql> SHOW VARIABLES LIKE '%trust%'; +---------------------------------+-------+ | Variable_name | Value | +---------------------------------+-------+ | log_bin_trust_function_creators | ON | +---------------------------------+-------+ 1 row in set (0.00 sec) mysql> mysql> mysql> set global log_bin_trust_function_creators=TRUE; Query OK, 0 rows affected (0.00 sec) mysql> mysql> CREATE FUNCTION hello(str CHAR(30)) -> RETURNS CHAR(50) -> RETURN CONCAT('Hello,',str,'!'); Query OK, 0 rows affected (0.00 sec) mysql>
4>.mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
报错原因:
缺少依赖库文件,名曰“libaio.so”。
解决方案:
既然知道缺少依赖库文件,我们直接使用yum工具安装一下即可!具体操作如下所示:
[root@node101 ~]# yum -y install libaio Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirror.jdcloud.com * extras: mirrors.neusoft.edu.cn * updates: mirrors.163.com Resolving Dependencies --> Running transaction check ---> Package libaio.x86_64 0:0.3.109-13.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ======================================================================================================================================================================================= Package Arch Version Repository Size ======================================================================================================================================================================================= Installing: libaio x86_64 0.3.109-13.el7 base 24 k Transaction Summary ======================================================================================================================================================================================= Install 1 Package Total download size: 24 k Installed size: 38 k Downloading packages: libaio-0.3.109-13.el7.x86_64.rpm | 24 kB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : libaio-0.3.109-13.el7.x86_64 1/1 Verifying : libaio-0.3.109-13.el7.x86_64 1/1 Installed: libaio.x86_64 0:0.3.109-13.el7 Complete! [root@node101 ~]#
5>.mysqld_safe error: log-error set to '/var/log/mariadb/mariadb.log', however file don't exists. Create writable for user 'mysql'.
报错原因:
很明显是文件权限问题,大家可以自行去看"/etc/my.cnf"配置文件的内容配置的是否正确,如果你配置的目录或文件不存在的话,可能会抛出各种各样的异常!
解决方案:
[root@node101 ~]# mkdir /var/log/mariadb [root@node101 ~]# [root@node101 ~]# touch /var/log/mariadb/mariadb.log [root@node101 ~]# [root@node101 ~]# chown -R mysql:mysql /var/log/mariadb/ [root@node101 ~]#
如果你发现本篇博客没有你相关的错误处理记录,也可以去看看官网常见的错误分析,是否有和你报错一致的:https://dev.mysql.com/doc/refman/8.0/en/error-handling.html。