[关闭]
@code33 2016-01-07T14:20:35.000000Z 字数 4683 阅读 813

Mysql 生产安装,配置,维护(1)

技术文档 mysql

以下配置参数与centOS6.x 下测试通过
此版本基于mysq.5.6.23
create by jyo
code0515@gmail.com
2016-01-07


基本类库依赖

  1. yum -y install gcc gcc-c++ autoconf automake zlib libxml* ncurses-devel bison-devel libtool

安装Cmake

  1. cd /usr/local/src/
  2. wget http://www.cmake.org/files/v3.3/cmake-3.3.1.tar.gz
  3. tar zxvf cmake-3.3.1.tar.gz
  4. cd cmake-3.3.1
  5. ./bootstrap
  6. gmake
  7. gmake install

编译安装mysql

  1. groupadd mysql
  2. useradd -g mysql mysql
  3. mkdir -p /usr/local/mysql
  4. mkdir -p /usr/local/mysql/data
  5. chown mysql:mysql -R /usr/local/mysql
  6. chown mysql:mysql -R /usr/local/mysql/data
  1. tar zxvf mysql-5.6.26.tar.gz
  2. cd mysql-5.6.26
  3. cmake -L
  4. cmake -LH 查看参数
  1. cmake \
  2. -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
  3. -DMYSQL_DATADIR=/usr/local/mysql/data \
  4. -DSYSCONFDIR=/etc \
  5. -DWITH_MYISAM_STORAGE_ENGINE=1 \
  6. -DWITH_INNOBASE_STORAGE_ENGINE=1 \
  7. -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
  8. -DMYSQL_TCP_PORT=3306 \
  9. -DENABLED_LOCAL_INFILE=1 \
  10. -DWITH_PARTITION_STORAGE_ENGINE=1 \
  11. -DEXTRA_CHARSETS=all \
  12. -DDEFAULT_CHARSET=utf8 \
  13. -DDEFAULT_COLLATION=utf8_general_ci
  1. make && make install

初始化数据库

  1. cp support-files/mysql.server /etc/init.d/mysql
  2. chmod 775 /etc/init.d/mysql
  3. chkconfig mysql on
  4. export PATH=/usr/local/mysql/bin:$PATH
  5. /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
  6. service mysql start

开机启动

  1. echo 'export PATH=/usr/local/mysql/bin:$PATH' >> /etc/profile

设置密码

  1. /usr/local/mysql/bin/mysqladmin -u root password "fuckgfw"

防火墙开放端口

vim /etc/sysconfig/iptables

  1. iptables -I INPUT -p tcp --dport 3888 -j ACCEPT

防火墙重启

service iptables restart

防火墙查看

service iptables status

查看开机是否自动启动

  1. chkconfig --list | grep mysql

进入数据库

  1. mysql -uroot -pfuckgfw -P 3888

my.cnf启动参数脚本

将此脚本建立到 /etc/my.cnf

  1. # Example MySQL config file for medium systems.
  2. #
  3. # This is for a system with little memory (32M - 64M) where MySQL plays
  4. # an important part, or systems up to 128M where MySQL is used together with
  5. # other programs (such as a web server)
  6. #
  7. # MySQL programs look for option files in a set of
  8. # locations which depend on the deployment platform.
  9. # You can copy this option file to one of those
  10. # locations. For information about these locations, see:
  11. # http://dev.mysql.com/doc/mysql/en/option-files.html
  12. #
  13. # In this file, you can use all long options that a program supports.
  14. # If you want to know which options a program supports, run the program
  15. # with the "--help" option.
  16. # The following options will be passed to all MySQL clients
  17. [client]
  18. #password = your_password
  19. port = 3888
  20. socket = /tmp/mysql.sock
  21. default-character-set=utf8
  22. # Here follows entries for some specific programs
  23. # The MySQL server
  24. [mysqld]
  25. character-set-server=utf8
  26. port = 3888
  27. socket = /tmp/mysql.sock
  28. datadir = /usr/local/mysql/data
  29. skip-external-locking
  30. max_connections = 1000
  31. key_buffer_size = 16M
  32. max_allowed_packet = 1M
  33. table_open_cache = 64
  34. sort_buffer_size = 512K
  35. net_buffer_length = 8K
  36. read_buffer_size = 256K
  37. read_rnd_buffer_size = 512K
  38. myisam_sort_buffer_size = 8M
  39. # Don't listen on a TCP/IP port at all. This can be a security enhancement,
  40. # if all processes that need to connect to mysqld run on the same host.
  41. # All interaction with mysqld must be made via Unix sockets or named pipes.
  42. # Note that using this option without enabling named pipes on Windows
  43. # (via the "enable-named-pipe" option) will render mysqld useless!
  44. #
  45. #skip-networking
  46. # Replication Master Server (default)
  47. # binary logging is required for replication
  48. log-bin=mysql-bin
  49. # binary logging format - mixed recommended
  50. binlog_format=mixed
  51. # required unique id between 1 and 2^32 - 1
  52. # defaults to 1 if master-host is not set
  53. # but will not function as a master if omitted
  54. server-id = 1
  55. #loose-innodb-trx=0
  56. #loose-innodb-locks=0
  57. #loose-innodb-lock-waits=0
  58. #loose-innodb-cmp=0
  59. #loose-innodb-cmp-per-index=0
  60. #loose-innodb-cmp-per-index-reset=0
  61. #loose-innodb-cmp-reset=0
  62. #loose-innodb-cmpmem=0
  63. #loose-innodb-cmpmem-reset=0
  64. #loose-innodb-buffer-page=0
  65. #loose-innodb-buffer-page-lru=0
  66. #loose-innodb-buffer-pool-stats=0
  67. #loose-innodb-metrics=0
  68. #loose-innodb-ft-default-stopword=0
  69. #loose-innodb-ft-inserted=0
  70. #loose-innodb-ft-deleted=0
  71. #loose-innodb-ft-being-deleted=0
  72. #loose-innodb-ft-config=0
  73. #loose-innodb-ft-index-cache=0
  74. #loose-innodb-ft-index-table=0
  75. #loose-innodb-sys-tables=0
  76. #loose-innodb-sys-tablestats=0
  77. #loose-innodb-sys-indexes=0
  78. #loose-innodb-sys-columns=0
  79. #loose-innodb-sys-fields=0
  80. #loose-innodb-sys-foreign=0
  81. #loose-innodb-sys-foreign-cols=0
  82. # Uncomment the following if you are using InnoDB tables
  83. innodb_data_home_dir = /usr/local/mysql/data
  84. innodb_data_file_path = ibdata1:100M:autoextend
  85. innodb_log_group_home_dir = /usr/local/mysql/data
  86. # You can set .._buffer_pool_size up to 50 - 80 %
  87. # of RAM but beware of setting memory usage too high
  88. innodb_buffer_pool_size = 16M
  89. innodb_additional_mem_pool_size = 2M
  90. # Set .._log_file_size to 25 % of buffer pool size
  91. innodb_log_file_size = 5M
  92. innodb_log_buffer_size = 8M
  93. innodb_flush_log_at_trx_commit = 1
  94. innodb_lock_wait_timeout = 50
  95. skip-name-resolve
  96. [mysqldump]
  97. quick
  98. max_allowed_packet = 16M
  99. [mysql]
  100. default-character-set=utf8
  101. no-auto-rehash
  102. # Remove the next comment character if you are not familiar with SQL
  103. #safe-updates
  104. [myisamchk]
  105. key_buffer_size = 20M
  106. sort_buffer_size = 20M
  107. read_buffer = 2M
  108. write_buffer = 2M
  109. [mysqlhotcopy]
  110. interactive-timeout
  111. expire_logs_days = 10

在此输入正文

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注