Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1986966
  • 博文数量: 176
  • 博客积分: 1857
  • 博客等级: 上尉
  • 技术积分: 2729
  • 用 户 组: 普通用户
  • 注册时间: 2012-04-14 22:55
个人简介

吾生有涯,而知无涯,适当止学.循序渐进,步步提升 Talk is cheap, show me the code.

文章分类

全部博文(176)

文章存档

2019年(1)

2018年(14)

2017年(20)

2016年(31)

2015年(15)

2014年(5)

2013年(10)

2012年(80)

分类: Mysql/postgreSQL

2012-08-24 14:12:33

添加用户和用户组

点击(此处)折叠或打开

  1. groupadd mysql

  2. useradd -g mysql mysql

解压mysql文件&0编译源代码

点击(此处)折叠或打开

  1. tar zxvf mysql-5.1.65.tar.gz

  2. cd mysql-5.1.65


  3. ./configure --prefix=/usr/local/mysql/ --with-server-suffix=-zsd-edition --enable-assembler --enable-local-infile --enable-thread-safe-client --with-big-tables --with-charset=utf8 --with-extra-charsets=gbk,gb2312,utf8,ascii --with-readline --with-ssl --with-embedded-server --with-pthread --with-mysqld-user=mysql --with-mysqld-ldflags=-all-static --with-client-ldflags=-all-static --with-plugins=partition,innobase,innodb_plugin > /root/mysql_setuplogs_configure.log 2>&1

查看/root/mysql_setuplogs_configure.log,如果出现libtool的问题,按下述方法可解决

查看libtool是否已经安装。

1、确认libtool是否已经安装,如果没有安装的话,则先安装libtool

点击(此处)折叠或打开

  1. # rpm -qa | grep libtool

  2. # yum -y install libtool
2、分别执行以下三条命令:

点击(此处)折叠或打开

  1. # autoreconf --force --install

  2. # libtoolize --automake --force

  3. # automake --force --add-missing

make&安装:

点击(此处)折叠或打开

  1. make > /root/mysql_setuplogs_make.log 2>&1

  2. make install > /root/mysql_setuplogs_makeinstall.log 2>&1

修改相关路径权限:

点击(此处)折叠或打开

  1. cd /usr/local/

  2. chown -R mysql:mysql mysql

  3. mkdir -p /data/mysqldata/3306
  4. cd /data/mysqldata/3306
  5. mkdir data binlog tmp innodb_ts innodb_log

  6. chown -R mysql:mysql ./
创建mysql_install_db

点击(此处)折叠或打开

  1. /usr/local/mysql/bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysqldata/3306/data

配置my.cnf


点击(此处)折叠或打开

  1. vi /data/mysqldata/3306/my.cnf



  2. [client]
  3. port = 3306
  4. socket = /data/mysqldata/3306/mysql.sock
  5. character-set-server = utf8

  6. # Here follows entries for some specific programs

  7. # The MySQL server
  8. [mysqld]
  9. port = 3306
  10. user = mysql
  11. socket = /data/mysqldata/3306/mysql.sock
  12. pid-file = /data/mysqldata/3306/mysql.pid
  13. basedir = /usr/local/mysql
  14. datadir = /data/mysqldata/3306/data
  15. tmpdir = /data/mysqldata/3306/tmp
  16. open_files_limit = 10240
  17. server-id = 1333306
  18. lower_case_table_names = 1
  19. character-set-server = utf8
  20. skip-name-resolve

  21. max_connections = 3000
  22. max_connect_errors = 6000
  23. max_allowed_packet = 512M
  24. max_heap_table_size = 1024M
  25. max_length_for_sort_data = 4096
  26. back_log=100
  27. interactive_timeout = 600
  28. wait_timeout = 600

  29. default-storage-engine = InnoDB

  30. net_buffer_length = 8K
  31. sort_buffer_size = 2M
  32. join_buffer_size = 4M
  33. read_buffer_size = 2M
  34. read_rnd_buffer_size = 16M

  35. query_cache_size = 128M
  36. query_cache_limit = 2M
  37. query_cache_min_res_unit = 2k

  38. thread_cache_size = 300
  39. table_open_cache = 1024
  40. tmp_table_size = 256M

  41. #*********** Logs related settings ***********
  42. log-bin = /data/mysqldata/3306/binlog/mysql-bin
  43. log-slave-updates =1
  44. binlog_format=statement
  45. binlog_cache_size=32m
  46. max_binlog_cache_size=512m
  47. max_binlog_size=512m
  48. long_query_time = 3
  49. log_output = FILE
  50. log-error = /data/mysqldata/3306/mysql-error.log
  51. slow_query_log = 1
  52. slow_query_log_file = /data/mysqldata/3306/slow_statement.log
  53. log_queries_not_using_indexes
  54. general_log = 0
  55. general_log_file = /data/mysqldata/3306/general_statement.log
  56. expire-logs-days = 14

  57. #*********** MyISAM Specific options ***********
  58. key_buffer_size = 32M
  59. bulk_insert_buffer_size = 64M
  60. myisam_sort_buffer_size = 128M
  61. myisam_max_sort_file_size = 10G
  62. myisam_repair_threads = 1
  63. myisam_recover

  64. #*********** INNODB Specific options ***********
  65. innodb_file_per_table
  66. transaction-isolation = READ-COMMITTED

  67. innodb_additional_mem_pool_size = 16M
  68. innodb_buffer_pool_size = 1024M
  69. innodb_data_home_dir = /data/mysqldata/3306/innodb_ts
  70. innodb_data_file_path = ibdata1:2048M:autoextend

  71. innodb_file_io_threads = 4
  72. innodb_thread_concurrency = 0
  73. innodb_log_buffer_size = 16M
  74. innodb_log_file_size = 256M
  75. innodb_log_files_in_group = 2

  76. innodb_log_group_home_dir = /data/mysqldata/3306/innodb_log
  77. innodb_flush_log_at_trx_commit = 2
  78. innodb_max_dirty_pages_pct = 80
  79. innodb_lock_wait_timeout = 120
  80. innodb_flush_method=O_DIRECT

  81. [mysqldump]
  82. quick
  83. max_allowed_packet = 512M

  84. [mysql]
  85. no-auto-rehash
  86. # Remove the next comment character if you are not familiar with SQL
  87. #safe-updates

  88. [myisamchk]
  89. key_buffer_size = 32M
  90. sort_buffer_size = 20M
  91. read_buffer_size = 2M
  92. write_buffer_size = 2M

  93. [mysqlhotcopy]
  94. interactive-timeout

  95. [mysqld_safe]
  96. open-files-limit = 8192

启动mysql服务:

点击(此处)折叠或打开

  1. /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysqldata/3306/my.cnf &

进入mysql:

点击(此处)折叠或打开

  1. /usr/local/mysql/bin/mysql -uroot -S /data/mysqldata/3306/mysql.sock

关闭mysql:

点击(此处)折叠或打开

  1. /usr/local/mysql/bin/mysqladmin -uroot -S /data/mysqldata/3306/mysql.sock shutdown

安装mysql后,对安全性做一点设置:

(1)删除掉不安全的用户:

点击(此处)折叠或打开

  1. drop user ''@'localhost';
  2. drop user ''@'mysql-n1';

(2)为root用户设置密码:(以root用户登录)

点击(此处)折叠或打开

  1. set password=password('zsd0507');

设置环境变量:

点击(此处)折叠或打开

  1. sudo su - mysql

  2. vi /home/mysql/.bash_profile

  3. umask 022

  4. MYSQL_BASE=/usr/local/mysql
  5. MYSQL_HOME=/usr/local/mysql

  6. PATH=$MYSQL_BASE/bin:$PATH

  7. export PATH
  8. export MYSQL_BASE MYSQL_HOME

  9. 使得环境变量生效:

  10. source /home/mysql/.bash_profile

设置启动脚本(让它跟系统一起自动启动)


点击(此处)折叠或打开

  1. cd /etc/init.d

  2. vi mysql

#!/bin/sh

mysql_port=3306
mysql_username="root"
mysql_password="zsd0507"

function_start_mysql()
{
    printf "Starting MySQL...\n"
    /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysqldata/

${mysql_port}/my.cnf 2>&1 > /dev/null &
}

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

/data/mysqldata/${mysql_port}/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: /data/mysqldata/${mysql_port}/mysql {start|stop|restart|

kill}\n"
fi

  1. chmod 755 mysql

到此,全部结束!~



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