MySQL常见错误收集

MySQL常见错误收集

[TOC]

避免笛卡尔积

mysql的utf8和utf8mb4的区别

记住,永远不要在MySQL中使用“utf8”
最近我遇到了一个bug,我试着通过Rails在以“utf8”编码的MariaDB中保存一个UTF-8字符串,然后出现了一个离奇的错误:

Incorrect string value: ‘\xF0\x9F\x98\x83 <…’ for column ‘summary’ at row 1

我用的是UTF-8编码的客户端,服务器也是UTF-8编码的,数据库也是,就连要保存的这个字符串“ <…”也是合法的UTF-8。


问题的症结在于,MySQL的“utf8”实际上不是真正的UTF-8。

“utf8”只支持每个字符最多三个字节,而真正的UTF-8是每个字符最多四个字节。

MySQL一直没有修复这个bug,他们在2010年发布了一个叫作“utf8mb4”的字符集,绕过了这个问题。

当然,他们并没有对新的字符集广而告之(可能是因为这个bug让他们觉得很尴尬),以致于现在网络上仍然在建议开发者使用“utf8”,但这些建议都是错误的。

简单概括如下:
MySQL的“utf8mb4”是真正的“UTF-8”。
MySQL的“utf8”是一种“专属的编码”,它能够编码的Unicode字符并不多。
我要在这里澄清一下:所有在使用“utf8”的MySQL和MariaDB用户都应该改用“utf8mb4”,永远都不要再使用“utf8”。

那么什么是编码?什么是UTF-8?

我们都知道,计算机使用0和1来存储文本。比如字符“C”被存成“01000011”,那么计算机在显示这个字符时需要经过两个步骤:
计算机读取“01000011”,得到数字67,因为67被编码成“01000011”。
计算机在Unicode字符集中查找67,找到了“C”。
同样的:
我的电脑将“C”映射成Unicode字符集中的67。
我的电脑将67编码成“01000011”,并发送给Web服务器。
几乎所有的网络应用都使用了Unicode字符集,因为没有理由使用其他字符集。

Unicode字符集包含了上百万个字符。最简单的编码是UTF-32,每个字符使用32位。这样做最简单,因为一直以来,计算机将32位视为数字,而计算机最在行的就是处理数字。但问题是,这样太浪费空间了。

UTF-8可以节省空间,在UTF-8中,字符“C”只需要8位,一些不常用的字符,比如“”需要32位。其他的字符可能使用16位或24位。一篇类似本文这样的文章,如果使用UTF-8编码,占用的空间只有UTF-32的四分之一左右。

MySQL的“utf8”字符集与其他程序不兼容,它所谓的“”,可能真的是一坨……

MySQL简史

为什么MySQL开发者会让“utf8”失效?我们或许可以从提交日志中寻找答案。

MySQL从4.1版本开始支持UTF-8,也就是2003年,而今天使用的UTF-8标准(RFC 3629)是随后才出现的。

旧版的UTF-8标准(RFC 2279)最多支持每个字符6个字节。2002年3月28日,MySQL开发者在第一个MySQL 4.1预览版中使用了RFC 2279。

同年9月,他们对MySQL源代码进行了一次调整:“UTF8现在最多只支持3个字节的序列”。

是谁提交了这些代码?他为什么要这样做?这个问题不得而知。在迁移到Git后(MySQL最开始使用的是BitKeeper),MySQL代码库中的很多提交者的名字都丢失了。2003年9月的邮件列表中也找不到可以解释这一变更的线索。

不过我可以试着猜测一下。

2002年,MySQL做出了一个决定:如果用户可以保证数据表的每一行都使用相同的字节数,那么MySQL就可以在性能方面来一个大提升。为此,用户需要将文本列定义为“CHAR”,每个“CHAR”列总是拥有相同数量的字符。如果插入的字符少于定义的数量,MySQL就会在后面填充空格,如果插入的字符超过了定义的数量,后面超出部分会被截断。

MySQL开发者在最开始尝试UTF-8时使用了每个字符6个字节,CHAR(1)使用6个字节,CHAR(2)使用12个字节,并以此类推。

应该说,他们最初的行为才是正确的,可惜这一版本一直没有发布。但是文档上却这么写了,而且广为流传,所有了解UTF-8的人都认同文档里写的东西。

不过很显然,MySQL开发者或厂商担心会有用户做这两件事:
使用CHAR定义列(在现在看来,CHAR已经是老古董了,但在那时,在MySQL中使用CHAR会更快,不过从2005年以后就不是这样子了)。
将CHAR列的编码设置为“utf8”。
我的猜测是MySQL开发者本来想帮助那些希望在空间和速度上双赢的用户,但他们搞砸了“utf8”编码。

所以结果就是没有赢家。那些希望在空间和速度上双赢的用户,当他们在使用“utf8”的CHAR列时,实际上使用的空间比预期的更大,速度也比预期的慢。而想要正确性的用户,当他们使用“utf8”编码时,却无法保存像“”这样的字符。

在这个不合法的字符集发布了之后,MySQL就无法修复它,因为这样需要要求所有用户重新构建他们的数据库。最终,MySQL在2010年重新发布了“utf8mb4”来支持真正的UTF-8。

为什么这件事情会让人如此抓狂

因为这个问题,我整整抓狂了一个礼拜。我被“utf8”愚弄了,花了很多时间才找到这个bug。但我一定不是唯一的一个,网络上几乎所有的文章都把“utf8”当成是真正的UTF-8。

“utf8”只能算是个专有的字符集,它给我们带来了新问题,却一直没有得到解决。

总结

如果你在使用MySQL或MariaDB,不要用“utf8”编码,改用“utf8mb4”。这里(https://mathiasbynens.be/notes/mysql-utf8mb4#utf8-to-utf8mb4)提供了一个指南用于将现有数据库的字符编码从“utf8”转成“utf8mb4”。

英文原文:https://medium.com/@adamhooper/in-mysql-never-use-utf8-use-utf8mb4-11761243e434

写入MySQL报错超出 max_allowed_packet 的问题

MySQL会根据配置文件会限制server接受的数据包的大小。如果写入大数据时,因为默认的配置太小,插入和更新操作会因为 max_allowed_packet 参数限制,而导致失败。

MySQL查询得到的结果, 单位为字节数.

查看当前配置:

mysql> show variables like 'max_allowed_packet';
+--------------------+---------+
| Variable_name      | Value   |
+--------------------+---------+
| max_allowed_packet | 4194304 |
+--------------------+---------+
1 row in set (0.19 sec)

也可以用select查看:

mysql> select @@max_allowed_packet;
+----------------------+
| @@max_allowed_packet |
+----------------------+
|              4194304 |
+----------------------+
1 row in set (0.06 sec)

max_allowed_packet 如果不设置,默认值在不同的 MySQL 版本表现不同,有的版本默认1M,有的版本默认4M。

临时修改

set global max_allowed_packet = 100 * 1024 * 1024;

修改配置文件(永久修改)

vim /etc/my.cnf
[mysqld]
max_allowed_packet = 100M

注意:

  1. 命令行修改时,不能用M、G,只能这算成字节数设置。配置文件修改才允许设置M、G单位。
  2. 命令行修改之后,需要退出当前回话(关闭当前mysql server链接),然后重新登录才能查看修改后的值。通过命令行修改只能临时生效,下次数据库重启后又复原了。
  3. max_allowed_packet 最大值是1G(1073741824),如果设置超过1G,查看最终生效结果也只有1G。

The talbe 'XXX' is full

这种情况一般就是磁盘爆满导致MySQL无法写入, 这时候去查看MySQL日志也会发现(以我这个导数据为例) 这里也会提示空间不足之类的.

InnoDB: Error number 0 means 'Success'.
InnoDB: Some operating system error numbers are described at
InnoDB: http://dev.mysql.com/doc/refman/5.6/en/operating-system-error-codes.html
2018-10-11 16:41:45 1516 [ERROR] /usr/sbin/mysqld: The table 'user_info' is full
2018-10-11 16:42:43 1516 [ERROR] /usr/sbin/mysqld: The table 'user_info' is full
2018-10-11 16:45:30 7f71164977002018-10-11 16:45:30 1516 [ERROR] InnoDB: Failure of system call pwrite(). Operating system error number is 28.
InnoDB: Error number 28 means 'No space left on device'.
InnoDB: Some operating system error numbers are described at
InnoDB: http://dev.mysql.com/doc/refman/5.6/en/operating-system-error-codes.html
2018-10-11 16:45:30 1516 [ERROR] /usr/sbin/mysqld: The table 'user_info' is full

我遇到的一般就是磁盘爆满

  1. 一般就是这种, 磁盘爆满. 解决方案就是删除没用的东西, 虚拟机的话重启是最好的选择. 使用df -h命令查看,发现/根目录的剩余空间为0 使用du -h -x --max-depth=1 查看哪个目录占用过高,对于过高目录中的内容适当删减腾出一些空间

  2. 还有一种情况就是 该表的主键超出了最大的ID

  3. 或者按照官方所说的您正在使用内存(堆)存储引擎;在这种情况下,需要增加max_heap_table_size系统变量的值。参见5.1.3节“服务器系统变量”。 如果是MEMORY引擎

    1、适当提高 max_heap_table_size 设置(注意该值是会话级别,不要设置过大,例如1GB,一般不建议超过256MB);

    2、执行ALTER TABLE t_mem ENGINE=MEMORY; 重整表空间, 否则无法写入新数据 ;

    3、删除部分历史数据或者直接清空,重整表空间;

    4、设置 big_tables = 1 ,将所有临时表存储在磁盘,而非内存中,缺点是如果某个SQL执行时需要用到临时表,则性能会差很多

    于是就修改Mysql的配置文件my.ini,在[mysqld]下添加/修改两行: tmp_table_size = 256M max_heap_table_size = 256M

系统默认是16M,修改完后重启mysql


Mysql5.7中写入数据或者查询数据时产生

  • Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'kgt_com.order_kgtc.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

  • 确认问题所在:

    select @@sql_mode
    查看结果是否含有ONLY_FULL_GROUP_BY; 该设置为检测SQL语句是否遵守SQL92标准.
    
    SELECT列表中的任何非聚合字段都必须包括在GROUP BY表达式中。这条定律遵守SQL92标准,而且是很安全的假设——非聚合列可以有多个值,因此如果不进行分组,数据库引擎在判断取哪个值的时候就会有困难。 
    

    语句例子1:

        在make.php Kline 产生的语句中:
        SELECT min(price) pmin, max(price) pmax, sum(num) number, min(id) idmin, max(id) idmax, FROM_UNIXTIME(created,'%Y-%m-%d %H:00') dt FROM order_kgtc WHERE created>1486656985 GROUP BY dt ORDER BY idmin ASC
    报出该错误, 将语句修改为以下语句,修复错误:
        SELECT min(price) pmin, max(price) pmax, sum(num) number, min(id) idmin, max(id) idmax, FROM_UNIXTIME(created,'%Y-%m-%d %H:00') dt FROM order_kgtc WHERE created>1486656109 GROUP BY FROM_UNIXTIME(created,'%Y-%m-%d %H:00') ORDER BY idmin ASC
    
    语句例子2:
    select id,price,num_over from trade_kgtc where type='buy' group by price order by price desc;
    报出该错误错, 将语句修改为以下语句, 修复错误问题.
    select count(id),price,sum(num_over) from trade_kgtc where type='buy' group by price order by price desc;
    
  • 也可以通过取消安全验证, 来避免该问题 :

    永久修复: 
    在my.cnf 里面设置
    sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
    在sql_mode 中去掉only_full_group_by 
    
    临时修复:
        SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''))
        将ONLY_FULL_GROUP_BY调换为空;
    

ONLY_FULL_GROUP_BY设置的意义

ONLY_FULL_GROUP_BY是mysql提供的一个sql_mode,通过这个, 可以进行SQL语句合法性的检测; 在mysql的sql_mode=default的情况下是非ONLY_FULL_GROUP_BY语义,也就是说一条select语句,mysql允许target list中输出的表达式是除聚集函数,group by column以外的表达式,这个表达式的值可能在经过group by操作后变成undefined,无法确定(实际上mysql的表现是分组内第一行对应列的值); 
而对于语义限制都比较严谨的多家数据库,如SQLServer、Oracle、PostgreSql都不支持select target list中出现语义不明确的列,这样的语句在这些数据库中是会被报错的,所以mysql在后续的版本中出了一个修正语义,就是我们所说的ONLY_FULL_GROUP_BY语义;

对于GROUP BY聚合操作,如果在SELECT中的列,没有在GROUP BY中出现,那么这个SQL是不合法的,因为列不在GROUP BY从句中
所以对于设置了这个mode的数据库,在使用group by 的时候,就要用MAX(),SUM(),ANT_VALUE()这种聚合函数,才能完成GROUP BY 的聚合操作.

其他的一些mode含义:

STRICT_TRANS_TABLES:
在该模式下,如果一个值不能插入到一个事务表中,则中断当前的操作,对非事务表不做限制
NO_ZERO_IN_DATE:
在严格模式下,不允许日期和月份为零
NO_ZERO_DATE:
设置该值,MySQL数据库不允许插入零日期,插入零日期会抛出错误而不是警告。
ERROR_FOR_DIVISION_BY_ZERO:
在INSERT或UPDATE过程中,如果数据被零除,则产生错误而非警告。如 果未给出该模式,那么数据被零除时MySQL返回NULL
NO_AUTO_CREATE_USER:
禁止GRANT创建密码为空的用户
NO_ENGINE_SUBSTITUTION:
如果需要的存储引擎被禁用或未编译,那么抛出错误。不设置此值时,用默认的存储引擎替代,并抛出一个异常
PIPES_AS_CONCAT:
将"||"视为字符串的连接操作符而非或运算符,这和Oracle数据库是一样的,也和字符串的拼接函数Concat相类似
ANSI_QUOTES:
启用ANSI_QUOTES后,不能用双引号来引用字符串,因为它被解释为识别符
NO_AUTO_VALUE_ON_ZERO:
该值影响自增长列的插入。默认设置下,插入0或NULL代表生成下一个自增长值。如果用户 希望插入的值为0,而该列又是自增长的,那么这个选项就有用了。

在使用Host,User,Password来测试数据库连接的时候,报这样的错误:

 Connection failed: Could not connect to the DB: Access denied for user 'root'@'localhost' (using password: NO)
 
或者是明明设置了用户名和密码,却能无密码登陆,有密码反而登陆不了
原因:user表中有一条数据是Host='localhost',但是密码和用户名都为空,而数据库在user表中读取权限时,优先匹配最能确定具体主机的纪录,由于'%'匹配所有主机,所以localhost优先于'%',所以即使你创建了用户名和密码,在dos中直接连接mysql,相当于Host就是localhost,所以会优先去读取localhost这一条记录,然后进行无密码登录

解决方法:delete from user where Host='localhost' and User='';

MySQL编译错误

https://segmentfault.com/a/1190000012099346

cmake 错误0:

    [root@localhost mysql-5.7.19]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
    > -DSYSCONFDIR=/etc \
    > -DMYSQL_TCP_PORT=3306 \
    > -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
    > -DEFAULT_CHARSET=utf8 \
    > -DMYSQL_DATADIR=/usr/local/mysql/data \
    > -DENABLED_LOCAL_INFILE=1 \
    > -DEXTRA_CHARSETS=all \
    > -DDEFAULT_COLLATION=utf8_general_ci \
    > -DDOWNLOAD_BOOST=1 \
    > -DWITH_BOOST=/usr/local/src/boost_1_59_0
    -- Running cmake version 2.8.11
    -- Could NOT find Git (missing: GIT_EXECUTABLE)
    -- Configuring with MAX_INDEXES = 64U
    -- The C compiler identification is unknown
    -- The CXX compiler identification is unknown
    CMake Error: your C compiler: "CMAKE_C_COMPILER-NOTFOUND" was not found. Please set CMAKE_C_COMPILER to a valid compiler path or name.
    CMake Error: your CXX compiler: "CMAKE_CXX_COMPILER-NOTFOUND" was not found. Please set CMAKE_CXX_COMPILER to a valid compiler path or
    name.
    -- CMAKE_GENERATOR: Unix Makefiles
    CMake Error at cmake/os/Linux.cmake:41 (MESSAGE):
    Unsupported compiler!
    Call Stack (most recent call first):
    CMakeLists.txt:169 (INCLUDE)
    -- Configuring incomplete, errors occurred!
    [root@localhost mysql-5.7.19]# gcc
    bash: gcc: 未找到命令...                    
    **报错原因:没安装gcc**      

cmake 报错1:

    [root@CentOS73-1 mysql-5.7.19]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc -DMYSQL_TCP_PORT=3306 -DMYSQL_UNIX_ADDR=/
    var/lib/mysql/mysql.sock -DEFAULT_CHA
    RSET=utf8 -DMYSQL_DATADIR=/usr/local/mysql/data -DENABLED_LOCAL_INFILE=1 -DEXTRA_CHARSETS=all -DDEFAULT_COLLATION=utf8_general_ci -
    DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/loca
    l/src/boost_1_59_0
    -- Running cmake version 2.8.12.2
    -- Could NOT find Git (missing: GIT_EXECUTABLE)
    -- Configuring with MAX_INDEXES = 64U
    -- The CXX compiler identification is unknown
    CMake Error: your CXX compiler: "CMAKE_CXX_COMPILER-NOTFOUND" was not found. Please set CMAKE_CXX_COMPILER to a valid compiler path or
    name.
    -- CMAKE_GENERATOR: Unix Makefiles
    -- SIZEOF_VOIDP 8
    -- MySQL 5.7.19
    -- Packaging as: mysql-5.7.19-Linux-x86_64
    -- Local boost dir /usr/local/src/boost_1_59_0
    -- Found /usr/local/src/boost_1_59_0/boost/version.hpp
    -- BOOST_VERSION_NUMBER is #define BOOST_VERSION 105900
    -- BOOST_INCLUDE_DIR /usr/local/src/boost_1_59_0
    -- NUMA library missing or required version not available
    -- Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH)
    CMake Error at cmake/readline.cmake:64 (MESSAGE):
    Curses library not found. Please install appropriate package,
    remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncursesdevel.
    Call Stack (most recent call first):
    cmake/readline.cmake:107 (FIND_CURSES)
    cmake/readline.cmake:197 (MYSQL_USE_BUNDLED_EDITLINE)
    CMakeLists.txt:519 (MYSQL_CHECK_EDITLINE)
    -- Configuring incomplete, errors occurred!
    See also "/usr/local/src/mysql-5.7.19/CMakeFiles/CMakeOutput.log".
    See also "/usr/local/src/mysql-5.7.19/CMakeFiles/CMakeError.log".
       **报错原因:没安装 ncurses-devel**  

cmake报错2:

       CMake Error: Internal CMake error, TryCompile configure of cmake failed
    -- Performing Test HAVE_NO_BUILTIN_MEMCMP - Failed
    CMake Warning at cmake/bison.cmake:20 (MESSAGE):
    Bison executable not found in PATH
    Call Stack (most recent call first):
    sql/CMakeLists.txt:548 (INCLUDE)
    CMake Warning at cmake/bison.cmake:20 (MESSAGE):
    Bison executable not found in PATH
    Call Stack (most recent call first):
    libmysqld/CMakeLists.txt:187 (INCLUDE)
    -- Library mysqlserver depends on OSLIBS -lpthread;m;rt;crypt;dl
    -- INSTALL mysqlclient.pc lib/pkgconfig
    -- Skipping deb packaging on unsupported platform .
    -- CMAKE_BUILD_TYPE: RelWithDebInfo
    -- COMPILE_DEFINITIONS: _GNU_SOURCE;_FILE_OFFSET_BITS=64;HAVE_CONFIG_H;HAVE_LIBEVENT1
    -- CMAKE_C_FLAGS: -Wall -Wextra -Wformat-security -Wvla -Wwrite-strings -Wdeclaration-after-statement
    -- CMAKE_CXX_FLAGS:
    -- CMAKE_C_LINK_FLAGS:
    -- CMAKE_CXX_LINK_FLAGS:
    -- CMAKE_C_FLAGS_RELWITHDEBINFO: -O3 -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -DDBUG_OFF
    -- CMAKE_CXX_FLAGS_RELWITHDEBINFO: -DDBUG_OFF
    -- Configuring incomplete, errors occurred!
    See also "/usr/local/src/mysql-5.7.19/CMakeFiles/CMakeOutput.log".
    See also "/usr/local/src/mysql-5.7.19/CMakeFiles/CMakeError.log".
    报错原因:没有安装gcc-c++           

make 出错 1:

    [root@CentOS73-1 mysql-5.7.19]# make -j4
    [ 0%] Built target zlib
    [ 0%] Built target INFO_BIN
    [ 0%] Built target INFO_SRC
    [ 1%] Built target yassl
    [ 3%] Built target taocrypt
    [ 5%] Built target edit
    [ 7%] Built target strings
    [ 8%] Built target mysqlservices
    Linking C static library liblz4_lib.a
    [ 8%] Built target gen_lex_hash
    [ 8%] Built target vio
    [ 8%] [ 9%] Built target lz4_lib
    Built target regex
    [ 9%] Built target comp_sql
    [ 9%] Built target abi_check
   [ 9%] [ 10%] [ 10%] Building CXX object rapid/plugin/group_replication/CMakeFiles/gr_unit_test_resource.dir/src/member_info.cc.o 
    Built target event
    Scanning dependencies of target protobuf-lite
    Built target GenLiteProtos
    Scanning dependencies of target protobuf
    Scanning dependencies of target protoclib
    [ 10%] Building CXX object extra/protobuf/CMakeFiles/protobuf-lite.dir/protobuf-2.6.1/src/google/protobuf/stubs/
    atomicops_internals_x86_gcc.cc.o
    In file included from /usr/local/src/mysql-5.7.19/rapid/plugin/group_replication/include/plugin_server_include.h:38:0,
    from /usr/local/src/mysql-5.7.19/rapid/plugin/group_replication/include/plugin_psi.h:19,
    from /usr/local/src/mysql-5.7.19/rapid/plugin/group_replication/src/member_info.cc:17:
    /usr/local/src/mysql-5.7.19/include/my_atomic.h:64:4: error: #error Native atomics support not found!
    # error Native atomics support not found!
    ^
    [ 10%] Building CXX object extra/protobuf/CMakeFiles/protoclib.dir/protobuf-2.6.1/src/google/protobuf/compiler/code_generator.cc.o
    [ 10%] Building CXX object extra/protobuf/CMakeFiles/protobuf.dir/protobuf-2.6.1/src/google/protobuf/stubs/strutil.cc.o
    [ 10%] Building CXX object extra/protobuf/CMakeFiles/protobuf-lite.dir/protobuf-2.6.1/src/google/protobuf/stubs/
    atomicops_internals_x86_msvc.cc.o
    make[2]: *** [rapid/plugin/group_replication/CMakeFiles/gr_unit_test_resource.dir/src/member_info.cc.o] Error 1
    make[1]: *** [rapid/plugin/group_replication/CMakeFiles/gr_unit_test_resource.dir/all] Error 2
    make[1]: *** Waiting for unfinished jobs....
    [ 10%] Building CXX object extra/protobuf/CMakeFiles/protobuf-lite.dir/protobuf-2.6.1/src/google/protobuf/stubs/common.cc.o
    [ 11%] Building CXX object extra/protobuf/CMakeFiles/protobuf-lite.dir/protobuf-2.6.1/src/google/protobuf/stubs/once.cc.o
    [ 11%] [ 11%] Building CXX object extra/protobuf/CMakeFiles/protobuf-lite.dir/protobuf-2.6.1/src/google/protobuf/stubs/stringprintf.cc.o
    Building CXX object extra/protobuf/CMakeFiles/protoclib.dir/protobuf-2.6.1/src/google/protobuf/compiler/command_line_interface.cc.o
    [ 11%] Building CXX object extra/protobuf/CMakeFiles/protobuf-lite.dir/protobuf-2.6.1/src/google/protobuf/extension_set.cc.o
    [ 11%] Building CXX object extra/protobuf/CMakeFiles/protobuf-lite.dir/protobuf-2.6.1/src/google/protobuf/generated_message_util.cc.o
    [ 11%] [ 11%] Building CXX object extra/protobuf/CMakeFiles/protobuf.dir/protobuf-2.6.1/src/google/protobuf/stubs/substitute.cc.o
    Building CXX object extra/protobuf/CMakeFiles/protobuf-lite.dir/protobuf-2.6.1/src/google/protobuf/message_lite.cc.o
    [ 11%] Building CXX object extra/protobuf/CMakeFiles/protobuf.dir/protobuf-2.6.1/src/google/protobuf/stubs/structurally_valid.cc.o
    [ 11%] Building CXX object extra/protobuf/CMakeFiles/protobuf-lite.dir/protobuf-2.6.1/src/google/protobuf/repeated_field.cc.o
    [ 11%] Building CXX object extra/protobuf/CMakeFiles/protobuf.dir/protobuf-2.6.1/src/google/protobuf/descriptor.cc.o
    [ 11%] Building CXX object extra/protobuf/CMakeFiles/protobuf-lite.dir/protobuf-2.6.1/src/google/protobuf/wire_format_lite.cc.o
    [ 11%] Building CXX object extra/protobuf/CMakeFiles/protobuf-lite.dir/protobuf-2.6.1/src/google/protobuf/io/coded_stream.cc.o
    [ 11%] Building CXX object extra/protobuf/CMakeFiles/protobuf-lite.dir/protobuf-2.6.1/src/google/protobuf/io/zero_copy_stream.cc.o
    [ 11%] Building CXX object extra/protobuf/CMakeFiles/protobuf-lite.dir/protobuf-2.6.1/src/google/protobuf/io/zero_copy_stream_impl_lite.cc.o
    [ 11%] Building CXX object extra/protobuf/CMakeFiles/protobuf.dir/protobuf-2.6.1/src/google/protobuf/descriptor.pb.cc.o
    Linking CXX static library libprotobuf-lite.a
    [ 11%] Built target protobuf-lite
    [ 11%] Building CXX object extra/protobuf/CMakeFiles/protobuf.dir/protobuf-2.6.1/src/google/protobuf/descriptor_database.cc.o
    [ 11%] Building CXX object extra/protobuf/CMakeFiles/protoclib.dir/protobuf-2.6.1/src/google/protobuf/compiler/plugin.cc.o
    [ 11%] Building CXX object extra/protobuf/CMakeFiles/protoclib.dir/protobuf-2.6.1/src/google/protobuf/compiler/plugin.pb.cc.o
    [ 11%] Building CXX object extra/protobuf/CMakeFiles/protobuf.dir/protobuf-2.6.1/src/google/protobuf/dynamic_message.cc.o
    [ 11%] Building CXX object extra/protobuf/CMakeFiles/protoclib.dir/protobuf-2.6.1/src/google/protobuf/compiler/subprocess.cc.o
    [ 11%] Building CXX object extra/protobuf/CMakeFiles/protoclib.dir/protobuf-2.6.1/src/google/protobuf/compiler/zip_writer.cc.o
    [ 11%] Building CXX object extra/protobuf/CMakeFiles/protobuf.dir/protobuf-2.6.1/src/google/protobuf/extension_set_heavy.cc.o
    [ 11%] Building CXX object extra/protobuf/CMakeFiles/protoclib.dir/protobuf-2.6.1/src/google/protobuf/compiler/cpp/cpp_enum.cc.o
    [ 11%] Building CXX object extra/protobuf/CMakeFiles/protobuf.dir/protobuf-2.6.1/src/google/protobuf/generated_message_reflection.cc.o
    [ 11%] Building CXX object extra/protobuf/CMakeFiles/protoclib.dir/protobuf-2.6.1/src/google/protobuf/compiler/cpp/cpp_enum_field.cc.o
    [ 11%] Building CXX object extra/protobuf/CMakeFiles/protobuf.dir/protobuf-2.6.1/src/google/protobuf/message.cc.o
    [ 12%] Building CXX object extra/protobuf/CMakeFiles/protoclib.dir/protobuf-2.6.1/src/google/protobuf/compiler/cpp/cpp_extension.cc.o
      [ 12%] Building CXX object extra/protobuf/CMakeFiles/protobuf.dir/protobuf-2.6.1/src/google/protobuf/reflection_ops.cc.o
      [ 12%] Building CXX object extra/protobuf/CMakeFiles/protobuf.dir/protobuf-2.6.1/src/google/protobuf/service.cc.o
        [ 12%] Building CXX object extra/protobuf/CMakeFiles/protobuf.dir/protobuf-2.6.1/src/google/protobuf/text_format.cc.o 
         [ 12%] Building CXX object extra/protobuf/CMakeFiles/protobuf.dir/protobuf-2.6.1/src/google/protobuf/unknown_field_set.cc.o
    [ 12%] Building CXX object extra/protobuf/CMakeFiles/protobuf.dir/protobuf-2.6.1/src/google/protobuf/wire_format.cc.o
    [ 12%] Building CXX object extra/protobuf/CMakeFiles/protobuf.dir/protobuf-2.6.1/src/google/protobuf/io/gzip_stream.cc.o
    [ 12%] Building CXX object extra/protobuf/CMakeFiles/protoclib.dir/protobuf-2.6.1/src/google/protobuf/compiler/cpp/cpp_field.cc.o
    [ 12%] Building CXX object extra/protobuf/CMakeFiles/protobuf.dir/protobuf-2.6.1/src/google/protobuf/io/printer.cc.o
    [ 12%] Building CXX object extra/protobuf/CMakeFiles/protobuf.dir/protobuf-2.6.1/src/google/protobuf/io/strtod.cc.o
    [ 13%] Building CXX object extra/protobuf/CMakeFiles/protobuf.dir/protobuf-2.6.1/src/google/protobuf/io/tokenizer.cc.o
    [ 13%] Building CXX object extra/protobuf/CMakeFiles/protobuf.dir/protobuf-2.6.1/src/google/protobuf/io/zero_copy_stream_impl.cc.o
    [ 13%] Building CXX object extra/protobuf/CMakeFiles/protoclib.dir/protobuf-2.6.1/src/google/protobuf/compiler/cpp/cpp_file.cc.o
    [ 13%] Building CXX object extra/protobuf/CMakeFiles/protobuf.dir/protobuf-2.6.1/src/google/protobuf/compiler/importer.cc.o
    [ 13%] Building CXX object extra/protobuf/CMakeFiles/protobuf.dir/protobuf-2.6.1/src/google/protobuf/compiler/parser.cc.o
    [ 13%] Building CXX object extra/protobuf/CMakeFiles/protoclib.dir/protobuf-2.6.1/src/google/protobuf/compiler/cpp/cpp_generator.cc.o
    [ 13%] Building CXX object extra/protobuf/CMakeFiles/protobuf.dir/protobuf-2.6.1/src/google/protobuf/stubs/atomicops_internals_x86_gcc.cc.o
    [ 13%] Building CXX object extra/protobuf/CMakeFiles/protobuf.dir/protobuf-2.6.1/src/google/protobuf/stubs/atomicops_internals_x86_msvc.cc.o
    [ 13%] Building CXX object extra/protobuf/CMakeFiles/protobuf.dir/protobuf-2.6.1/src/google/protobuf/stubs/common.cc.o
    [ 13%] Building CXX object extra/protobuf/CMakeFiles/protobuf.dir/protobuf-2.6.1/src/google/protobuf/stubs/once.cc.o
    [ 13%] Building CXX object extra/protobuf/CMakeFiles/protoclib.dir/protobuf-2.6.1/src/google/protobuf/compiler/cpp/cpp_helpers.cc.o
    [ 13%] Building CXX object extra/protobuf/CMakeFiles/protobuf.dir/protobuf-2.6.1/src/google/protobuf/stubs/stringprintf.cc.o
    [ 13%] [ 13%] Building CXX object extra/protobuf/CMakeFiles/protoclib.dir/protobuf-2.6.1/src/google/protobuf/compiler/cpp/cpp_message.cc.o
    Building CXX object extra/protobuf/CMakeFiles/protobuf.dir/protobuf-2.6.1/src/google/protobuf/extension_set.cc.o
    [ 13%] Building CXX object extra/protobuf/CMakeFiles/protobuf.dir/protobuf-2.6.1/src/google/protobuf/generated_message_util.cc.o
    [ 13%] Building CXX object extra/protobuf/CMakeFiles/protobuf.dir/protobuf-2.6.1/src/google/protobuf/message_lite.cc.o
    [ 13%] Building CXX object extra/protobuf/CMakeFiles/protoclib.dir/protobuf-2.6.1/src/google/protobuf/compiler/cpp/cpp_message_field.cc.o
    [ 13%] Building CXX object extra/protobuf/CMakeFiles/protobuf.dir/protobuf-2.6.1/src/google/protobuf/repeated_field.cc.o
    [ 13%] Building CXX object extra/protobuf/CMakeFiles/protobuf.dir/protobuf-2.6.1/src/google/protobuf/wire_format_lite.cc.o
    [ 13%] Building CXX object extra/protobuf/CMakeFiles/protoclib.dir/protobuf-2.6.1/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc.o
    [ 13%] Building CXX object extra/protobuf/CMakeFiles/protobuf.dir/protobuf-2.6.1/src/google/protobuf/io/coded_stream.cc.o
    [ 13%] Building CXX object extra/protobuf/CMakeFiles/protobuf.dir/protobuf-2.6.1/src/google/protobuf/io/zero_copy_stream.cc.o
    [ 13%] Building CXX object extra/protobuf/CMakeFiles/protobuf.dir/protobuf-2.6.1/src/google/protobuf/io/zero_copy_stream_impl_lite.cc.o
    [ 13%] Building CXX object extra/protobuf/CMakeFiles/protoclib.dir/protobuf-2.6.1/src/google/protobuf/compiler/cpp/cpp_service.cc.o
    Linking CXX static library libprotobuf.a
    [ 13%] Built target protobuf
    [ 13%] Building CXX object extra/protobuf/CMakeFiles/protoclib.dir/protobuf-2.6.1/src/google/protobuf/compiler/cpp/cpp_string_field.cc.o
    [ 13%] Building CXX object extra/protobuf/CMakeFiles/protoclib.dir/protobuf-2.6.1/src/google/protobuf/compiler/java/java_context.cc.o
    [ 13%] Building CXX object extra/protobuf/CMakeFiles/protoclib.dir/protobuf-2.6.1/src/google/protobuf/compiler/java/java_enum.cc.o
    [ 13%] Building CXX object extra/protobuf/CMakeFiles/protoclib.dir/protobuf-2.6.1/src/google/protobuf/compiler/java/java_enum_field.cc.o
    [ 13%] Building CXX object extra/protobuf/CMakeFiles/protoclib.dir/protobuf-2.6.1/src/google/protobuf/compiler/java/java_extension.cc.o
    [ 13%] Building CXX object extra/protobuf/CMakeFiles/protoclib.dir/protobuf-2.6.1/src/google/protobuf/compiler/java/java_field.cc.o
    [ 13%] Building CXX object extra/protobuf/CMakeFiles/protoclib.dir/protobuf-2.6.1/src/google/protobuf/compiler/java/java_file.cc.o
    [ 13%] Building CXX object extra/protobuf/CMakeFiles/protoclib.dir/protobuf-2.6.1/src/google/protobuf/compiler/java/java_generator.cc.o
    [ 13%] Building CXX object extra/protobuf/CMakeFiles/protoclib.dir/protobuf-2.6.1/src/google/protobuf/compiler/java/
    java_generator_factory.cc.o
    [ 13%] Building CXX object extra/protobuf/CMakeFiles/protoclib.dir/protobuf-2.6.1/src/google/protobuf/compiler/java/java_helpers.cc.o
    [ 13%] Building CXX object extra/protobuf/CMakeFiles/protoclib.dir/protobuf-2.6.1/src/google/protobuf/compiler/java/
    java_lazy_message_field.cc.o
    [ 14%] Building CXX object extra/protobuf/CMakeFiles/protoclib.dir/protobuf-2.6.1/src/google/protobuf/compiler/java/java_message.cc.o
    [ 14%] Building CXX object extra/protobuf/CMakeFiles/protoclib.dir/protobuf-2.6.1/src/google/protobuf/compiler/java/java_message_field.cc.o
    [ 14%] Building CXX object extra/protobuf/CMakeFiles/protoclib.dir/protobuf-2.6.1/src/google/protobuf/compiler/java/java_name_resolver.cc.o
    [ 14%] Building CXX object extra/protobuf/CMakeFiles/protoclib.dir/protobuf-2.6.1/src/google/protobuf/compiler/java/
    java_primitive_field.cc.o
    [ 14%] Building CXX object extra/protobuf/CMakeFiles/protoclib.dir/protobuf-2.6.1/src/google/protobuf/compiler/java/
    java_shared_code_generator.cc.o
    [ 14%] Building CXX object extra/protobuf/CMakeFiles/protoclib.dir/protobuf-2.6.1/src/google/protobuf/compiler/java/java_service.cc.o    
      [ 14%] Building CXX object extra/protobuf/CMakeFiles/protoclib.dir/protobuf-2.6.1/src/google/protobuf/compiler/java/java_string_field.cc.o
    [ 14%] Building CXX object extra/protobuf/CMakeFiles/protoclib.dir/protobuf-2.6.1/src/google/protobuf/compiler/java/java_doc_comment.cc.o
    [ 14%] Building CXX object extra/protobuf/CMakeFiles/protoclib.dir/protobuf-2.6.1/src/google/protobuf/compiler/python/python_generator.cc.o
    Linking CXX static library libprotoclib.a
    [ 14%] Built target protoclib
    make: *** [all] Error 2
    **报错原因:cmake 版本太低** 

编译安装 cmake :

    [root@CentOS73-1 cmake-3.9.1]# ./configure
    [root@CentOS73-1 cmake-3.9.1]# make
    [root@CentOS73-1 cmake-3.9.1]# make install
    [root@CentOS73-1 ~]# cd /usr/local/src/mysql-5.7.19/
    [root@CentOS73-1 mysql-5.7.19]# rm -rf CMakeCache.txt
    退出终端,重进
    重新 cmake , make ,make install
    cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
    -DSYSCONFDIR=/etc \
    -DMYSQL_TCP_PORT=3306 \
    -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
    -DDEFAULT_CHARSET=utf8 \
    -DMYSQL_DATADIR=/usr/local/mysql/data \
    -DENABLED_LOCAL_INFILE=1 \
    -DEXTRA_CHARSETS=all \
    -DDEFAULT_COLLATION=utf8_general_ci \
    -DWITH_BOOST=/usr/local/src/boost_1_59_0        

make 出错 2:

    [ 78%] Building CXX object rapid/plugin/x/CMakeFiles/mysqlx.dir/generated/protobuf_lite/mysqlx_resultset.pb.cc.o
    [ 78%] Building CXX object libmysqld/CMakeFiles/sql_embedded.dir/__/sql/item_geofunc_buffer.cc.o
    [ 78%] Building CXX object libmysqld/CMakeFiles/sql_embedded.dir/__/sql/item_geofunc_internal.cc.o
    [ 78%] Linking CXX shared module mysqlx.so
    [ 79%] Built target mysqlx
    [ 79%] Building CXX object libmysqld/CMakeFiles/sql_embedded.dir/__/sql/item_geofunc_relchecks.cc.o
    c++: internal compiler error: Killed (program cc1plus)
    Please submit a full bug report,
    with preprocessed source if appropriate.
    See <http://bugzilla.redhat.com/bugzilla> for instructions. 
    make[2]: *** [libmysqld/CMakeFiles/sql_embedded.dir/__/sql/item_geofunc.cc.o] Error 4
    make[2]: *** Waiting for unfinished jobs....
    make[1]: *** [libmysqld/CMakeFiles/sql_embedded.dir/all] Error 2
    make: *** [all] Error 2
    **错误原因:内存不不够 make -j4 启动 4 个gcc 进程耗费内存过⼤大**    

[实践发现]在编译mysql5.7.12时在编译⼀一半时出现错误,其实是邮于阿⾥里里vps内存不不⾜足所导致。

    背景:⽤用阿⾥里里云编译mysql5.7.12时在编译⼀一半时出现错误,如下:
    [ 50%] Building CXX object sql/CMakeFiles/sql.dir/item_cmpfunc.cc.o
    [ 50%] Building CXX object sql/CMakeFiles/sql.dir/item_create.cc.o
    [ 50%] Building CXX object sql/CMakeFiles/sql.dir/item_func.cc.o
    [ 50%] Building CXX object sql/CMakeFiles/sql.dir/item_geofunc.cc.o
    c++: 编译器器内部错误:已杀死(程序 cc1plus)
    Please submit a full bug report,
    with preprocessed source if appropriate.
    See <http://bugzilla.redhat.com/bugzilla> for instructions.
    make[2]: *** [sql/CMakeFiles/sql.dir/item_geofunc.cc.o] 错误 4
    make[1]: *** [sql/CMakeFiles/sql.dir/all] 错误 2
    make: *** [all] 错误 2
    不不要感觉奇怪,其实是内存不不够导致的,这位兄弟也遇到⼀一样的问题,如下:
    在这⾥里里特别提醒, 对于mysql5.7.8的make编译, 如果是阿⾥里里云centos主机512M内存的, 会在make编译到45%时会报错, 这是内存不不⾜足所致。
    c++: Internal error: Killed (program cc1plus)
    Please submit a full bug report.
    See <http://bugzilla.redhat.com/bugzilla> for instructions.
    make[2]: *** [sql/CMakeFiles/sql.dir/item_geofunc.cc.o] Error 1
    make[1]: *** [sql/CMakeFiles/sql.dir/all] Error 2
    make: *** [all] Error 2
    那么设置2G交换分区来⽤用下 :
    # dd if=/dev/zero of=/swapfile bs=1k count=2048000 --获取要增加的2G的SWAP⽂文件块
    # mkswap /swapfile -- 创建SWAP⽂文件
    # swapon /swapfile -- 激活SWAP⽂文件
    # swapon -s -- 查看SWAP信息是否正确
    # echo "/var/swapfile swap swap defaults 0 0" >> /etc/fstab -- 添加到fstab⽂文件中让系统引导时⾃自动启动
     注意, swapfile⽂文件的路路径在/var/下
    编译完后, 如果不不想要交换分区了了, 可以删除:
    # swapoff /swapfile
    # rm -fr /swapfile     

初始化报错 mysql_install_db 命令已经不不赞成使⽤用,需要使⽤用 mysqld 命令初始化数据库⽬目录

    [root@centos74-0 mysql-5.7.19]# ./bin/mysql_install_db --user=mysql
    2017-11-18 14:57:04 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
    2017-11-18 14:57:04 [ERROR] The data directory needs to be specified.

[root@centos74-0 mysql-5.7.19]# ./bin/mysqld --initialize

    2017-11-18T06:57:28.845607Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --
    explicit_defaults_for_timestamp server option (see documentation for more details).
    2017-11-18T06:57:29.129344Z 0 [Warning] InnoDB: New log files created, LSN=45790
    2017-11-18T06:57:29.203844Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
    2017-11-18T06:57:29.263076Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this
    server has been started. Generating a new UUID: be136ee3-cc2d-11e7-b4a7-001c42ebb70f.
    2017-11-18T06:57:29.264361Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
    2017-11-18T06:57:29.265114Z 1 [Note] A temporary password is generated for root@localhost: xkkJiMlmX3&s

[root@centos74-0 mysql-5.7.19]# ll -d data

drwxr-x--- 5 root root 147 Nov 18 14:57 data

[root@centos74-0 bin]# ./mysqld --initialize --user=mysql

    2017-11-18T07:20:37.761916Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --
    explicit_defaults_for_timestamp server option (see documentation for more details).
    2017-11-18T07:20:38.007055Z 0 [Warning] InnoDB: New log files created, LSN=45790
    2017-11-18T07:20:38.055215Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
    2017-11-18T07:20:38.112842Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this
    server has been started. Generating a new UUID: f9e51e81-cc30-11e7-b3f5-001c42ebb70f.
    2017-11-18T07:20:38.114500Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
    2017-11-18T07:20:38.115271Z 1 [Note] A temporary password is generated for root@localhost: I<XPKquuk0:u

[root@centos74-0 bin]# ./mysqld_safe --user=mysql

      Logging to '/usr/local/mysql-5.7.20/data/centos74-0.err'. 
      2017-11-18T07:21:14.070919Z mysqld_safe Starting mysqld daemon         
    with databases from /usr/local/mysql-5.7.20/data

[root@centos74-0 mysql-5.7.20]# ./bin/mysql -uroot -p'I<XPKquuk0:u'

    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 3
    Server version: 5.7.20
    Copyright (c) 2000, 2017, 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>      

如果数据⽬目录⾮非空,会认为数据库已存在,⽆无法初始化

    [root@localhost mysql]# ./bin/mysqld --initialize --user=mysql
    2017-11-18T07:25:50.083462Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp
    server option (see documentation for more details).
    2017-11-18T07:25:50.088292Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
    2017-11-18T07:25:50.088372Z 0 [ERROR] Aborting     
    

百度的未经测试/tmp/mysql.sock can't find

一、原因:

1、linux系统一次不正常关机后,连接mysql的时候系统提示不能通过/tmp/mysql.sock文件进行连接,或者非正确关闭时,导致mysql.sock文件再次丢失,当你在次启动时出现如下错误,connect mysqld faild ,/tmp/mysql.sock can't find

mysql.sock的丢失主要是因为更改了机器名,在没有正确关闭mysqld的情况下,去执行mysqld_safe,这样他就删除已经运行的mysql.sock了。正常情况下,mysqld_safe 应该告诉我们是已经有Mysqld运行了,而上边并没有这样提示,主要是更改机器名导致mysqld_safe判断是否已经运行,去找的是newhostname.pid文件,但已经运行的mysqld生成的是oldhostname.pid, 肯定找不到newhostname.pid,所以mysqld_safe收拾一下(清理了mysql.sock),然后去重启,但是ibdata需要lock,它lock不了,还是起不了,但是老的mysql.sock就消失。
2、连接localhost通常通过一个Unix域套接字文件进行,一般是/tmp/mysql.sock。如果套接字文件被删除了,本地客户就不能连接。这可能发生在你的系统运行一个cron任务删除了/tmp下的临时文件。
如果你因为丢失套接字文件而不能连接,你可以简单地通过重启服务器重新创建得到它。因为服务器在启动时重新创建它。

二、解决方法:

方法一:
mysql --port=3306 -uroot -p123qwe*** -S /var/lib/mysql/mysql.sock
方法二:
mysql --socket=/var/lib/mysql/mysql.sock --port=3306 -uroot -p123qwe***
方法三:
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
三、步骤:

我的startmysql.sh :

my.cnf位置:

里面都是关于启动Mysql的一些东西。

vi /etc/my.cnf

默认去连接的/var/lib/mysql/mysql.sock 这个文件。
而我们的启动配置文件在:--socket=/tmp/mysql.sock
两个配置文件:启动运行的时候是在/data0/mysql/3306/my.cnf 的mysql.sock在位置/tmp/mysql.sock,而/etc/my.cnf 的mysql.sock在位置/var/lib/mysql/mysql.sock 刚好和在终端运行mysql出现在错误相同:Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

my.cnf是mysql的启动配置文件。所以为了使改动生效必须重启mysql!

使用MySQL导出数据提示--secure-file-priv错误

  • 使用SQL
#导出文件
SELECT * FROM `TABLE_NAME` INTO OUTFILE 'FILE_PATH';
#导入文件
LOAD DATA INFILE 'FILE_PATH' INTO TABLE `TABLE_NAME`;
  • 报错信息
The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
  • 方法1. 把导入导出的文件存放到 secure-file-priv 路径下即可
  • 方法2 找到MySQL配置文件修改secure_file_priv的值

注意Variable 'secure_file_priv' is a read only variable该参数不能通过set XXX=XX 来修改.

通过SHOW VARIABLES LIKE "secure_file_priv";查看导入导出的目录限制.

如果value值为null,则为禁止,如果有文件夹目录,则只允许改目录下文件(测试子目录也不行),如果为空,则不限制目录;

修改配置可修改mysql配置文件[mysqld]中,查看是否有
secure_file_priv = 
这样一行内容,如果没有,则手动添加,
secure_file_priv = /home 
表示限制为/home文件夹
secure_file_priv = 
表示不限制目录,等号一定要有,否则mysql无法启动
修改完配置文件后,重启mysql生效
  • 更完善的SQL
#更详细的导出文件
SELECT * FROM MY_TABLE 
INTO OUTFILE 'FILE_PATH' 
FIELDS TERMINATED BY ','   
OPTIONALLY ENCLOSED BY '"'   
LINES TERMINATED BY '\n';
#更详细的导入文件 
LOAD DATA INFILE 'FILE_PATH' 
INTO TABLE MY_TABLE
FIELDS TERMINATED BY ','   
OPTIONALLY ENCLOSED BY '"'   
LINES TERMINATED BY '\n';
  • 解决导入导出csv中文乱码问题(亲测可行):将csv用txt打开,另存为,选择utf8编码即可

修改配置文件

[client]
default-character-set=utf8
[mysqld]
default-storage-engine=INNODB
character-set-server=utf8
collation-server=utf8_general_ci

The table 'XXX' is full

发生这种情况有多重情况:

  1. 可能是磁盘满了

  2. 出现此报错原因还有一个,那就是实际操作中,产生的临时表太大了,临时表的大小由参数tmp_table_size决定,默认为16M.

如果是内存表太大, 解决方法,是删数据还是修改此参数,看实际应用情况了。不过一个内存表能到2G个以上也是不太好的,内存毕竟有限。

更改表空间大小

vim /etc/my.cnf

设置
系统默认是16M,修改完后重启mysql
如果是要通过在MySQL中set来做动态修改的话参数类型会有所不同,这时候是字节单位.
可以通过show variables like '%tmp_table_size%'来做对比

tmp_table_size=1024M

max_heap_table_size=1024M

重启MySQL
service mysql restart

转载于:https://my.oschina.net/chinaliuhan/blog/3065292

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值