mysql5.7.19带源码_MySQL5.7.19源码编译安装

环境说明:

1. 系统环境: CentOS7-64位 内存:4GB 硬盘:20GB (VMWARE虚拟机)

2. MySQL版本: 5.7.19

--------------

1. 下载MySQL

Screen%20Shot%202017-07-30%20at%2020.20.49.png

下载后上传至Linux服务器,这里把源码包放到/usr/local目录下。

2. 环境准备

2.1 安装编译需要用到的依赖软件

Screen%20Shot%202017-07-30%20at%2021.09.35.png

如果数据库使用多实例,还需要安装: libaio, libaio-devel, 另外,还可安装: bison-devel openssl-devel。

(cmake加参数:-DWITH_SSL=yes时依赖openssl库)

2.2 添加mysql用户和用户组

执行命令: sudo groupadd mysql && sudo useradd mysql -s /sbin/nologin -M -g mysql

3. 开始安装

3.1 预编译

执行命令:

cd /usr/local/mysql-5.7.19 && sudo cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DMYSQL_UNIX_ADDR=/usr/local/mysql/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii -DENABLE_LOCAL_INFILE=ON -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 -DWITHOUT_PARTITION_STORAGE_ENGINE=1 -DWITH_FAST_MUTEXES=1 -DWITH_ZLIB=bundled -DENABLE_LOCAL_INFILE=1 -DWITH_READLINE=1 -DWITH_EMBEDDED_SERVER=1 -DWITH_DEBUG=0

出现如下错误,提示找不到boost库:

Screen%20Shot%202017-07-30%20at%2021.19.21.png

这里再添加两个参数: -DDOWNLOAD_BOOST=1 -DWITH_BOOST=, boost路径填/usr/local/boost即可,它会在这个目录找,找不到就会自己下载到该目录下,如下所示:

Screen%20Shot%202017-07-30%20at%2021.21.40.png

注意:

cmake生成的临时文件是CMakeCache.txt,重新cmake时,最好删除上一个CMakeCache.txt文件,避免不必要的错误。

3.2 编译

执行命令:

sudo make即可,注意,内存最好大于等于4G, 内存为2G可能会编译失败。编译完如下:

Screen%20Shot%202017-07-30%20at%2022.28.54.png

3.3 安装

执行命令:

sudo make install。安装完如下:

Screen%20Shot%202017-07-30%20at%2022.30.46.png

3.4 配置

3.4.1 目录授权

Screen%20Shot%202017-07-30%20at%2022.37.02.png

另外,还需创建一个目录,命令: sudo mkdir /usr/local/mysql/tmp

3.4.2 初始化mysql的系统数据表

命令: sudo /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data

在Mysql5.7之前,初始化一般都是使用sripts目录下的mysql_install_db脚本,这里改为用mysqld了, 并且初始化后有一个默认的root随机密码:

Screen%20Shot%202017-07-30%20at%2022.41.20.png

3.4.3 创建配置文件

这里没有my-default.cnf文件:

Screen%20Shot%202017-07-30%20at%2022.49.16.png

我们在网站找一个,然后按我们的参数修改配置即可,命令:

sudo mv /etc/my.cnf /etc/my.cnf.bak && sudo mv my.cnf /etc/my.cnf,文件内容如下:

# Example MySQL config file for small systems.

#

# This is for a system with little memory (<= 64M) where MySQL is only used

# from time to time and it's important that the mysqld daemon

# doesn't use much resources.

#

# MySQL programs look for option files in a set of

# locations which depend on the deployment platform.

# You can copy this option file to one of those

# locations. For information about these locations, see:

# http://dev.mysql.com/doc/mysql/en/option-files.html

#

# In this file, you can use all long options that a program supports.

# If you want to know which options a program supports, run the program

# with the "--help" option.

# The following options will be passed to all MySQL clients

[client]

#password= your_password

port= 3298

socket= /usr/local/mysql/tmp/mysql.sock

# Here follows entries for some specific programs

# The MySQL server

[mysqld]

port= 3298

socket= /usr/local/mysql/tmp/mysql.sock

skip-external-locking

key_buffer_size = 16K

max_allowed_packet = 1M

table_open_cache = 4

sort_buffer_size = 64K

read_buffer_size = 256K

read_rnd_buffer_size = 256K

net_buffer_length = 2K

thread_stack = 256K

# Don't listen on a TCP/IP port at all. This can be a security enhancement,

# if all processes that need to connect to mysqld run on the same host.

# All interaction with mysqld must be made via Unix sockets or named pipes.

# Note that using this option without enabling named pipes on Windows

# (using the "enable-named-pipe" option) will render mysqld useless!

#

#skip-networking

server-id= 1

# Uncomment the following if you want to log updates

#log-bin=mysql-bin

# binary logging format - mixed recommended

#binlog_format=mixed

# Causes updates to non-transactional engines using statement format to be

# written directly to binary log. Before using this option make sure that

# there are no dependencies between transactional and non-transactional

# tables such as in the statement INSERT INTO t_myisam SELECT * FROM

# t_innodb; otherwise, slaves may diverge from the master.

#binlog_direct_non_transactional_updates=TRUE

# Uncomment the following if you are using InnoDB tables

#innodb_data_home_dir = /usr/local/mysql/data

#innodb_data_file_path = ibdata1:10M:autoextend

#innodb_log_group_home_dir = /usr/local/mysql/data

# You can set .._buffer_pool_size up to 50 - 80 %

# of RAM but beware of setting memory usage too high

#innodb_buffer_pool_size = 16M

#innodb_additional_mem_pool_size = 2M

# Set .._log_file_size to 25 % of buffer pool size

#innodb_log_file_size = 5M

#innodb_log_buffer_size = 8M

#innodb_flush_log_at_trx_commit = 1

#innodb_lock_wait_timeout = 50

[mysqldump]

quick

max_allowed_packet = 16M

[mysql]

no-auto-rehash

# Remove the next comment character if you are not familiar with SQL

#safe-updates

[myisamchk]

key_buffer_size = 8M

sort_buffer_size = 8M

[mysqlhotcopy]

interactive-timeout

3.4.4 (按需)配置了SSL的需要执行

命令: sudo /usr/local/mysql/bin/mysql_ssl_rsa_setup

3.5 启动

命令: sudo /usr/local/mysql/bin/mysqld_safe --user=mysql &

发生如下错误:

Screen%20Shot%202017-07-30%20at%2023.00.37.png

修改目录授权:sudo chown -R mysql:mysql /usr/local/mysql,之前的所属用户和组是root,修改后重启启动:

Screen%20Shot%202017-07-30%20at%2023.02.39.png

MySQL启动完成。

前面在初始化系统数据表时,提示一句,说明了root的初始随机密码,内容如下:

2017-07-30T14:39:57.719908Z 1 [Note] A temporary password is generated for root@localhost:

现在用这个密码

Screen%20Shot%202017-07-30%20at%2023.08.30.png

暂时无法执行命令,需要先重置root密码:

Screen%20Shot%202017-07-30%20at%2023.10.05.png

3.6 关闭MySQL

命令: /usr/local/mysql/bin/mysqladmin shutdown -u root -p

Screen%20Shot%202017-07-30%20at%2023.11.29.png

3.7 其他

3.7.1 查看MySQL从什么位置加载my.cnf配置文件

0da580c93d074c415279bf7dd50c470d.png

如果存在多个文件,MySQL会以读取到的最后一个配置文件参数为准启动进程。

3.7.2 数据库与数据库实例

数据库是文件的集合,是依照某种数据模型组织起来并存放于二级存储器中的数据集合。

数据库实例是程序,是位于用户与操作系统之间的一层数据管理软件,用户对数据库数据的任何操作,包括数据库定义、数据查询、数据维护、数据库运行控制等都是在数据库实例下进行的,应用程序只有通过数据库实例才能和数据库打交道。

3.7.3 数据库的存储引擎是基于表的,而不是数据库!

3.7.4 N/A.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
mysql官网上下载mysql-server_5.7.21-1ubuntu14.04_amd64.deb-bundle.tar,然后进行离线安装,解压该安装包,会出现11个依赖包,按照顺序依次使用sudo dpkg -i 进行安装,中间会报错,显示缺少相应的依赖,具体如下: *******@ubuntu:/opt/mysql$ sudo dpkg -i mysql-community-client_5.7.21-1ubuntu14.04_amd64.deb Selecting previously unselected package mysql-community-client. (Reading database ... 208518 files and directories currently installed.) Preparing to unpack mysql-community-client_5.7.21-1ubuntu14.04_amd64.deb ... Unpacking mysql-community-client (5.7.21-1ubuntu14.04) ... dpkg: dependency problems prevent configuration of mysql-community-client: mysql-community-client depends on libaio1 (>= 0.3.93); however: Package libaio1 is not installed. dpkg: error processing package mysql-community-client (--install): dependency problems - leaving unconfigured Processing triggers for man-db (2.6.7.1-1ubuntu1) ... Errors were encountered while processing: mysql-community-client 和 ********@ubuntu:/opt/mysql$ sudo dpkg -i mysql-community-server_5.7.21-1ubuntu14.04_amd64.deb Selecting previously unselected package mysql-community-server. (Reading database ... 208598 files and directories currently installed.) Preparing to unpack mysql-community-server_5.7.21-1ubuntu14.04_amd64.deb ... Unpacking mysql-community-server (5.7.21-1ubuntu14.04) ... dpkg: dependency problems prevent configuration of mysql-community-server: mysql-community-server depends on libmecab2 (>= 0.996-1.1); however: Package libmecab2 is not installed. dpkg: error processing package mysql-community-server (--install): dependency problems - leaving unconfigured Processing triggers for man-db (2.6.7.1-1ubuntu1) ... Processing triggers for ureadahead (0.100.0-16) ... ureadahead will be reprofiled on next reboot Errors were encountered while processing: mysql-community-server 附上依赖包安装顺序: 1.mysql-common_5.7.21-1ubuntu14.04_amd64.deb 2.libmysqlclient20_5.7.21-1ubuntu14.04_amd64.deb 3.libmysqlclient-dev_5.7.21-1ubuntu14.04_amd64.deb 4.libmysqld-dev_5.7.21-1ubuntu14.04_amd64.deb
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值