本文MYSQL配置是用于游戏服务器mysql配置的,当然有很多不足的地方,请各位多多指点指点
1.假设已经有mysql-5.5.25a.tar.gz以及cmake-2.8.8.tar.gz两个源文件
***mysql5.5以后是通过cmake来编译的
tar -zxv -f cmake-2.8.8.tar.gz
cd cmake-2.8.8
./configure
make && make install && make clean
mkdir -p /usr/local/mysql //安装mysql
mkdir -p /usr/local/mysql/data //存放数据库
groupadd mysql
useradd -r -g mysql mysql
tar -zxv -f mysql-5.5.25a.tar.gz
cd mysql-5.5.25a
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DENABLED_LOCAL_INFILE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DWITH_EMBEDDED_SERVER=1
make
make install
参数说明: ****更多说明http://blog.csdn.net/zhuoxiong/article/details/7831264
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql //安装目录
-DMYSQL_DATADIR=/usr/local/mysql/data //数据库存放目录
-DDEFAULT_CHARSET=utf8 //使用utf8字符
-DDEFAULT_COLLATION=utf8_general_ci //校验字符
-DEXTRA_CHARSETS=all //安装所有扩展字符集
-DENABLED_LOCAL_INFILE=1 //允许从本地导入数据
-DWITH_MYISAM_STORAGE_ENGINE //
-DWITH_INNOBASE_STORAGE_ENGINE //
-DWITH_READLINE
-DWITH_EMBEDDED_SERVER
注意事项:
重新编译时,需要清除旧的对象文件和缓存信息。
# make clean
# rm -f CMakeCache.txt
# rm -rf /etc/my.cnf
2.配置
cd /usr/local/mysql
chown -R root:mysql . //把当前目录中所有文件的所有者所有者设为root,所属组为mysql
chown -R mysql:mysql data
chgrp -R mysql .
cp support-files/my-medium.cnf /etc/my.cnf //将mysql的启动服务添加到系统服务中
设置环境变量
vi /root/.bash_profile
在PATH=$PATH:$HOME/bin添加参数为:
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin:/usr/local/mysql/lib64 //注意,这里的lib64看你的系统位数
source /root/.bash_profile
创建系统数据库的表
cd /usr/local/mysql
scripts/mysql_install_db --user=mysql
bin/mysqld_safe --user=mysql &
ln -sf /usr/local/mysql/bin/mysql /usr/local/bin/mysql
ln -sf /usr/local/mysql/bin/mysqldump /usr/local/bin/mysqldump
ln -sf /usr/local/mysql/bin/mysqladmin /usr/local/bin/mysqladmin
ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/ //注意,这里的lib64看你的系统位数
启动日志写在此文件下:/usr/local/mysql/data/localhost.err
关闭MySQL服务
mysqladmin -u root -p shutdown //这里MySQL的root用户还没有配置密码,所以为空值。需要输入密码时,直接点回车键即可。
cp support-files/mysql.server /etc/init.d/mysqld //将mysql的启动服务添加到系统服务中
chmod 755 /etc/init.d/mysqld
测试启动 service mysqld restart
mysql配置 引擎为innodb
mkdir /usr/local/mysql/data_innodb
chown mysql:mysql -R data_innodb
chmod 777 -R data_innodb
*********************my.cnf 配置 begin *********************
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
user = mysql
[client]
#password = your_password
port = 3306
socket = /tmp/mysql.sock
[mysqld]
port = 3306
socket = /tmp/mysql.sock
datadir = /usr/local/mysql/data
user = mysql
server-id = 1
interactive_timeout=100
#slave-skip-errors=1062
max_heap_table_size = 128M
skip-name-resolve
skip-external-locking
back_log = 400
key_buffer_size = 256M
max_allowed_packet = 256M
thread_stack = 192K
table_open_cache = 1300
sort_buffer_size = 6M
read_buffer_size = 1M
join_buffer_size = 2M
net_buffer_length = 8K
read_rnd_buffer_size = 2M
bulk_insert_buffer_size = 16M
myisam_repair_threads = 1
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 2G
thread_cache_size = 200
query_cache_size = 128M
query_cache_limit = 2M
query_cache_min_res_unit = 2k
tmp_table_size = 128M
max_connections = 1000
max_connect_errors = 1000000000
transaction_isolation = READ-UNCOMMITTED
slow_query_log
slow_query_log_file = /usr/local/mysql/data/slowsql
long_query_time = 0.5
log_queries_not_using_indexes
external-locking = FALSE
thread_concurrency = 8
myisam_recover
#default-character-set=utf8 #old version format
sql_mode=''
character-set-server=utf8
collation-server=utf8_general_ci
init_connect="SET NAMES 'utf8'"
#skip-networking
log-bin=mysql-bin
max_binlog_size=100M
binlog_format=mixed
binlog_cache_size=16M
max_binlog_cache_size=32M
#binlog-do-db=
binlog-ignore-db=Dice_logs,Dicetest_logs
#expire_logs_days = 1
#skip-federated
#master-host = <hostname>
#master-user = <username>
# the master - required
#master-password = <password>
# optional - defaults to 3306
#master-port = <port>
innodb_data_home_dir = /usr/local/mysql/data_innodb
innodb_use_sys_malloc=1
innodb_buffer_pool_size = 256M
innodb_data_file_path = ibdata1:1000M;ibdata2:1000M:autoextend
innodb_file_io_threads = 4
innodb_thread_concurrency = 8
innodb_flush_log_at_trx_commit = 0
innodb_log_buffer_size = 16M
innodb_log_file_size = 512M
innodb_log_files_in_group = 3
innodb_lock_wait_timeout = 10
innodb_file_per_table = 1
[mysqldump]
quick
max_allowed_packet = 2048M
[mysql]
no-auto-rehash
[isamchk]
key_buffer = 256M
sort_buffer_size = 128M
read_buffer = 2M
write_buffer = 2M
[myisamchk]
key_buffer_size = 256M
sort_buffer_size = 128M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
#skip-federated
*********************my.cnf 配置 end *********************