mysql报错合集

2023-11-11

1、Too many connections

报错

quickBI上报错
数据源执行SQL失败:INTERNAL: java.sql.SQLException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Data source rejected establishment of connection, message from server: "Too many connections"

Navicat上报错
"Too many connections"

或者Linux上报错
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1040 (08004): Too many connections

处理

#1、 root 用户登录mysql
[root@master etc]# mysql -u root -p123456@qwe
Server version: 5.7.38 MySQL Community Server (GPL)
mysql> 
# 查看MySQL能建立的最大连接数
mysql> show variables like 'max_connections';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 151   |
+-----------------+-------+
1 row in set (0.00 sec)

# 查看响应的连接数
mysql> show status like 'max%connections';
+----------------------+-------+
| Variable_name        | Value |
+----------------------+-------+
| Max_used_connections | 152   |
+----------------------+-------+
1 row in set (0.00 sec)

# 设置最大连接数为1000
mysql> set global max_connections=1000;
Query OK, 0 rows affected (0.00 sec)

# 查看MySQL能建立的最大连接数
mysql> show variables like 'max_connections';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 1000  |
+-----------------+-------+
1 row in set (0.00 sec)

# 设置的最大连接数只在mysql当前服务进程有效,一旦mysql重启,又会恢复到初始状态。
# 因为mysql启动后的初始化工作是从其配置文件中读取数据的,而这种方式没有对其配置文件做更改。
# 可以通过修改配置文件来修改mysql最大连接数(max_connections)

#2、 MySQL 的配置文件是 my.cnf,一般会放在 /etc/my.cnf 或 /etc/mysql/my.cnf 目录下

[root@master mysql]# cat /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]
#
...
max_connections=1000

log-error=/var/log/mysqld.log

Linux下mysql修改连接超时wait_timeout(在这个问题中,不是必要操作)

# 大规模多线程操作事务的时候,有时候打开一个链接,会进行等待,
# 这时候如果数据库的超时时间设置的过短,就可能会出现,数据链接自动被释放,可能会遭遇到“mysql has gone away”之类的问题。
# 当然设置过大也不好,慢SQL或其他因素引起的链接过长,MySQL里大量的SLEEP进程无法及时释放,导致整个系统被拖慢,甚至挂掉。
# 所以,需要适当的设置超时时间
mysql> 
# 查看超时时间设置
mysql> SHOW GLOBAL VARIABLES LIKE '%timeout%';
+-----------------------------+----------+
| Variable_name               | Value    |
+-----------------------------+----------+
| connect_timeout             | 10       |
| delayed_insert_timeout      | 300      |
| have_statement_timeout      | YES      |
| innodb_flush_log_at_timeout | 1        |
| innodb_lock_wait_timeout    | 50       |
| innodb_rollback_on_timeout  | OFF      |
| interactive_timeout         | 28800    |
| lock_wait_timeout           | 31536000 |
| net_read_timeout            | 30       |
| net_write_timeout           | 60       |
| rpl_stop_slave_timeout      | 31536000 |
| slave_net_timeout           | 60       |
| wait_timeout                | 28800    |
+-----------------------------+----------+
13 rows in set (0.00 sec)
# 通过jdbc连接数据库是非交互式连接

# 设置为10000(临时方法,重启MySQL服务器会失效,恢复默认值)
mysql> SET GLOBAL wait_timeout=10000;
Query OK, 0 rows affected (0.00 sec)

mysql> SHOW GLOBAL VARIABLES LIKE '%timeout%';
+-----------------------------+----------+
| Variable_name               | Value    |
+-----------------------------+----------+
| connect_timeout             | 10       |
| delayed_insert_timeout      | 300      |
| have_statement_timeout      | YES      |
| innodb_flush_log_at_timeout | 1        |
| innodb_lock_wait_timeout    | 50       |
| innodb_rollback_on_timeout  | OFF      |
| interactive_timeout         | 28800    |
| lock_wait_timeout           | 31536000 |
| net_read_timeout            | 30       |
| net_write_timeout           | 60       |
| rpl_stop_slave_timeout      | 31536000 |
| slave_net_timeout           | 60       |
| wait_timeout                | 10000    |
+-----------------------------+----------+
13 rows in set (0.01 sec)

2、运行建表语句时,Navicat报错

报错

1142 - CREATE command denied to user 'test_v'@'192.168.1.1' for table 'price_a'

处理

是数据库权限设置的问题

# root 用户登录mysql
[root@master etc]# mysql -u root -p123456@qwe
Server version: 5.7.38 MySQL Community Server (GPL)
mysql> 
mysql> use test_my;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> grant all privileges on test_my.* to test_v;  # test_my是数据库,test_v是使用test_my的用户
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;  # 刷新
Query OK, 0 rows affected (0.00 sec)

mysql> 

3、Navicat运行脚本报错

报错

Got a packet bigger than 'max_allowed_packet' bytes

导入的数据大于系统的限制的最大包大小

处理

[root@master ~]# mysql -u root -p123456@qwe
Server version: 5.7.38 MySQL Community Server (GPL)
mysql> 
# 查看max_allowed_packet的大小
mysql> show variables like '%max_allowed_packet%' ;
+--------------------------+-------+
| Variable_name            | Value |
+--------------------------+-------+
| max_allowed_packet       | 2048  |
| slave_max_allowed_packet | 2048  |
+--------------------------+-------+
2 rows in set (0.00 sec)

# 方式一
mysql> SET GLOBAL max_allowed_packet=150M;
ERROR 1232 (42000): Incorrect argument type to variable 'max_allowed_packet'
# 报错就用,方式二
mysql> SET GLOBAL max_allowed_packet=152428800;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> show variables like '%max_allowed_packet%' ;
+--------------------------+-------+
| Variable_name            | Value |
+--------------------------+-------+
| max_allowed_packet       | 2048  |
| slave_max_allowed_packet | 2048  |
+--------------------------+-------+
2 rows in set (0.00 sec)

mysql> 
# Navicat 就可以运行脚本了
# 等运行结束,

Linux下mysql修改max_allowed_packet参数配置(这个问题中,非必要操作),重启生效

[root@master ~]# mysql --help | grep my.cnf
                      order of preference, my.cnf, $MYSQL_TCP_PORT,
/etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf 
[root@master ~]# vim /etc/my.cnf
[root@master ~]# cat /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]

datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
character-set-server=UTF8MB4
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
max_connections=1000
lower_case_table_names=1 

max_allowed_packet = 100M

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

# 重启MySQL
[root@master ~]# service mysqld restart

4、Packet for query is too large (2656 > 1024)

quick BI报错

任务执行失败.:com.mysql.jdbc.PacketTooBigException: Packet for query is too large (2656 > 1024). You can change this value on the server by setting the max_allowed_packet' variable.
报错详情

数据源执行SQL失败:INTERNAL: java.lang.RuntimeException: SQL execute error by datasource... 
com.mysql.jdbc.PacketTooBigException: Packet for query is too large (2884 > 1024). You can change this value on the server by setting the max_allowed_packet' variable. 
com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3540) 
com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2417) 
com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2582) 
com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2531) 
com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2489)

原因是mysql的max_allowed_packet设置过小引起的

解决

mysql>show VARIABLES like '%max_allowed_packet%';

mysql>set global max_allowed_packet = 2*1024*1024*10;

mysql> show variables like '%max_allowed_packet%' ;
+--------------------------+------------+
| Variable_name            | Value      |
+--------------------------+------------+
| max_allowed_packet       | 104857600  |
| slave_max_allowed_packet | 1073741824 |
+--------------------------+------------+
2 rows in set (0.00 sec)

5、使用navicat连接mysql报错 2003

2003-Can’t connect to MySQL server (10060)错误
在这里插入图片描述
可能的原因:

  • 网络不通畅
  • mysql 服务未启动
  • 防火墙未开放端口

我这边Linux下能进入MySQL,就不存在前两种情况

# 查看防火墙状态
[root@localhost ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since 三 2022-07-27 17:18:18 CST; 1 day 16h ago
     Docs: man:firewalld(1)
 Main PID: 779 (firewalld)
   CGroup: /system.slice/firewalld.service
           └─779 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid

727 17:18:17 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
727 17:18:18 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.
727 17:18:19 localhost.localdomain firewalld[779]: WARNING: AllowZoneDrifting is enabled. This is considered an insecure configuration ...it now.
Hint: Some lines were ellipsized, use -l to show in full.
# 查看所有已开放的临时端口
[root@localhost ~]# firewall-cmd --list-ports

# 查看所有永久开放的端口
[root@localhost ~]# firewall-cmd --list-ports --permanent

# 添加永久开放的端口
[root@localhost ~]# firewall-cmd --add-port=3306/tcp --permanent
success
# 查看所有永久开放的端口
[root@localhost ~]# firewall-cmd --list-ports --permanent
3306/tcp
# 重载
[root@localhost ~]# firewall-cmd --reload
success
# 重启防火墙
[root@localhost ~]# systemctl restart firewalld
# 查看防火墙状态
[root@localhost ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since 五 2022-07-29 09:48:02 CST; 12s ago
     Docs: man:firewalld(1)
 Main PID: 30500 (firewalld)
   CGroup: /system.slice/firewalld.service
           └─30500 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid

729 09:48:01 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
729 09:48:02 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.
729 09:48:02 localhost.localdomain firewalld[30500]: WARNING: AllowZoneDrifting is enabled. This is considered an insecure configuratio...it now.
Hint: Some lines were ellipsized, use -l to show in full.
# 查看所有永久开放的端口
[root@localhost ~]# firewall-cmd --list-ports --permanent
3306/tcp 

6、使用navicat连接mysql报错 1130

1130-host is not allowed to connect to this MySQL server

在这里插入图片描述

7、navicat报错 1142

报错

1142 - CREATE command denied to user ‘test_v’@‘192.168.1.11’ for table

[root@localhost ~]# 
[root@localhost ~]# mysql -uroot -p89jdhHYT@#$
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 37
Server version: 5.7.38 MySQL Community Server (GPL)

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 
mysql> 
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select Host,User from user;
+------------------+---------------+
| Host             | User          |
+------------------+---------------+
| %                | root          |
| 192.168.1.1      | test_v        |
| localhost        | mysql.session |
| localhost        | mysql.sys     |
+------------------+---------------+
9 rows in set (0.00 sec)

mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP ON test.* TO 'test_v'@'192.168.1.11' identified by '12!QAwsar@1234';
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

mysql报错合集 的相关文章

随机推荐

  • 【规划】RRT Planer 以及 python实现

    本文转载自头条号作者半杯茶的小酒杯 百度的研发工程师 文章多是自动驾驶相关 推介给大家 RRT Planer 快速搜索随机树 RRT Rapidly ExploringRandom Trees 是一种常见的用于机器人路径规划的方法 他的原始
  • Qt中的JSON操作

    JSON JavaScript Object Notation js对象标记 是一种轻量级的数据交换格式 它基于ECMAScript的一个子集 使用完全独立于编程语言的文本格式来存储和表示数据 简洁和清晰的的层次结构使得JSON成为理想的数
  • ScaleTable matlab,【转】用matlab跑一下下面的程序,带上耳机,你会有发现一些惊喜噢...

    Cripple Pachebel s Canon on Matlab Have fun fs 44100 sample rate dt 1 fs T16 0 125 t16 0 dt T16 temp k size t16 t4 linsp
  • mysql导出binLog日志

    安装 https blog csdn net weixin 43423484 article details 124408565 设置 mysqld 设置3306端口 port 3306 设置mysql的安装目录 这里输入你安装的文件路径
  • 缺少项目经验 & 找工作处处碰壁?这 240 个实战项目请打包带走!

    全部面试找工作时 最常被问到的问题就是 有什么项目经验 对于毕业生来说 我们刚走出校园 还没有工作和项目经验 只能拿学校里练习做的 小游戏 或者 命令行程序 出来 但是 这些项目并不符合现代编程的需要 现代编程需要 前后端分工合作 网络接入
  • 云直播SDK核心功能对比|腾讯云、阿里云、声网、即构等SDK厂商对比

    直播业务概述 大家所熟知的直播平台虎牙 斗鱼 快手 抖音 B站 直播功能看似普遍 但从零到一开发却不简单 直播中运用到的技术难点非常之多 音频视频处理 编解码 前后处理 直播分发 即时通讯等技术 学好任何一项都需要比较高的成本 将它们融合到
  • QT从入门到实战x篇_14_消息对话框(QMessageBox、静态成员函数的访问、修改按键、利用函数返回值为枚举判断按键类型,实现指定动作)

    接上篇 QT从入门到实战x篇 xx 模态和非模态对话框创建 对话框建立在栈上运行完即释放 堆上不删除不可释放 对象在栈上及堆上的生命周期问题需弄懂 在帮助文档中 搜索QMessageBox 会看到其比较重要的几个函数如下 对应的为静态成员函
  • npm start 作用

    在配置phonecat项目时需要运行npm start在本地配置一个服务器环境 npm start首先会安装一系列的必要程序 这些程序依赖package json中的内容 package json中的内容详解如下 依赖包介绍 在克隆项目之后
  • 【Android开发】toast提示

    什么是Toast 在屏幕下方浮现出一个窗口 显示一段时间后又消失 这个可视化组件叫做 Toast 它主要用于提示用户某种事件发生了 如何在添加Toast 最关键的是在事件处理逻辑中加两条语句 定义一个Toast 用makeText 设置要浮
  • 饥荒暴食模式服务器无响应,饥荒暴食模式无银盘图文攻略介绍

    饥荒暴食模式无银盘图文攻略介绍 2018 06 26 17 03 50来源 游戏下载编辑 苦力趴评论 0 饥荒 近日推出了新的游戏模式暴食模式 玩家可以选择单人通关亦或是组队一同任务 下面就为大家带来饥荒暴食模式无银盘图文攻略介绍 基本思路
  • 数据库之数据库设计和E-R模型

    本篇文章介绍数据库设计和E R模型 内容基本是笔者在学习 数据库系统概念 时摘抄总结而来 仅作笔记 实体 联系模型 实体 联系 entity relationship E R 数据模型的提出旨在方便数据库的设计 它是通过允许定义代表数据库全
  • related work

    Traditional approaches e g genetic algorithm GA 2 and ant colony optimization ACO 3 can obtain optimal mapping results b
  • mysql查询练习(三)

    31 查询成绩比该课程平均成绩低的同学的成绩表 mysql gt select from score a where degree lt select avg degree from score b where a cno b cno sn
  • 查看linux系统版本命令

    一 查看内核版本命令 1 root SOR SYS cat proc version Linux version 2 6 18 238 el5 mockbuild x86 012 build bos redhat com gcc versi
  • Robot Framework完整流程学习--分层思想

    一 环境搭建 网上有很多的教程 这里就不多讲了 二 RIDE的界面认识 这里只介绍几个重要常用的功能 其他相信自己都能理解 1 Search Keywords F5 搜索关键字 2 Content Assistance 内容助手 3 Vie
  • java 多线程 总结一

    首先讲一下进程和线程的区别 进程 每个进程都有独立的代码和数据空间 进程上下文 进程间的切换会有较大的开销 一个进程包含1 n个线程 线程 同一类线程共享代码和数据空间 每个线程有独立的运行栈和程序计数器 PC 线程切换开销小 线程和进程一
  • nmap常规使用和参数超细详解 -- 小黑liux武器库详解<宝藏文>

    namp非常强大的主机发现和端口扫描工具 这是web渗透常用的工具 包含四项基本功能 主机发现 端口扫描 版本侦测 操作系统侦测 目录 常规使用 单体拳法 组合拳 参数详解 主机发现 扫描技术 服务版本探测 操作系统检测 防火墙 IDS规避
  • opencv +数字识别

    现在很多场景需要使用的数字识别 比如银行卡识别 以及车牌识别等 在AI领域有很多图像识别算法 大多是居于opencv 或者谷歌开源的tesseract 识别 由于公司业务需要 需要开发一个客户端程序 同时需要在xp这种老古董的机子上运行 故
  • protoBuffer的下载以及使用①

    这里写了一个简单的示例检测proto是否可以使用 使用protoBuf需要提供以下 protobuf java 2 6 1 sources jar protoc 2 6 1 win32 zip 这两个文件我已经添加了附件 当然也可去谷歌官网
  • mysql报错合集

    1 Too many connections 报错 quickBI上报错 数据源执行SQL失败 INTERNAL java sql SQLException com mysql jdbc exceptions jdbc4 MySQLNonT