上手VPS之编译安装mysql

By | 2013年3月14日

安装的版本为最新的5.6.10。

首先安装几个必要的包(针对我自己的VPS环境)

yum install ncurses-devel.x86_64 gcc-c++.x86_64 bison

使用cmake安装mysql,以前的版本用configure,现在5.6.X版本都用cmake。

cmake . -DCMAKE_INSTALL_PREFIX=/opt/ProgramFiles/mysql
	-DSYSCONFDIR=/opt/ProgramFiles/mysql/cnf
	-DDEFAULT_CHARSET=utf8
	-DWITH_EXTRA_CHARSETS=complex
       -DDEFAULT_COLLATION=utf8_general_ci
	-DMYSQL_DATADIR=/opt/mysqldata
       -DMYSQL_TCP_PORT=1316
	-DMYSQL_UNIX_ADDR=/var/cache/mysql/mysql.sock
	-DENABLED_PROFILING=on
       -DWITHOUT_PERFSCHEMA_STORAGE_ENGINE=1
       -DWITH_INNOBASE_STORAGE_ENGINE=on
       -DWITH_SSL=bundled
	-DWITH_ZLIB=bundled
make
make install

创建mysql使用的用户与组

groupadd mysql
useradd -r -g mysql mysql

复制下init脚本,方便管理mysql

cp /opt/ProgramFiles/mysql/support-files/mysql.server /etc/init.d/mysql

初始化数据库

chown -R mysql:mysql /opt/ProgramFiles/mysql/
/opt/ProgramFiles/mysql/scripts/mysql_install_db --user=mysql
chown -R root:root /opt/ProgramFiles/mysql/

运行安全工具,配置root密码等

service mysql start
/opt/ProgramFiles/mysql/bin/mysql_secure_installation

至此,安装就完成了。

我还修改了环境变量,便于随时执行mysql命令。

vim /etc/profile

#文件底部,加入
PATH=$PATH:/opt/ProgramFiles/mysql/bin
export PATH

#保存关闭后
source /etc/profile

修改配置文件,我的文件my.cnf:

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html

[client]
port = 3345
socket = /var/cache/mysql/mysql.sock

[mysqld]
port = 3345
bind_address = 0.0.0.0
server_id = 1
basedir = /opt/ProgramFiles/mysql
datadir = /opt/mysqldata
socket = /var/cache/mysql/mysql.sock
#pid-file = /var/cache/mysql/mysql.pid
#log-error = /var/log/mysql/error.log

character-set-server = utf8

skip-name-resolve
skip-innodb
#skip-networking
#log-bin = /data/mysqldata/binlog/mysql-bin
#binlog_format = mixed
#binlog_cache_size = 4M
#max_binlog_cache_size = 8M
#max_binlog_size = 1G
#expire_logs_days = 90
#binlog-ignore-db = mysql
#binlog-ignore-db = test
#binlog-ignore-db = information_schema

#4G memory=256~384M
key_buffer_size = 8M
sort_buffer_size = 512K
read_buffer_size = 2M

#16G memory=16M
read_rnd_buffer_size = 4M

#16G memory=2M
join_buffer_size = 256K
thread_cache_size = 10
query_cache_size = 1M
query_cache_limit = 2M
query_cache_min_res_unit = 4k

#CPU's*2
thread_concurrency = 2

#table_cache = 720
table_open_cache = 720

#max_connections*5 / max_connections + table_cache*2
open_files_limit = 1000
back_log = 80
max_connections = 100
max_connect_errors = 200
external-locking = FALSE

max_allowed_packet = 16M
default-storage-engine = MyISAM
default_tmp_storage_engine = MyISAM
thread_stack = 192K
transaction_isolation = READ-COMMITTED

#16G memory=256M
tmp_table_size = 4M

#16G memory=512M
max_heap_table_size = 32M

#16G memory=64M
bulk_insert_buffer_size = 4M

#16G memory=64M
myisam_sort_buffer_size = 8M

myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover

#interactive_timeout = 120
#wait_timeout = 120

#long_query_time = 2
#log-slow-queries = /data/mysqldata/log/slow.log

server-id = 1

#innodb_additional_mem_pool_size = 16M
#innodb_buffer_pool_size = 512M
#innodb_data_file_path = ibdata1:256M:autoextend
#innodb_file_io_threads = 4
#innodb_thread_concurrency = 8
#innodb_flush_log_at_trx_commit = 2
#innodb_log_buffer_size = 16M
#innodb_log_file_size = 128M
#innodb_log_files_in_group = 3
#innodb_max_dirty_pages_pct = 90
#innodb_lock_wait_timeout = 120
#innodb_file_per_table = 0

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysqldump]
quick
max_allowed_packet = 32M
[mysql]
no-auto-rehash

参考这篇文章:http://www.1987.name/515.html