一、安装前准备
下载MySQL源码安装包 http://dev.mysql.com/downloads/mysql/ 需要有oracle账户登录下载
同时需要下载与MySQL版本对应的boost,下载地址:http://sourceforge.net/projects/boost/files/boost/
安装cmake:yum install -y cmake ncurses-devel
创建MySQL用户
groupadd mysql
useradd -g mysql -d /usr/local/mysql mysql
二、将MySQL源码包以及boost_1_57_0.tar.gz上传到服务器上,并解压
tar zxvf boost_1_59_0.tar.gz && mv boost_1_59_0/* boost/
tar zxvf mysql-5.7.10.tar.gz && cd mysql-5.7.10
三、编译安装
cmake -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr/local/mysql -DCOMMUNITY_BUILD:BOOL=ON -DENABLED_PROFILING:BOOL=ON -DENABLE_DEBUG_SYNC:BOOL=OFF -DINSTALL_LAYOUT:STRING=STANDALONE -DMYSQL_DATADIR:PATH=/data/mysql/db -DMYSQL_MAINTAINER_MODE:BOOL=OFF -DWITH_EMBEDDED_SERVER:BOOL=ON -DWITH_EXTRA_CHARSETS:STRING=all -DWITH_SSL:STRING=bundled -DWITH_UNIT_TESTS:BOOL=OFF -DWITH_BOOST=/usr/local/mysql/boost/ && gmake && gmake install
四、创建相关目录
mkdir -p /data/mysql/sock
mkdir -p /data/mysql/run
mkdir -p /data/mysql/db
mkdir -p /data/mysql/tmp
mkdir -p /data/mysql/logs
mkdir -p /data/mysql/binlogs
mkdir -p /data/mysql/binlogs/mysql-bin
mkdir -p /data/mysql/innodb
mkdir -p /usr/local/mysql/etc
chown -R mysql.mysql /usr/local/mysql
chown -R mysql.mysql /data/mysql
五、创建配置文件:/usr/local/mysql/etc/my.cnf
#++++++++++++++++++++++++++++++++ multi ++++++++++++++++++++++++++
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
use = root
log = /usr/local/mysql/logs/multi.log
#+++++++++++++++++++++++++++++++client+++++++++++++++++++++++++++
[client]
default-character-set = utf8
#+++++++++++++++++++++++++++++mysql+++++++++++++++++++++++++++++
[mysql]
prompt = mysql(\\u@\h-\R:\\m:\\s [\\d])>
#提示当前数据库操作用户名、库名、时间等
default-character-set=utf8
#++++++++++++++++++++++++++++++++++monitor++++++++++++++++++++++++++
[mysqld]
user = mysql
#Add at 2014/05/21
init_connect='SET collation_connection = utf8_general_ci; SET NAMES utf8;'
port = 3307
character-set-server=utf8
collation-server = utf8_general_ci
socket = /data/mysql/sock/mysql.sock
pid-file = /data/mysql/run/mysql.pid
datadir = /data/mysql/db
tmpdir = /data/mysql/tmp
big_tables
skip_external_locking
skip-name-resolve
lower_case_table_names = 1
back_log = 2048
max_connections = 3000
max_connect_errors = 100000
interactive_timeout = 28800
wait_timeout = 28800
max_allowed_packet = 32M
max_heap_table_size = 128M
tmp_table_size = 128M
max_length_for_sort_data = 8072
net_buffer_length = 1M
sort_buffer_size = 4M
join_buffer_size = 4M
read_buffer_size = 2M
read_rnd_buffer_size = 16M
table_open_cache = 2048
thread_cache_size = 64
#thread_concurrency = 12
query_cache_type = 0
query_cache_size = 64M
query_cache_limit = 4M
#******************************* Logs related settings ***************************
log-error = /data/mysql/logs/error.log
log_warnings
long_query_time = 1
slow_query_log
slow_query_log_file = /data/mysql/logs/slow-query.log
log_queries_not_using_indexes
binlog_cache_size = 8M
max_binlog_size = 512M
log-bin = /data/mysql/binlogs/mysql-bin
log-bin-index = /data/mysql/binlogs/mysql-bin.index
expire_logs_days = 60
#******************************* Replication related settings **********************
server-id = 1
report_port = 3307
report_user = repl
slave_net_timeout = 60
sync_binlog = 1
binlog-format = ROW
#Change at 2014/05/21
transaction_isolation = READ-COMMITTED
slave-skip-errors = 1062
#******************************* MyISAM Specific options ****************************
key_buffer_size = 32M
bulk_insert_buffer_size = 16M
myisam_sort_buffer_size = 64M
myisam_max_sort_file_size = 1G
myisam_repair_threads = 1
#myisam_recover
#***************************** INNODB Specific options ******************************
innodb_file_per_table = 1
innodb_flush_log_at_trx_commit = 1
innodb_autoinc_lock_mode = 1
innodb_fast_shutdown = 0
#innodb_additional_mem_pool_size = 64M
innodb_buffer_pool_size = 2G
innodb_data_home_dir = /data/mysql/innodb
innodb_data_file_path = ibdata1:256M:autoextend
#innodb_file_io_threads = 8
innodb_thread_concurrency = 4
innodb_log_buffer_size = 8M
innodb_log_file_size = 128M
innodb_log_group_home_dir = /data/mysql/innodb
#Change at 2014/05/21
#innodb_max_dirty_pages_pct = 20
innodb_max_dirty_pages_pct = 30
innodb_lock_wait_timeout = 120
innodb_flush_method=O_DIRECT
[mysqldump]
quick
max_allowed_packet = 2048M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
六、数据库初始化
/usr/local/mysql/bin/mysqld --defaults-file=/usr/local/mysql/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql/db --explicit_defaults_for_timestamp --initialize
七、启动数据库
/usr/local/mysql/bin/mysqld_safe --defaults-extra-file=/usr/local/mysql/etc/my.cnf --user=mysql &
八、查看数据库初始root密码
cat /data/mysql/logs/error.log | grep password
九、修改数据库密码
mysqladmin -u root -p password 新密码 -S /data/mysql/sock/mysql.sock
十、登录数据库进行常用操作测试
/usr/local/mysql/bin/mysql -S /data/mysql/sock/mysql.sock -uroot -p
十一、配置系统环境信息,在/etc/profile添加以下信息
export MYSQL_HOME=/usr/local/mysql
export PATH=$JAVA_HOME/bin:$MYSQL_HOME/bin:$PATH
十二、在/usr/local/mysql/script路径下创建以下脚本便于日常运维管理操作
进程查看脚本:ps.sh
#/bin/sh
ps -ef | grep mysql
启动脚本:start.sh
#/bin/sh
/usr/local/mysql/bin/mysqld_safe --defaults-extra-file=/usr/local/mysql/etc/my.cnf --user=mysql &
停止脚本:stop.sh
#/bin/sh
/usr/local/mysql/bin/mysqladmin -S /data/mysql/sock/mysql.sock -uroot shutdown
登录数据库脚本:connect.sh
#/bin/sh
/usr/local/mysql/bin/mysql -S /data/mysql/sock/mysql.sock -uroot -p
查看错误日志脚本:tailerrog.sh
#/bin/sh
echo "显示最近两百行日志"
tail -200 /data/mysql/logs/tailerrorlog.log
查看慢查询日志脚本:tailslowlog.sh
#/bin/sh
echo "显示最近两百行日志"
tail -200 /data/mysql/logs/slow-query.log
本文转自aaron428 51CTO博客,原文链接:http://blog.51cto.com/aaronsa/1740632,如需转载请自行联系原作者