MySQL源码安装的示例分析
这篇文章主要介绍MySQL源码安装的示例分析,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
操作系统:CentOS 6.7
MySQL版本:5.6.30
·1.前期准备
·2.系统配置
·3.CMake编译配置
·4.make && make install
·5.后期配置和测试
·Reference
1.前期准备
首先需要CMake,可以yum直接安装:
yum install cmake
也可以官网https://cmake.org/下载源码编译。
我这里选择了官网下载最新版本cmake-3.5.2.tar.gz。
# tar -zxvfcmake-3.5.2.tar.gz && cd cmake-3.5.2
# ./configure
部分输出略。
-- Build files havebeen written to: /soft/cmake-3.5.2
---------------------------------------------
CMake hasbootstrapped. Now run gmake.
# gmake
# make install
2.系统配置
添加组和用户:
groupadd mysql
useradd -g mysqlmysql
vi/etc/security/limits.conf 文件末尾添加:
mysql softnproc 2047
mysql hardnproc 16384
mysql softnofile 1024
mysql hardnofile 65536
3.CMake编译配置
解压源码包:
tar zxvfmysql-5.6.30.tar.gz && cd mysql-5.6.30
CMake编译配置
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8\
-DDEFAULT_COLLATION=utf8_general_ci\
-DENABLED_LOCAL_INFILE=ON\
-DWITH_INNOBASE_STORAGE_ENGINE=1\
-DWITH_FEDERATED_STORAGE_ENGINE=1\
-DWITH_BLACKHOLE_STORAGE_ENGINE=1\
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1\
-DWITH_PARTITION_STORAGE_ENGINE=1\
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1\
-DCOMPILATION_COMMENT='JSSfor mysqltest' \
-DWITH_READLINE=ON\
-DSYSCONFDIR=/data/mysqldata/3306\
-DMYSQL_UNIX_ADDR=/data/mysqldata/3306/mysql.sock
遇到以下错误,
-- Could NOT findCurses (missing: CURSES_LIBRARYCURSES_INCLUDE_PATH)
CMake Error atcmake/readline.cmake:85 (MESSAGE):
Curses library not found. Please install appropriate package,
remove CMakeCache.txt and rerun cmake.OnDebian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it isncurses-devel.
Call Stack (mostrecent call first):
cmake/readline.cmake:128 (FIND_CURSES)
cmake/readline.cmake:202 (MYSQL_USE_BUNDLED_EDITLINE)
CMakeLists.txt:421 (MYSQL_CHECK_EDITLINE)
-- Configuringincomplete, errors occurred!
See also "/soft/mysql-5.6.30/CMakeFiles/CMakeOutput.log".
See also"/soft/mysql-5.6.30/CMakeFiles/CMakeError.log".
[root@JY-DBmysql-5.6.30]#
yum安装提示缺失的包:
yum install ncurses-devel
重新删除配置文件:
rm -rf CMakeCache.txt
然后重新CMake工具编译:
CMake Warning:
Manually-specified variables were not used by the project:
WITH_READLINE
-- Build files havebeen written to: /soft/mysql-5.6.30
[root@JY-DB mysql-5.6.30]#
4.make &&make install
[root@JY-DB mysql-5.6.30]# make && make install
大量输出略。
这个时间会比较长,也跟机器性能有关。
5.后期配置和测试
5.1 打包MySQL二进制版本:
[root@JY-DB data]# tarzcvf mysql-5.6.30.tar.gz /usr/local/mysql/
5.2 修改MySQL软件所在目录拥有者:
chown -R mysql.mysql /usr/local/mysql
5.3 修改mysql用户环境变量:
vi ~/.bash_profile
exportLANG=zh_CN.GB18030
exportPATH=/usr/local/mysql/bin:$PATH
5.4 创建数据库服务:
# mkdir -p/data/mysqldata/{3306/{data,tmp,binlog},backup,scripts}
# chown -Rmysql.mysql /data/mysqldata
# su - mysql
$ more/usr/local/mysql/support-files/my-default.cnf
$ vi/data/mysqldata/3306/my.cnf
my.cnf配置文件内容如下:
[client]
port = 3306
socket = /data/mysqldata/3306/mysql.sock
#The MySQL Server
[mysqld]
port = 3306
user = mysql
socket =/data/mysqldata/3306/mysql.sock
pid-file =/data/mysqldata/3306/mysql.pid
basedir =/usr/local/mysql
datadir =/data/mysqldata/3306/data
tmpdir =/data/mysqldata/3306/tmp
open_files_limit =10240
explicit_defaults_for_timestamp
sql_mode =NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
#Buffer
max_allowed_packet =256M
max_heap_table_size =256M
net_buffer_length =8k
sort_buffer_size = 2M
join_buffer_size = 4M
read_buffer_size = 2M
read_rnd_buffer_size= 16M
#Log
log-bin =/data/mysqldata/3306/binlog/mysql-bin
binlog_cache_size =32M
max_binlog_cache_size= 512M
max_binlog_size =512M
binlog_format = mixed
log_output = FILE
log-error =../mysql-error.log
slow_query_log = 1
slow_query_log_file =../slow_query.log
general_log = 0
general_log_file =../general_query.log
expire-logs-days = 14
#InnoDB
innodb_data_file_path= ibdata1:2048M:autoextend
innodb_log_file_size= 256M
innodb_log_files_in_group= 3
innodb_buffer_pool_size= 1024M
[mysql]
no-auto-rehash
prompt =(\u@\h)[\d]>\_
default-character-set= gbk
初始化MySQL数据库:
$ /usr/local/mysql/scripts/mysql_install_db--datadir=/data/mysqldata/3306/data --basedir=/usr/local/mysql
5.5 启动数据库服务:
mysqld_safe --defaults-file=/data/mysqldata/3306/my.cnf&
测试连接并查看MySQL进程和端口监听状态:
netstat -lnt | grep 3306
ps -ef | grepbin/mysql | grep -v grep
实际操作过程如下:
[root@JY-DB ~]# su - mysql
[mysql@JY-DB ~]$mysql
Welcome to the MySQLmonitor. Commands end with ; or \g.
Your MySQL connectionid is 1
Server version: 5.6.30-log JSS for mysqltest
Copyright (c) 2000,2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registeredtrademark of Oracle Corporation and/or its
affiliates. Othernames may be trademarks of their respective
owners.
Type 'help;' or '\h'for help. Type '\c' to clear the current input statement.
(root@localhost)[(none)]>exit
Bye
[mysql@JY-DB ~]$netstat -lnt |grep 3306
tcp 00 :::3306 :::* LISTEN
[mysql@JY-DB~]$
[mysql@JY-DB ~]$ ps-ef | grep bin/mysql | grep -v grep
mysql 67361753 0 11:24 pts/0 00:00:00 /bin/sh/usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysqldata/3306/my.cnf
mysql 72026736 0 11:24 pts/0 00:00:00 /usr/local/mysql/bin/mysqld--defaults-file=/data/mysqldata/3306/my.cnf --basedir=/usr/local/mysql--datadir=/data/mysqldata/3306/data --plugin-dir=/usr/local/mysql/lib/plugin--log-error=/data/mysqldata/3306/data/../mysql-error.log--open-files-limit=10240 --pid-file=/data/mysqldata/3306/mysql.pid--socket=/data/mysqldata/3306/mysql.sock --port=3306
以上是“MySQL源码安装的示例分析”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。