Chinaunix首页 | 论坛 | 博客
  • 博客访问: 81934
  • 博文数量: 35
  • 博客积分: 1772
  • 博客等级: 上尉
  • 技术积分: 375
  • 用 户 组: 普通用户
  • 注册时间: 2010-04-08 14:39
文章分类
文章存档

2012年(1)

2011年(16)

2010年(18)

我的朋友

分类: LINUX

2010-05-05 11:11:15

升级系统先

yum -y install gcc gcc-c++ ncurses ncurses-devel


下载MYSQL

wget http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.46.tar.gz/from/http://mysql.cdpa.nsysu.edu.tw/


创建用户和组

groupadd mysql
useradd -g mysql mysql


编译安装

./configure --prefix=/usr/local/mysql --without-debug --with-charset=utf8 --with-extra-charsets=gbk,gb2312,utf8 --with-unix-socket-path=/tmp/mysql.sock --with-plugins=partition,innobase,myisammrg --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --with-big-tables --with-read-line --with-ssl --with-embedded-server --with-pthread --enable-thread-safe-client --enable-local-infile --enable-assembler

make

make install


创建数据库存储目录

mkdir -p /data0/mysql/3306/data
mkdir -p /data0/mysql/3306/binlog
mkdir -p /data0/mysql/3306/relaylog
chown -R mysql:mysql /data0/mysql/


初始化MYSQL表

/usr/local/mysql/bin/mysql_install_db --basedir=/usr/local/mysql --datadir=/data0/mysql/3306/data --user=mysql


创建MYSQL配置文件

vi /data0/mysql/3306/my.cnf



[client]
character-set-server = utf8
port = 3306
socket = /tmp/mysql.sock

[mysqld]
character-set-server = utf8
replicate-ignore-db = mysql
replicate-ignore-db = test
replicate-ignore-db = information_schema
user = mysql
port = 3306
socket = /tmp/mysql.sock
basedir = /usr/local/webserver/mysql
datadir = /data0/mysql/3306/data
log-error = /data0/mysql/3306/mysql_error.log
pid-file = /data0/mysql/3306/mysql.pid
open_files_limit = 10240
back_log = 600
max_connections = 5000
max_connect_errors = 6000
table_cache = 614
external-locking = FALSE
max_allowed_packet = 32M
sort_buffer_size = 1M
join_buffer_size = 1M
thread_cache_size = 300
thread_concurrency = 8
query_cache_size = 512M
query_cache_limit = 2M
query_cache_min_res_unit = 2k
default-storage-engine = MyISAM
thread_stack = 192K
transaction_isolation = READ-COMMITTED
tmp_table_size = 246M
max_heap_table_size = 246M
long_query_time = 3
log-slave-updates
log-bin = /data0/mysql/3306/binlog/binlog
binlog_cache_size = 4M
binlog_format = MIXED
max_binlog_cache_size = 8M
max_binlog_size = 1G
relay-log-index = /data0/mysql/3306/relaylog/relaylog
relay-log-info-file = /data0/mysql/3306/relaylog/relaylog
relay-log = /data0/mysql/3306/relaylog/relaylog
expire_logs_days = 30
key_buffer_size = 256M
read_buffer_size = 1M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover

interactive_timeout = 120
wait_timeout = 120

skip-name-resolve
master-connect-retry = 10
slave-skip-errors = 1032,1062,126,1114,1146,1048,1396

#master-host = 192.168.1.2
#master-user = username
#master-password = password
#master-port = 3306

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

#log-slow-queries = /data0/mysql/3306/slow.log
#long_query_time = 10

[mysqldump]
quick
max_allowed_packet = 32M


创建MYSQL启动脚本

vi /data0/mysql/3306/mysql



#!/bin/sh

mysql_port=3306
mysql_username="admin"
mysql_password="12345678"

function_start_mysql()
{
    printf "Starting MySQL...\n"
    /bin/sh /usr/local/webserver/mysql/bin/mysqld_safe --defaults-file=/data0/mysql/${mysql_port}/my.cnf 2>&1 > /dev/null &
}

function_stop_mysql()
{
    printf "Stoping MySQL...\n"
    /usr/local/webserver/mysql/bin/mysqladmin -u ${mysql_username} -p${mysql_password} -S /tmp/mysql.sock shutdown
}

function_restart_mysql()
{
    printf "Restarting MySQL...\n"
    function_stop_mysql
    sleep 5
    function_start_mysql
}

function_kill_mysql()
{
    kill -9 $(ps -ef |; grep 'bin/mysqld_safe' |; grep ${mysql_port} |; awk '{printf $2}')
    kill -9 $(ps -ef |; grep 'libexec/mysqld' |; grep ${mysql_port} |; awk '{printf $2}')
}

if [ "$1" = "start" ]; then
    function_start_mysql
elif [ "$1" = "stop" ]; then
    function_stop_mysql
elif [ "$1" = "restart" ]; then
function_restart_mysql
elif [ "$1" = "kill" ]; then
function_kill_mysql
else
    printf "Usage: /data0/mysql/${mysql_port}/mysql {start|stop|restart|kill}\n"
fi


修改执行权限

chmod +x /data0/mysql/3306/mysql


启动服务

/data0/mysql/3306/mysql start


登陆到MYSQL创建一个用户

GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' IDENTIFIED BY '12345678';
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'127.0.0.1' IDENTIFIED BY '12345678'


完毕~~
阅读(451) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~