mysql5.7源码安装

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql5.7源码安装相关的知识,希望对你有一定的参考价值。

1.安装所有包

yum -y install gcc-c++ ncurses-devel cmake make perl gcc autoconf automake zlib libxml libgcrypt libtool bison Python-devel

2.创建用户,目录,权限

[[email protected] ~]# groupadd mysql
[[email protected] ~]# useradd -r -g mysql -s /bin/false mysql
[[email protected] ~]# tar xvf mysql-5.7.17.tar.gz
[[email protected] ~]# cd mysql-5.7.17
mkdir /usr/local/mysql  软件目录
mkdir -p /usr/local/mysql/data   数据目录
mkdir -p /var/log/mysql     日志路径
mkdir -p /var/run/mysql     pid路径


-- 用户属主

chown -R mysql:mysql /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql/data
chown -R mysql:mysql /var/log/mysql
chown -R mysql:mysql /var/run/mysql

另外如果有登陆固需求:

设置vim  /etc/security/limits.conf

MySQL   soft   nproc  2047

mysql   hard  nproc  16384


mysql   soft   nofile  1024


mysql  hard   nofile  65536

环境变量:

vim /home/mysql/.bash_profile

export  LANG=zh_CN.GB18030

export PATH=/usr/local/mysql/bin:$PATH

3.安装一些配置,工具包

gmock ,地址http://git.typecodes.com/libs/ccpp/gmock-1.6.0.zip
安装步骤,解压到mysql-5.7.9的source_downloads目录,可选步骤
安装cmake,可以使用yum安装或者下载安装,下载路经http://git.typecodes.com/libs/ccpp/cmake-3.2.1.tar.gz
安装ncurses-devel,yum安装
GNU分析器生成器,连接http://git.typecodes.com/libs/ccpp/bison-3.0.tar.gz

4.编译&&安装

tar zxvf mysql-5.7.9.tar.gz
cd mysql-5.7.9
第一部:       

[[email protected] ~]# groupadd mysql
[[email protected] ~]# useradd -r -g mysql -s /bin/false mysql
[[email protected] ~]# tar xvf mysql-5.7.17.tar.gz
[[email protected] ~]# cd mysql-5.7.17
[[email protected] ~]# cmake . \
-DWITH_BOOST=boost/boost_1_59_0/ \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DSYSCONFDIR=/etc \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DINSTALL_MANDIR=/usr/share/man \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1
[[email protected] ~]# make
[[email protected] ~]# make install

cmake .\-DCMAKE_INSTALL_PREFIX=/usr/local/mysql  -DMYSQL_DATADIR=/usr/local/mysql/data  -DSYSCONFDIR=/etc -DMYSQL_USER=mysql -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/var/run/mysql/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DENABLE_DOWNLOADS=1 -DWITH_PARTITION_STORAGE_ENGINE=1  -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_DEBUG=0 -DMYSQL_MAINTAINER_MODE=0 -DWITH_SSL:STRING=bundled -DWITH_ZLIB:STRING=bundled -DWITH_BOOST=/usr/local/boost

第二部:make && make install
说明
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql  \              [MySQL安装的根目录]
-DMYSQL_DATADIR=/mydata/mysql/data  \                   [MySQL数据库文件存放目录]
-DSYSCONFDIR=/etc \                                     [MySQL配置文件所在目录]
-DMYSQL_USER=mysql \                                    [MySQL用户名]      
-DWITH_MYISAM_STORAGE_ENGINE=1 \                        [MySQL的数据库引擎]
-DWITH_INNOBASE_STORAGE_ENGINE=1 \                      [MySQL的数据库引擎]
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \                       [MySQL的数据库引擎]
-DWITH_MEMORY_STORAGE_ENGINE=1 \                        [MySQL的数据库引擎]
-DWITH_READLINE=1 \                                     [MySQL的readline library]
-DMYSQL_UNIX_ADDR=/var/run/mysql/mysql.sock \           [MySQL的通讯目录]
-DMYSQL_TCP_PORT=3306 \                                 [MySQL的监听端口]
-DENABLED_LOCAL_INFILE=1 \                              [启用加载本地数据]
-DENABLE_DOWNLOADS=1 \                                  [编译时允许自主下载相关文件]
-DWITH_PARTITION_STORAGE_ENGINE=1  \
-DEXTRA_CHARSETS=all \                                  [使MySQL支持所有的扩展字符]
-DDEFAULT_CHARSET=utf8 \                                [设置默认字符集为utf8]
-DDEFAULT_COLLATION=utf8_general_ci \                   [设置默认字符校对]
-DWITH_DEBUG=0 \                                        [禁用调试模式]
-DMYSQL_MAINTAINER_MODE=0 \
-DWITH_SSL:STRING=bundled \                             [通讯时支持ssl协议]
-DWITH_ZLIB:STRING=bundled \                            [允许使用zlib library]
-DWITH_BOOST=/usr/local/boost                [boost库地址,如果安装了,可以不用指定]
中间遇到两个问题,
第一,CMake Error at cmake/boost.cmake:76 (MESSAGE)
You can download it with -DDOWNLOAD_BOOST=1 -DWITH_BOOST=<directory>
解决方法:追加编译选项-DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost或者将 http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz下载到/usr/local/boost 再追加编译选项-DWITH_BOOST=/usr/local/boost
这个一定要匹配,mysql-5.7.9可能需要安装boost_1_59_0以上版本的
第二,Could NOT find Curses (missing:  CURSES_LIBRARY CURSES_INCLUDE_PATH)
解决:
rm CMakeCache.txt
yum install ncurses-devel

其实这个根据提示就可以看出来了

第三,安装boost的时候,提示很多python库没找到

yum install python-devel

5配置文件

我们安装时配置的路径是etc,这里有个默认的文件my.cnf,修改内容为类似如下,这一步最好使用安装文件/usr/local/mysql/support-files/my-default.cnf 放到/etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It‘s a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[client]
port=3306
socket=/var/run/mysql/mysql.sock

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
user = mysql
basedir = /usr/local/mysql
datadir = /mydata/mysql/data
port=3306
server-id = 1
socket=/var/run/mysql/mysql.sock

character-set-server = utf8
log-error = /var/log/mysql/error.log
pid-file = /var/log/mysql/mysql.pid
general_log = 1
skip-name-resolve
#skip-networking
back_log = 300

max_connections = 1000
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 128 
max_allowed_packet = 4M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 16M

read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 28M
key_buffer_size = 4M

thread_cache_size = 8

query_cache_type = 1
query_cache_size = 8M
query_cache_limit = 2M

ft_min_word_len = 4

log_bin = mysql-bin
binlog_format = mixed
expire_logs_days = 30


performance_schema = 0
explicit_defaults_for_timestamp

#lower_case_table_names = 1

#default-storage-engine=myism
#innodb_buffer_pool_size=2048M
#innodb_log_file_size=1024M

myisam_sort_buffer_size = 8M
myisam_repair_threads = 1

interactive_timeout = 28800
wait_timeout = 28800


# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M 

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,NO_AUTO_CREATE_USER,STRICT_TRANS_TABLES 

[mysqldump]
quick
max_allowed_packet = 16M

[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M

6.初始化数据库

[[email protected] local]# cd mysql
[[email protected] mysql]# chown -R mysql .
[[email protected] mysql]# chgrp -R mysql .
[[email protected] mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
[[email protected] mysql]# bin/mysql_ssl_rsa_setup
[[email protected] mysql]# chown -R root .
[[email protected] mysql]# chown -R mysql data mysql-files

[[email protected] mysql]# \cp -rf support-files/my-default.cnf  /etc/my.cnf
[[email protected] mysql]# bin/mysqld_safe --user=mysql &
[[email protected] mysql]# echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
[[email protected] mysql]# source /etc/profile
[[email protected] mysql]# mysql -uroot -p‘xxxx‘
mysql> alter user [email protected]‘localhost‘ identified by ‘tianyun‘;

7.设置系统服务,开机子启动

cp /usr/local/mysql/support-files/mysql.server  /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld  
chkconfig --add mysql

chkconfig mysqld on

可以参考:http://blog.csdn.NET/jc_benben/article/details/52767649

8.启动服务

mysqld_safe --user=mysql --datadir=/mydata/mysql/data --log-error=/var/log/mysql/error.log &
service mysqld start
不懂两者关系摆渡
查看启动情况:ps -ef | grep mysql,netstat -tunpl | grep 3306

9.初始化配置

mysql_secure_installation
根据需要配置一些root密码,是否匿名访问,是否远程访问,删除test库等操作

10.创建用户等

mysql -uroot -p
create database `mysqldb` default character set utf8 collate utf8_general_ci;
grant all privileges on mysqldb.* to [email protected] identified by ‘china123‘;
flush privileges;

说明:mysql比较特殊,不像Oracle,授权即可创建新用户


以上是关于mysql5.7源码安装的主要内容,如果未能解决你的问题,请参考以下文章

mysql5.7源码安装数据库部署

MYSQL5.7源码包编译安装

ubuntu编译安装mysql5.7

源码编译并二进制安装MySQL5.7 3 二进制安装mariadb10.4

mysql5.7源码安装及常用命令

CentOS 源码安装MySQL5.7