Mysql Errors

Mysql Errors

1 ERROR 1044

 

1.1 42000

  • 错误信息css

    MariaDB [mysql]>  grant select on information_schema.* to 'test'@'%';
    ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'information_schema'
    
  • 缘由html

    information_schema是一个视图库,里面全部对象都是以视图的形式存在的,并且是在实例启动时自动加载和建立的。 Mariadb 不容许 对该库进行任何的操做。java

  • 解决python

    对于information_schema库的问题,咱们能够针对其源表进行受权 。informat_schema库的源表是 mysql库。只要 让test用户拥有查询mysql库的权限,天然就能够查询information_schema库了。mysql

    grant select on mysql.* to 'test'@'%';
    

2 ERROR 1045

 

2.1 28000

 

2.1.1 无登陆权限

  • 错误信息sql

    ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
    

    在有些状况下,mysql 使用root 用户登陆时,会出现这种状况。具体缘由不明。咱不会读源码, 否则这个问题必定给它搞清楚。蛋疼。shell

  • 解决方法 解决这个问题的方法,不一样的版本中操做方法也不同。主要是经过修改mysql.user 中保存的密码 , 可是不一样的版本还会有些小的区别,早期版本,只要更新mysql.user表就能够,可是mysql 5.6 / 5.7,除了手动更新mysql.user,还要另外执行一个操做。下面是主要操做流程:数据库

    # 修改参数实现免认证登陆数据库
    将/etc/my.cnf 中的[mysqld] 下面加上一行skip-grant-tables,保存退出编译文件。
    
    # 重启mysql,不一样版本的操做系统中命令不同,此处以CentOS 7 为例
    systemctl restart mysqld
    
    # 手动更新mysql.user.authentication_string 或者 mysql.user.password 字段
    update mysql.user set authentication_string=password('您的密码') where user='root';
    flush privileges;
    
    # 5.5 以前的版本中,到这一步,再重启Mysql,就能够了。可是5.六、5.7之后还要额外操做:
    # 关闭mysql
    systemctl stop mysqld
    
    # 取消免密登陆,修改/etc/my.cnf 将skip-grant-tables 参数注释或者删除。
    
    # 编译文件initfile.txt,在文件中添加以下一句SQL:
    SET PASSWORD FOR 'root'@'localhost' = PASSWORD('密码');
    
    # 启动mysql 指定--init-file参数,参数值即在上一步中编译的文件名,在启动时执行脚本中的命令
    # 若是不经过这种方式,仍会遇到错误。
    mysqld --init-file=initfile.txt
    
    # 重启mysql
    systemctl restart mysqld
    
    

2.1.2 无文件访问权限

  • 错误信息
MySQL [ypsx_order0]> select * into outfile '/tmp/a.xls' from order0;
ERROR 1045 (28000): Access denied for user 'order_read'@'%' (using password: YES)

当将一张表中的数据经过 select outfile 方式将数据备份至文件系统时出现。sass

  • 分析缘由

其实这个问题也并无跳出圈外。仍旧是权限问题,只不过是是否有访问文件的权限。 Mysql.user表中列出了一个用户所能够拥有的全部权限,其中包含一个 File_Priv 字段,这个字段表明用户是否有写文件的权限。只有拥有这个权限,才有可能进行下一 步–> 写文件,固然写文件前还要判断Mysql用户是否有文件路径有写权限等。ruby

  • 解决方法

    update mysql.user set File_priv=’Y’ where user=’xxxx’;
    

3 ERROR 1055

  • 错误信息

    [Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column
    'information_schema.PROFILING.SEQ' which is not functionally dependent on columns in GROUP BY clause;
    this is incompatible with sql_mode=only_full_group_by
    
  • 缘由分析
    Mysql 中的SQL 语法并是严格按照SQL 95 标准的。在聚合操做时,group by 容许不包含全部select的非聚合 列. mysql 提供了一个参数可使SQL 严格按照SQL 95标准编写,可是同时此参数是存在缺陷的。一些delete 等非聚合操做,从java 客户端发起时,有可能会引发错误:[err] 1055.
  • 解决方案
    简单的解决方案就是取消此参数设置。参数的设置方法以下:

    # 临时调整
    set @@sql_mode='参数列表,以逗号分隔'
    或者
    set global sql_mode='参数列表,以逗号分隔'
    # 永久调整  修改参数配置文件my.cnf
    sql_mode = '参数列表,不一样参数之间以逗号分隔'
    
  • 操做示例
    在Mysql 里大部分的参数是分为全局和会话级别,全局分为临时与永久。通常临时调整就是经过set 命令调整。 全局调整,须要在参数文件中修改, 通常为/etc/my.cnf
    • 临时修改示例

      mysql> set global sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
      Query OK, 0 rows affected (0.00 sec)
      mysql> exit
      Bye
      [root@test ~]# mysql -D
      Reading table information for completion of table and column names
      You can turn off this feature to get a quicker startup with -A
      
      Welcome to the MySQL monitor.  Commands end with ; or \g.
      Your MySQL connection id is 1814164
      Server version: 5.7.17 MySQL Community Server (GPL)
      
      Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
      
      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> select @@sql_mode;
      +------------------------------------------------------------------------------------------------------------------------+
      | @@sql_mode                                                                                                             |
      +------------------------------------------------------------------------------------------------------------------------+
      | STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |
      +------------------------------------------------------------------------------------------------------------------------+
      1 row in set (0.00 sec)
      
    • 永久修改示例

      # 修改以前
      sql_mode='ONLY_FULL_GROUP_BY,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
      # 修改以后
      sql_mode='NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
      

4 ERROR 1201

  • error code:ERROR 1201 (HY000): Could not initialize master info structure; more error messages can be found in the MySQL error log
  • Reason:

      出现这个问题的缘由是以前曾作过主从复制!须要reset slave后再change
    
  • Solve:

    reset slave;
    

5 ERROR 1292

 

5.1 22007

  • 错误信息

    ERROR 1292 (22007): Truncated incorrect DOUBLE value: ''
    
  • 分析

    该错误是因为 MySQL 对字符值是否符合字段要求进行了严格的检查,可是有时候,这个 检查的结果倒是错误的。就像下面示例:

    MariaDB [(none)]> update test.test set status=NULL where status=6;
    
    ERROR 1292 (22007): Truncated incorrect DOUBLE value: ''
    
    MariaDB [(none)]> desc test.test;
    +---------------------+--------------+------+-----+---------+----------------+
    | Field               | Type         | Null | Key | Default | Extra          |
    +---------------------+--------------+------+-----+---------+----------------+
    | id                  | bigint(20)   | NO   | PRI | NULL    | auto_increment |
    | status              | varchar(30)  | YES  |     | NULL    |                |
    +---------------------+--------------+------+-----+---------+----------------+
    2 rows in set (0.02 sec)
    

    从上面的查询结果来看,status 字段容许为空, 默认为空。我将该字段值更新为空字段并 没有违反该字段的约束条件。可是,错误就是么离奇的发生了。明明没有问题,却提示为错误 数据。

  • 查看SQL_MODE

      MariaDB [(none)]> show variables like 'sql_mode';
    +---------------+-------------------------------------------------------------------------------------------+
    | Variable_name | Value                                                                                     |
    +---------------+-------------------------------------------------------------------------------------------+
    | sql_mode      | STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |
    +---------------+-------------------------------------------------------------------------------------------+
    
  • 解决 主要是把sql_mode中的strict_trans_tables去掉便可。

    set [global | session] variables sql_mode = 'ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
    

6 ERROR 1293

 

6.1 HY000

 

6.1.1 错误信息

ERROR 1293 (HY000) at line 35: Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause

6.1.2 缘由

MySQL功能上的缺陷,不容许同一张表中的多个timestamp字段同时具备 on update current_timestamp() 的功能, 建表语句中只有第一个timestamp字段能够有这种属性,后面的不能够。在5.5及以前的版本中都 有这样的限制。5.6.5 之后取消了这种限制并扩展到了datetime类型字段上。 官方文档中有以下描述

  • MySQL 5.5

    One TIMESTAMP column in a table can have the current timestamp as the default value for initializing the column, as the auto-update value, or both. It is not possible to have the current timestamp be the default value for one column and the auto-update value for another column.
    
  • MySQL 5.6.5

    Previously, at most one TIMESTAMP column per table could be automatically initialized or updated to the current date and time. This restriction has been lifted. Any TIMESTAMP column definition can have any combination of DEFAULT CURRENT_TIMESTAMP and ON UPDATE CURRENT_TIMESTAMP clauses. In addition, these clauses now can be used with DATETIME column definitions. For more information, see Automatic Initialization and Updating for TIMESTAMP and DATETIME.
    

6.1.3 解决方法

  1. 升级mysql 到 5.6.5 及以上版本。
  2. 修改建表语句,只保留第一个timestamp字段使用current_timestamp()。

7 ERROR 1548

错误信息:

Cannot load from mysql.proc. The table is probably corrupted.

内部表结构不对。须要升级更新:

mysql_upgrade -uroot -p

8 ERROR 1872

 

8.1 错误信息

ERROR 1872 (HY000): Slave failed to initialize relay log info structure from the repository

8.2 分析缘由

  1. 配置了参数 log_slave_updates . 配置此参数后, 数据库相应的须要生成中继日志,若是没有配置,则不会生成,也就是说,log_slave_updates 依赖于relay_log。
    所以,在这种状况下,要求 配置relay_log 参数
  2. master.info 文件中的信息有误
  3. slave 信息变更 slave 信息发生变更,使用reset slave. 可是内存中的信息没有被清空。要清空内存与配置中的信息,须要执行reset slave all;
  4. …. 未知.

9 ERROR 2003

  • error code:ERROR 2003 (HY000): Can't connect to MySQL server on 'ip_address' (111)
  • Reason:

10 ERROR 2013

 

10.1 错误提示

mysqldump: Error 2013: Lost connection to MySQL server during query when dumping table `xxxxx` at row: 7114978

10.2 缘由1

  • 缘由

    mysqldump来不及接受mysql server端发送过来的数据,Server端的数据就会积压在内存中等待发送,
    这个等待不是无限期的,当Server的等待时间超过net_write_timeout(默认是60秒)时它就失去了耐心,
    mysqldump的链接会被断开,同时抛出错误Got error: 2013: Lost connection.
    
    增长net_write_timeout能够解决上述的问题的。在实践中发现,在增大 net_write_timeout后,
    Server端会消耗更多的内存,有时甚至会致使swap的使用(并不肯定是否是修改 net_write_timeout所至)。
    建议在mysqldump以前修改net_write_timeout为一个较大的值(如1800),在 mysqldump结束后,
    在将这个值修改到默认的60。
    
  • 解决方法

    在sql命令行里面设置临时全局生效用相似以下命令:
    SET GLOBAL net_write_timeout=1800;
    

10.3 缘由2

  • 缘由
    因为MySQL没法解析ip地址,而报出的错误:
  • 解决方法
    在参数配置文件(默认为/etc/my.cnf) 中[mysqld] 下添加 skip-name-resove . 重启 MySQL便可。

Author: halberd

Created: 2019-08-04 Sun 05:07

Validate

相关文章
相关标签/搜索