• centos7下面编译安装mysql5.7


    boot下载:https://nchc.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz

    cmake下载:https://cmake.org/files/v2.8/cmake-2.8.12.2.tar.gz

    mysql包下载:http://ftp.ntu.edu.tw/MySQL/Downloads/MySQL-5.7/mysql-5.7.27.tar.gz

    2. 安装方法

    2.1 编译安装cmake

    #建议创建个tools目录,将所有的软件包放在一起

    1. [root@192168066012_MySQL_5_7_27 ~]# mkdir -p /home/tools/
    2. [root@192168066012_MySQL_5_7_27 ~]# cd /home/tools/
    3. [root@192168066012_MySQL_5_7_27 tools]# ls -l
    4. total 143932
    5. -rw-r--r-- 1 root root 83709983 Jul 31 18:34 boost_1_59_0.tar.gz
    6. -rw-r--r-- 1 root root 6068231 Jul 31 18:36 cmake-2.8.12.2.tar.gz
    7. -rw-r--r-- 1 root root 54398696 Jul 31 18:34 mysql-5.7.27.tar.gz

    #解压cmake安装包

    1. [root@192168066012_MySQL_5_7_27 tools]# tar xf cmake-2.8.12.2.tar.gz
    2. [root@192168066012_MySQL_5_7_27 tools]# cd cmake-2.8.12.2
    3. [root@192168066012_MySQL_5_7_27 cmake-2.8.12.2]# ll
    4. total 3056
    5. -rwxr-xr-x 1 501 games 53974 Jan 17 2014 bootstrap
    6. -rw-r--r-- 1 501 games 254736 Jan 17 2014 ChangeLog.manual
    7. -rw-r--r-- 1 501 games 2603523 Jan 17 2014 ChangeLog.txt
    8. -rw-r--r-- 1 501 games 5465 Jan 17 2014 CMakeCPack.cmake
    9. -rw-r--r-- 1 501 games 3436 Jan 17 2014 CMakeCPackOptions.cmake.in
    10. -rw-r--r-- 1 501 games 153 Jan 17 2014 CMakeGraphVizOptions.cmake
    11. -rw-r--r-- 1 501 games 25439 Jan 17 2014 CMakeLists.txt
    12. -rw-r--r-- 1 501 games 4481 Jan 17 2014 CMakeLogo.gif
    13. -rw-r--r-- 1 501 games 796 Jan 17 2014 cmake_uninstall.cmake.in
    14. -rw-r--r-- 1 501 games 2515 Jan 17 2014 CompileFlags.cmake
    15. -rwxr-xr-x 1 501 games 99 Jan 17 2014 configure
    16. -rw-r--r-- 1 501 games 2637 Jan 17 2014 Copyright.txt
    17. -rw-r--r-- 1 501 games 1050 Jan 17 2014 CTestConfig.cmake
    18. -rw-r--r-- 1 501 games 3338 Jan 17 2014 CTestCustom.cmake.in
    19. -rw-r--r-- 1 501 games 145 Jan 17 2014 CTestCustom.ctest.in
    20. -rw-r--r-- 1 501 games 809 Jan 17 2014 DartConfig.cmake
    21. -rw-r--r-- 1 501 games 4144 Jan 17 2014 DartLocal.conf.in
    22. drwxr-xr-x 3 root root 142 Aug 1 14:32 Docs
    23. -rw-r--r-- 1 501 games 28046 Jan 17 2014 doxygen.config
    24. drwxr-xr-x 4 root root 53 Aug 1 14:32 Example
    25. drwxr-xr-x 9 root root 16384 Aug 1 14:32 Modules
    26. -rw-r--r-- 1 501 games 1946 Jan 17 2014 Readme.txt
    27. drwxr-xr-x 7 root root 24576 Aug 1 14:32 Source
    28. drwxr-xr-x 2 root root 4096 Aug 1 14:32 Templates
    29. drwxr-xr-x 169 root root 8192 Aug 1 14:32 Tests
    30. drwxr-xr-x 15 root root 4096 Aug 1 14:32 Utilities

    #开始编译安装

    1. [root@192168066012_MySQL_5_7_27 cmake-2.8.12.2]# ./configure
    2. ...省略
    3. CMake has bootstrapped. Now run gmake.

    #看到“Now run gmake”说明ok,可以进行gmake && gmake install

    1. [root@192168066012_MySQL_5_7_27 cmake-2.8.12.2]# gmake
    2. ...省略
    3. [100%] Built target pseudonl_valgrind
    4. [root@192168066012_MySQL_5_7_27 cmake-2.8.12.2]# gmake install
    5. ...省略
    6. -- Installing: /usr/local/share/cmake-2.8/completions/ctest

    提示:
    每一步结束后,可以使用echo $? ,当返回值为0时,说明编译过程正常

    2.2 将boost库解压到/usr/local/目录

    #指定解压到/usr/local/目录,使用 -C 参数

    1. [root@192168066012_MySQL_5_7_27 tools]# tar xf boost_1_59_0.tar.gz -C /usr/local/
    2. [root@192168066012_MySQL_5_7_27 tools]# cd /usr/local/
    3. [root@192168066012_MySQL_5_7_27 local]# mv boost_1_59_0/ boost
    4. [root@192168066012_MySQL_5_7_27 local]# ls -l
    5. total 0
    6. drwxr-xr-x. 2 root root 45 Jul 30 19:49 bin
    7. drwx------ 8 501 games 302 Aug 12 2015 boost
    8. drwxr-xr-x 3 root root 23 Jul 30 19:49 doc
    9. drwxr-xr-x. 2 root root 6 Apr 11 2018 etc
    10. drwxr-xr-x. 2 root root 6 Apr 11 2018 games
    11. drwxr-xr-x. 2 root root 6 Apr 11 2018 include
    12. drwxr-xr-x. 2 root root 6 Apr 11 2018 lib
    13. drwxr-xr-x. 2 root root 6 Apr 11 2018 lib64
    14. drwxr-xr-x. 2 root root 6 Apr 11 2018 libexec
    15. drwxr-xr-x 3 root root 18 Jul 30 19:49 man
    16. drwxr-xr-x. 2 root root 6 Apr 11 2018 sbin
    17. drwxr-xr-x. 7 root root 81 Jul 30 19:49 share
    18. drwxr-xr-x. 2 root root 6 Apr 11 2018 src

    2.3 解压MySQL 5.7,并进行编译安装

    2.3.1 安装MySQL 5.7的依赖包

    1. [root@192168066012_MySQL_5_7_27 tools]# yum install ncurses-devel -y
    2. ...省略
    3. Installed:
    4. ncurses-devel.x86_64 0:5.9-14.20130511.el7_4
    5.  
    6. Complete!

    提示:
    MySQL 5.7依赖的软件包:gcc gcc-c++ ncurses ncurses-devel bison make等供参考,安装前可以使用rpm -qa|grep ${软件包名称}检查一下

    2.3.2 创建MySQL文件存放目录,用户和组

    #创建数据库相关目录

    1. [root@192168066012_MySQL_5_7_27 tools]# mkdir -p /application/mysql
    2. [root@192168066012_MySQL_5_7_27 tools]# mkdir -p /application/mysql/data/
    3. [root@192168066012_MySQL_5_7_27 tools]# mkdir -p /application/mysql/tmp/
    4. [root@192168066012_MySQL_5_7_27 tools]# mkdir -p /application/mysql/binlog/
    5. [root@192168066012_MySQL_5_7_27 tools]# mkdir -p /application/mysql/logs/
    6. [root@192168066012_MySQL_5_7_27 tools]# tree -L 2 /application/
    7. /application/
    8. └── mysql
    9. ├── binlog
    10. ├── data
    11. ├── logs
    12. └── tmp
    13.  
    14. 5 directories, 0 files

    #创建mysql组和用户

    1. [root@192168066012_MySQL_5_7_27 tools]# groupadd mysql
    2. [root@192168066012_MySQL_5_7_27 tools]# useradd mysql -s /sbin/nologin -M -g mysql
    3. [root@192168066012_MySQL_5_7_27 tools]# id mysql
    4. uid=1000(mysql) gid=1000(mysql) groups=1000(mysql)

    说明:
    -s /sbin/nologin 用户不能登录系统
    -M 不创建用户的HOME目录
    -g 指定用户登录组的GID或组名

    2.3.3 编译安装MySQL 5.7

    #解压源码mysql-5.7.27.tar.gz安装包

    1. [root@192168066012_MySQL_5_7_27 tools]# cd /home/tools/
    2. [root@192168066012_MySQL_5_7_27 tools]# tar xf mysql-5.7.27.tar.gz

    #cmake配置编译参数

    1. [root@192168066012_MySQL_5_7_27 tools]# cd mysql-5.7.27
    2. [root@192168066012_MySQL_5_7_27 mysql-5.7.27]# cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql
    3. -DMYSQL_DATADIR=/application/mysql/data
    4. -DMYSQL_UNIX_ADDR=/application/mysql/tmp/mysql.sock
    5. -DDEFAULT_CHARSET=utf8
    6. -DDEFAULT_COLLATION=utf8_general_ci
    7. -DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii
    8. -DENABLED_LOCAL_INFILE=ON
    9. -DWITH_INNOBASE_STORAGE_ENGINE=1
    10. -DWITH_FEDERATED_STORAGE_ENGINE=1
    11. -DWITH_BLACKHOLE_STORAGE_ENGINE=1
    12. -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1
    13. -DWITHOUT_PARTITION_STORAGE_ENGINE=1
    14. -DWITH_ZLIB=bundled
    15. -DWITH_EMBEDDED_SERVER=1
    16. -DWITH_DEBUG=0
    17. -DWITH_BOOST=/usr/local/boost

    #看到如下信息,说明cmake编译完成,执行make继续安装

    1. -- Configuring done
    2. -- Generating done
    3. -- Build files have been written to: /home/tools/mysql-5.7.27

    #继续执行make install继续安装

    1. ...省略
    2. Linking CXX executable my_safe_process
    3. [100%] Built target my_safe_process

    #安装完成

    1. ...省略
    2. -- Installing: /application/mysql-5.7.27/share/aclocal/mysql.m4
    3. -- Installing: /application/mysql-5.7.27/support-files/mysql.server

    提示:
    如果上述操作未出现错误(每个步骤结束后,都可以使用echo $?看返回值是否为0,为0则表示正确),查看/application/mysql/目录,若其下有内容,则表示MySQL5.7.27源代码包采用cmake方式安装成功了

    2.3.3 编译常见参数选项说明

    编译参数说明
    -DCMAKE_INSTALL_PREFIX=/application/mysql-5.7.27 设定mysql安装目录
    -DMYSQL_DATADIR=/application/mysql-5.7.27/data 设定mysql数据文件目录
    -DMYSQL_UNIX_ADDR=/application/mysql-5.7.27/tmp/mysql.sock 设定mysql.sock路径
    -DDEFAULT_CHARSET=utf8 设定默认的字符集为utf8
    -DDEFAULT_COLLATION=utf8_general_ci 设定默认排序规则
    -DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii 启用额外的字符集类型
    -DENABLED_LOCAL_INFILE=ON 启用本地数据导入支持
    -DWITH_INNOBASE_STORAGE_ENGINE=1 启用存储引擎;若想启用某个引擎的支持,-DWITH_<ENGINE>_STORAGEENGINE=1;若想禁用某个引擎的支持,-DWITHOUT<ENGINE>_STORAGE_ENGINE=0
    -DWITH_FEDERATED_STORAGE_ENGINE=1 启用存储引擎
    -DWITH_BLACKHOLE_STORAGE_ENGINE=1 启用存储引擎
    -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 启用存储引擎
    -DWITHOUT_PARTITION_STORAGE_ENGINE=1 启用存储引擎
    -DWITH_ZLIB=bundled 启用zlib库支持
    -DWITH_EMBEDDED_SERVER=1 编译嵌入式服务器支持
    -DWITH_DEBUG=0 禁用debug(默认为禁用)
    -DWITH_BOOST=/usr/local/boost 启用boost库支持,MySQL 5.7版本编译安装需要依赖boost库

    提示:
    更多编译参数选项说明参见官方文档:https://dev.mysql.com/doc/refman/5.7/en/source-configuration-options.html#option_cmake_with_boost

    2.4 配置MySQL系统环境变量

    1. [root@192168066012_MySQL_5_7_27 ~]# echo 'export PATH=/application/mysql/bin:$PATH' >>/etc/profile
    2. [root@192168066012_MySQL_5_7_27 ~]# tail -1 /etc/profile
    3. export PATH=/application/mysql/bin:$PATH

    #使/etc/profile配置文件立即生效

    1. [root@192168066012_MySQL_5_7_27 ~]# source /etc/profile
    2. [root@192168066012_MySQL_5_7_27 ~]# echo $PATH
    3. /application/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

    2.5 初始化数据库

    2.5.1 更改MySQL安装目录的属主和属组

    [root@192168066012_MySQL_5_7_27 ~]# chown -R mysql:mysql /application/mysql/

    2.5.2 修改my.cnf文件的属主和属组

    [root@192168066012_MySQL_5_7_27 ~]# chown mysql:mysql /etc/my.cnf

    2.5.3 修改my.cnf配置文件

    #修改/etc/my.cnf文件,和5.6之前的版本不一样,5.7版本support-files目录下没有.cnf文件,因此,需要自己手动编辑

    1. [root@192168066012_MySQL_5_7_27 ~]# cp /etc/my.cnf /etc/my.cnf.bak
    2. [root@192168066012_MySQL_5_7_27 ~]# vim /etc/my.cnf
    3. [client]
    4. port = 3306
    5. socket = /application/mysql/tmp/mysql.sock
    6. default-character-set = utf8
    7.  
    8. [mysqld]
    9. port = 3306
    10. user = mysql
    11. basedir = /application/mysql
    12. datadir = /application/mysql/data
    13. pid-file = /application/mysql/mysqld.pid
    14. socket = /application/mysql/tmp/mysql.sock
    15. tmpdir = /application/mysql/tmp
    16. character_set_server = utf8
    17. server-id = 1
    18. max_connections = 100
    19. max_connect_errors = 10
    20. sql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES
    21. log-bin = /application/mysql/binlog/mysql-bin
    22. log-error = /application/mysql/logs/mysql_5_7_27.err

    my.cnf文件常用选项详解
    [client]
    #默认连接端口
    port = 3306
    #用于本地连接的socket套接字
    socket = /application/mysql/tmp/mysql.sock
    #编码
    default-character-set = utf8

    [mysqld]
    #服务端口号,默认3306
    port = 3306
    #mysql启动用户
    user = mysql
    #mysql安装根目录
    basedir = /application/mysql
    #mysql数据文件所在位置
    datadir = /application/mysql/data
    #pid文件所在目录
    pid-file = /application/mysql/mysqld.pid
    #为MySQL客户端程序和服务器之间的本地通讯指定一个套接字文件
    socket = /application/mysql/tmp/mysql.sock
    #MySQL存放临时文件的目录
    tmpdir = /application/mysql/tmp
    #数据库默认字符集,主流字符集支持一些特殊表情符号(特殊表情符占用4个字节)
    character_set_server = utf8
    #MySQL服务的唯一编号,每个mysql服务Id需唯一
    server-id = 1
    #最大连接数
    max_connections = 100
    #最大错误连接数
    max_connect_errors = 10
    #sql_mode,定义了mysql应该支持的sql语法,数据校验
    #NO_ENGINE_SUBSTITUTION:如果需要的存储引擎被禁用或未编译,可以防止自动替换存储引擎
    #STRICT_TRANS_TABLES:存储引擎启用严格模式,非法数据值被拒绝
    #NO_AUTO_CREATE_USER:禁止GRANT创建密码为空的用户
    #NO_AUTO_VALUE_ON_ZERO:默认情况下自增长列是从1开始的,如果你插入值为0的数据会报错,设置这个之后就可以正常插入为0的数据了
    #NO_ZERO_IN_DATE:在严格模式,不接受月或日部分为0的日期
    #NO_ZERO_DATE:在严格模式,不要将 ‘0000-00-00′做为合法日期
    #ERROR_FOR_DIVISION_BY_ZERO:在严格模式,在INSERT或UPDATE过程中,如果被零除(或 MOD(X,0)),则产生错误(否则为警告)。如果未给出该模式,被零除时MySQL返回NULL
    #PIPES_AS_CONCAT:将||视为字符串连接操作符(+)(同CONCAT()),而不视为OR
    #ANSI_QUOTES:将‘”'视为识别符引号(‘`'引号字符),不要视为字符串的引号字符
    sql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES
    #开启二进制日志功能,binlog数据位置
    log-bin = /application/mysql/binlog/mysql-bin
    #mysql生成的错误日志存放的路径
    log-error = /application/mysql/logs/mysql_5_7_27.err

    2.5.4 初始化数据库

    1. [root@192168066012_MySQL_5_7_27 ~]# cd /application/mysql/
    2. [root@192168066012_MySQL_5_7_27 mysql]# ./bin/mysqld --initialize-insecure --user=mysql --basedir=/application/mysql --datadir=/application/mysql/data
    3. 2019-07-31T13:27:06.397226Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
    4. 2019-07-31T13:27:06.813340Z 0 [Warning] InnoDB: New log files created, LSN=45790
    5. 2019-07-31T13:27:06.871853Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
    6. 2019-07-31T13:27:06.929377Z 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: e45d3fac-b396-11e9-9e3e-000c290943d8.
    7. 2019-07-31T13:27:06.930628Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
    8. 2019-07-31T13:27:06.931630Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

    提示:
    #生成初始化密码参数(5.7版本才有),必须要添加,否则会初始化失败,会生成空密码
    --initialize-insecure
    #设定初始化用户
    --user=mysql
    #设定mysql工作目录
    --basedir=/application/mysql
    #设定数据文件目录
    --datadir=/application/mysql/data

    2.5.5 实例开启SSL连接

    1. [root@192168066012_MySQL_5_7_27 mysql]# cd /application/mysql/
    2. [root@192168066012_MySQL_5_7_27 mysql]# ./bin/mysql_ssl_rsa_setup --initialize-insecure --user=mysql --basedir=/application/mysql --datadir=/application/mysql/data
    3. Generating a 2048 bit RSA private key
    4. ............+++
    5. .............................................+++
    6. writing new private key to 'ca-key.pem'
    7. -----
    8. Generating a 2048 bit RSA private key
    9. ......+++
    10. ...................................+++
    11. writing new private key to 'server-key.pem'
    12. -----
    13. Generating a 2048 bit RSA private key
    14. .....................................................................................................+++
    15. ........................+++
    16. writing new private key to 'client-key.pem'
    17. -----

    2.5.6 修改data目录下的server-key.pem文件权限

    1. [root@192168066012_MySQL_5_7_27 ~]# cd /application/mysql/data/
    2. [root@192168066012_MySQL_5_7_27 data]# chmod +r server-key.pem
    3. [root@192168066012_MySQL_5_7_27 data]# ls -l server-key.pem
    4. -rw-r--r-- 1 root root 1675 Jul 31 20:01 server-key.pem

    提示:
    如果不给文件server-key.pem其他用户和组可读权限的话,当启动数据库的时候,会报如下错误
    2019-08-07T06:39:24.111526Z 0 [ERROR] SSL error: Unable to get private key from 'server-key.pem'
    2019-08-07T06:39:24.111555Z 0 [Warning] Failed to set up SSL because of the following SSL library error: Unable to get private key

    2.6 启动MySQL数据库

    #拷贝启动脚本到/etc/init.d/目录下,并改名mysqld

    1. [root@192168066012_MySQL_5_7_27 mysql]# cp support-files/mysql.server /etc/init.d/mysqld
    2. [root@192168066012_MySQL_5_7_27 mysql]# ls -l /etc/init.d/mysqld
    3. -rwxr-xr-x 1 root root 10588 Aug 1 18:33 /etc/init.d/mysqld

    #重新加载系统服务,将MySQL数据库加入开机自启动

    1. [root@192168066012_MySQL_5_7_27 ~]# /bin/systemctl daemon-reload
    2. [root@192168066012_MySQL_5_7_27 ~]# /bin/systemctl enable mysqld.service
    3. mysqld.service is not a native service, redirecting to /sbin/chkconfig.
    4. Executing /sbin/chkconfig mysqld on

    #启动MySQL数据库,并检查端口监听状态

    1. [root@192168066012_MySQL_5_7_27 ~]# /etc/init.d/mysqld start
    2. Starting MySQL. SUCCESS!
    3. [root@192168066012_MySQL_5_7_27 ~]# netstat -lntup
    4. Active Internet connections (only servers)
    5. Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
    6. tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 6549/sshd
    7. tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 7023/master
    8. tcp6 0 0 :::3306 :::* LISTEN 10947/mysqld
    9. tcp6 0 0 :::22 :::* LISTEN 6549/sshd
    10. tcp6 0 0 ::1:25 :::* LISTEN 7023/master

    提示:
    默认CentOS 7默认没有netstat命令,而是使用ss命令代替;如果想使用netstat命令的话,需要执行yum install net-tools进行安装net-tools软件包,然后就可以使用了;

    2.7 MySQL数据库基本优化(安全)

    #删除全部用户,添加额外管理员,重新加载mysql授予表

    1. mysql> select user,host from mysql.user;
    2. +---------------+-----------+
    3. | user | host |
    4. +---------------+-----------+
    5. | mysql.session | localhost |
    6. | mysql.sys | localhost |
    7. | root | localhost |
    8. +---------------+-----------+
    9. 3 rows in set (0.00 sec)
    10.  
    11. mysql> grant all privileges on *.* to boyu@'localhost' identified by 'boyu123' with grant option;
    12. Query OK, 0 rows affected, 1 warning (0.00 sec)
    13.  
    14. mysql> flush privileges;
    15. Query OK, 0 rows affected (0.00 sec)
    16.  
    17. mysql> delete from mysql.user where user='mysql.session';
    18. Query OK, 1 row affected (0.01 sec)
    19.  
    20. mysql> delete from mysql.user where user='mysql.sys';
    21. Query OK, 1 row affected (0.00 sec)
    22.  
    23. mysql> delete from mysql.user where user='root';
    24. Query OK, 1 row affected (0.00 sec)
    25.  
    26. mysql> select user,host from mysql.user;
    27. +------+-----------+
    28. | user | host |
    29. +------+-----------+
    30. | boyu | localhost |
    31. +------+-----------+
    32. 1 row in set (0.00 sec)

    2.8 优雅关闭MySQL数据的方法

    #使用MySQL自带的脚本

    1. [root@192168066012_MySQL_5_7_27 ~]# /etc/init.d/mysqld stop
    2. Shutting down MySQL. SUCCESS!

    #使用mysqladmin的方法

    1. [root@192168066012_MySQL_5_7_27 mysql]# mysqladmin -uboyu -pboyu123 shutdown
    2. mysqladmin: [Warning] Using a password on the command line interface can be insecure.
    3. #mysqladmin:[警告]在命令行界面上使用密码可能不安全

    提示:
    5.7版本优化了数据库的安全配置,建议配置SSL加密连接,默认在命令行输入的密码都是明文传输的,极为不安全;

    2.9 授权远程用户连接MySQL数据的方法

    #授权192.168.88.1对MySQL所有库和所有表都赋予boyu用户权限;

    1. mysql> grant all privileges on *.* to boyu@'192.168.66.11' identified by 'boyu123' with grant option;
    2. Query OK, 0 rows affected, 1 warning (0.00 sec)
    3.  
    4. mysql> flush privileges;
    5. Query OK, 0 rows affected (0.00 sec)
    6.  
    7. mysql> select user,host from mysql.user;
    8. +------+---------------+
    9. | user | host |
    10. +------+---------------+
    11. | boyu | 192.168.66.11 |
    12. | boyu | localhost |
    13. +------+---------------+
    14. 2 rows in set (0.00 sec)

    #测试远程登陆

    1. [root@192168066011 ~]# mysql -h192.168.66.12 -uboyu -pboyu123 -P3306
    2. Welcome to the MySQL monitor. Commands end with ; or g.
    3. Your MySQL connection id is 4
    4. Server version: 5.7.27 Source distribution
    5.  
    6. Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
    7.  
    8. Oracle is a registered trademark of Oracle Corporation and/or its
    9. affiliates. Other names may be trademarks of their respective
    10. owners.
    11.  
    12. Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
    13.  
    14. mysql> show databases;
    15. +--------------------+
    16. | Database |
    17. +--------------------+
    18. | information_schema |
    19. | mysql |
    20. | performance_schema |
    21. | sys |
    22. +--------------------+
    23. 4 rows in set (0.00 sec)

    3 案例和MySQL 5.7编译安装报错信息整理

    3.1 MySQL数据库使用kill的故障案例

    625某电商网站数据库宕机故障解决实录(上)
    625某电商网站数据库宕机故障解决实录(下)
    提示:
    不要野蛮粗鲁杀死数据库,生产高并发环境会导致数据丢失

    3.2 编译安装MySQL报错

    #未指定boost库,MySQL 5.7版本使用cmake配置编译参数时,强依赖boost
    CentOS 7.6源码编译安装MySQL 5.7.27

    解决办法:

    • MySQL 5.7版本对应的boost库版本为:boost_1_59_0.tar.gz,本文已提供下载连接
    • 将boost_1_59_0下载到本地,放在/usr/local/目录下
    • 添加cmake参数“-DWITH_BOOST=/usr/local/boost”,指定boost目录位置

    #找不到CURSES_LIBRARY
    CentOS 7.6源码编译安装MySQL 5.7.27

    解决办法:
    yum install ncurses-devel -y

    #make过程,报内存不足错误
    CentOS 7.6源码编译安装MySQL 5.7.27

    解决办法:
    增加内存空间,或者swap空间

  • 相关阅读:
    Visual Studio使用技巧
    排颜色问题——数组 leetcode lintcode
    【简洁】微信为何总令人感觉如此简洁、?(一)
    字符串通信协议解析函数
    我所改造的JSocket适用于任何DELPHI版本
    缓存和字符串相互转换
    TcxDBTreeList导出EXCEL
    TcxGrid导出EXCEL
    TdxAlertWindowManager右下角HINT显示控件
    好用的编辑框布局控件TdxLayoutControl
  • 原文地址:https://www.cnblogs.com/xingyunfashi/p/12196415.html
Copyright © 2020-2023  润新知