mysql el7_CentOS7中mysql-5.7.21-el7-x86_64.tar.gz版MySQL的安装与配置

一、准备阶段

通常情况下,MySQL在CentOS下主要使用glibc、rpm、yum等方式进行安装,使用mysql-5.7.21-el7-x86_64.tar.gz包进行安装的很少见,网上资料也较少。通过一上午的摸索,总结出如下安装方法。

下载安装包:

[root@GeekDevOps ~]# curl -C - -O https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.21-el7-x86_64.tar.gz

% Total % Received % Xferd Average Speed Time Time Time Current

Dload Upload Total Spent Left Speed

100 674M 100 674M 0 0 4311k 0 0:02:40 0:02:40 --:--:-- 4067k

创建安装账户:

[root@GeekDevOps ~]# useradd -s /bin/false -d /usr/local/mysql mysql

[root@GeekDevOps ~]# id mysql

uid=1000(mysql) gid=1000(mysql) 组=1000(mysql)

二、安装过程

[root@GeekDevOps ~]# tar -xvzf mysql-5.7.21-el7-x86_64.tar.gz -C /usr/local/mysql/

[root@GeekDevOps mysql]# cd /usr/local/mysql/mysql-5.7.21-el7-x86_64/

[root@GeekDevOps mysql-5.7.21-el7-x86_64]# mv * ../

[root@GeekDevOps mysql-5.7.21-el7-x86_64]# cd ..

[root@GeekDevOps mysql]# rmdir mysql-5.7.21-el7-x86_64/

[root@GeekDevOps mysql]# mkdir data

[root@GeekDevOps mysql]# chown -R mysql.mysql ../mysql

[root@GeekDevOps mysql]# cd bin

[root@GeekDevOps bin]# ./mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize

[root@GeekDevOps bin]# tail -100f ../data/error.log

2018-03-14T06:32:34.966407Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2018-03-14T06:32:36.208273Z 0 [Warning] InnoDB: New log files created, LSN=45790

2018-03-14T06:32:36.367294Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.

2018-03-14T06:32:36.522777Z 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: 7c405e3f-2751-11e8-8be8-000c29fb0102.

2018-03-14T06:32:36.525594Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.

2018-03-14T06:32:36.526540Z 1 [Note] A temporary password is generated for root@localhost: 7Eu;dsRqkY.3

[root@GeekDevOps bin]# cp ../support-files/mysql.server /etc/init.d/mysqld

三、配置过程

[root@GeekDevOps ~]# vi /etc/my.cnf

[mysqld]

port = 3306

basedir = /usr/local/mysql

datadir=/usr/local/mysql/data

socket=/tmp/mysql.sock

pid-file=/usr/local/mysql/data/mysql.pid

log-error=/usr/local/mysql/data/error.log

character_set_server=utf8

user=mysql

max_connections=1500

symbolic-links=0

!includedir /etc/my.cnf.d

四、启动服务并登陆

[root@GeekDevOps ~]# service mysqld start

Starting MySQL. SUCCESS!

[root@GeekDevOps mysql]# ./bin/mysql -u root -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.7.21

Copyright (c) 2000, 2018, 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>

在此过程中要求输入密码,在第三步中我们可以看到安装完成后的密码:7Eu;dsRqkY.3,输入即可登陆成功。

五、修改密码

mysql> set password=password('GeekDevOps');

Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> quit

Bye

下次登录即可使用新密码进行登录。安装过程至此结束,其他配置与我之前写的glibc版的别无二致,此处不再赘述,其他配置请在my.cnf按照自己的需求进行配置。

六、安装过程中出现的问题

在安装完成之后,查看日志我们看到:TIMESTAMP with implicit DEFAULT value is deprecated. Please use –explicit_defaults_for_timestamp server option (see documentation for more details)。这是一个常见问题,在配置文件/etc/my.cnf的mysqld块添加:explicit_defaults_for_timestamp=1,重启数据库服务。

在完成上一步操作的过程中,查看日志发现提示:–secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled。意思是与导出、导入有关的操作都是被禁用的,我们需要导出、导入的话就需要设置,在配置文件/etc/my.cnf中mysqld下加入:secure_file_priv=/test(目录可以按需求更改),这一项也可以在安装初始化的时候加入:–secure-file-priv=/test。

七、总结

mysql-5.7.21-el7-x86_64.tar.gz该版本的MySQL安装教程在网上并不常见,我是通过tar.gz包内的文档(/usr/local/mysql/docs/INFO_BIN)受到启发才进行安装的,从文档中我们可以看到编译的详细信息。

===== Information about the build process: =====

Build was run at 2017-12-28 05:42:32 on host 'vale08'

Build was done on Linux-4.1.12-61.1.27.el7uek.x86_64 using x86_64

Build was done using cmake 2.8.12

===== Compiler flags used (from the 'sql/' subdirectory): =====

# compile C with /bin/cc

# compile CXX with /bin/c++

C_FLAGS = -fPIC -Wall -Wextra -Wformat-security -Wvla -Wwrite-strings -Wdeclaration-after-statement -O3 -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -DDBUG_OFF -I/export/home/pb2/build/sb_0-26514852-1514435436.48/release/include -I/export/home/pb2/build/sb_0-26514852-1514435436.48/mysql-5.7.21/extra/rapidjson/include -I/export/home/pb2/build/sb_0-26514852-1514435436.48/release/libbinlogevents/include -I/export/home/pb2/build/sb_0-26514852-1514435436.48/mysql-5.7.21/libbinlogevents/export -I/export/home/pb2/build/sb_0-26514852-1514435436.48/mysql-5.7.21/include -I/export/home/pb2/build/sb_0-26514852-1514435436.48/mysql-5.7.21/sql/conn_handler -I/export/home/pb2/build/sb_0-26514852-1514435436.48/mysql-5.7.21/libbinlogevents/include -I/export/home/pb2/build/sb_0-26514852-1514435436.48/mysql-5.7.21/sql -I/export/home/pb2/build/sb_0-26514852-1514435436.48/mysql-5.7.21/sql/auth -I/export/home/pb2/build/sb_0-26514852-1514435436.48/mysql-5.7.21/regex -I/export/home/pb2/build/sb_0-26514852-1514435436.48/mysql-5.7.21/zlib -I/export/home/pb2/build/sb_0-26514852-1514435436.48/mysql-5.7.21/extra/yassl/include -I/export/home/pb2/build/sb_0-26514852-1514435436.48/mysql-5.7.21/extra/yassl/taocrypt/include -I/export/home/pb2/build/sb_0-26514852-1514435436.48/release/sql -I/export/home/pb2/build/sb_0-26514852-1514435436.48/mysql-5.7.21/extra/lz4 -DHAVE_YASSL -DYASSL_PREFIX -DHAVE_OPENSSL -DMULTI_THREADED

C_DEFINES = -DHAVE_CONFIG_H -DHAVE_LIBEVENT1 -DHAVE_REPLICATION -DMYSQL_SERVER -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE

本文同步分享在 博客“点亮梦想那束光”(CSDN)。

如有侵权,请联系 support@oschina.cn 删除。

本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值