Allow for much more configuration in my.cnf.

pull/63/head
Jeff Geerling 10 years ago
parent 4eaae0e43d
commit 80d6c797d4
  1. 17
      README.md
  2. 40
      defaults/main.yml
  3. 38
      files/my.cnf
  4. 8
      tasks/main.yml
  5. 53
      templates/my.cnf.j2
  6. 3
      templates/python-my.cnf.j2
  7. 7
      vars/main.yml

@ -31,6 +31,19 @@ The MySQL root user account password.
(RedHat/CentOS only) If you have enabled any additional repositories (might I suggest geerlingguy.repo-epel or geerlingguy.repo-remi), those repositories can be listed under this variable (e.g. `remi,epel`). This can be handy, as an example, if you want to install later versions of MySQL.
mysql_port: "3306"
mysql_datadir: /var/lib/mysql
mysql_socket: /var/lib/mysql/mysql.sock
Default MySQL connection configuration.
mysql_key_buffer_size: "256M"
mysql_max_allowed_packet: "1M"
mysql_table_open_cache: "256"
[...]
The rest of the settings in `defaults/main.yml` control MySQL's memory usage. The default values are tuned for a server where MySQL can consume ~512 MB RAM, so you should consider adjusting them to suit your particular server better.
## Dependencies
None.
@ -47,10 +60,6 @@ None.
mysql_root_password: super-secure-password
## TODO
- Convert my.cnf configuration to template, and allow for configurable variables.
## License
MIT / BSD

@ -0,0 +1,40 @@
---
mysql_user_home: /root
mysql_root_password: root
# Pass in a comma-separated list of repos to use (e.g. "remi,epel"). Used only
# for RedHat systems (and derivatives).
mysql_enablerepo: ""
# MySQL connection settings.
mysql_port: "3306"
mysql_datadir: /var/lib/mysql
mysql_socket: /var/lib/mysql/mysql.sock
# Memory settings (default values optimized ~512MB RAM).
mysql_key_buffer_size: "256M"
mysql_max_allowed_packet: "1M"
mysql_table_open_cache: "256"
mysql_sort_buffer_size: "1M"
mysql_read_buffer_size: "1M"
mysql_read_rnd_buffer_size: "4M"
mysql_myisam_sort_buffer_size: "64M"
mysql_thread_cache_size: "8"
mysql_query_cache_size: "16M"
# Try number of CPU's * 2 for thread_concurrency.
mysql_thread_concurrency: 2
# InnoDB settings.
# Set .._buffer_pool_size up to 80% of RAM but beware of setting too high.
mysql_innodb_file_per_table: "1"
mysql_innodb_buffer_pool_size: "256M"
mysql_innodb_additional_mem_pool_size: "20M"
# Set .._log_file_size to 25% of buffer pool size.
mysql_innodb_log_file_size: "64M"
mysql_innodb_log_buffer_size: "8M"
mysql_innodb_flush_log_at_trx_commit: "1"
mysql_innodb_lock_wait_timeout: 50
# mysqldump settings
mysql_mysqldump_max_allowed_packet: "64M"

@ -1,38 +0,0 @@
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used (fedora >= 15).
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mysqld according to the
# instructions in http://fedoraproject.org/wiki/Systemd
user=mysql
# Semisynchronous Replication
# http://dev.mysql.com/doc/refman/5.5/en/replication-semisync.html
# uncomment next line on MASTER
;plugin-load=rpl_semi_sync_master=semisync_master.so
# uncomment next line on SLAVE
;plugin-load=rpl_semi_sync_slave=semisync_slave.so
# Others options for Semisynchronous Replication
;rpl_semi_sync_master_enabled=1
;rpl_semi_sync_master_timeout=10
;rpl_semi_sync_slave_enabled=1
# http://dev.mysql.com/doc/refman/5.5/en/performance-schema.html
;performance_schema
# Customizations for local development.
wait_timeout = 28800
max_allowed_packet = 64M
innodb_file_per_table = 1 # Allows for recovery of disk space when table are removed
innodb_buffer_pool_size = 128M # Up to 80% of available RAM on a dedicated box
innodb_flush_log_at_trx_commit = 2 # 1 for durability, 0 or 2 for performance
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

@ -25,7 +25,11 @@
when: ansible_os_family == 'Debian'
- name: Copy my.cnf global MySQL configuration.
copy: src=my.cnf dest=/etc/my.cnf owner=root group=root mode=0644
template: >
src=my.cnf.j2
dest=/etc/my.cnf
owner=root group=root mode=644
notify: restart mysql
- name: Ensure MySQL is started and enabled on boot.
service: >
@ -53,7 +57,7 @@
# Has to be after the root password assignment, for idempotency.
- name: Copy .my.cnf file with root password credentials.
template: >
src=my.cnf.j2
src=python-my.cnf.j2
dest={{ mysql_user_home }}/.my.cnf
owner=root group=root mode=600

@ -1,3 +1,52 @@
[client]
user=root
password={{ mysql_root_password }}
#password = your_password
port = 3306
socket = /var/lib/mysql/mysql.sock
[mysqld]
port = {{ mysql_port }}
datadir = {{ mysql_datadir }}
socket = {{ mysql_socket }}
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links = 0
# Settings user and group are ignored when systemd is used (fedora >= 15).
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mysqld according to the
# instructions in http://fedoraproject.org/wiki/Systemd
user = mysql
# http://dev.mysql.com/doc/refman/5.5/en/performance-schema.html
;performance_schema
# Memory settings.
key_buffer_size = {{ mysql_key_buffer_size }}
max_allowed_packet = {{ mysql_max_allowed_packet }}
table_open_cache = {{ mysql_table_open_cache }}
sort_buffer_size = {{ mysql_sort_buffer_size }}
read_buffer_size = {{ mysql_read_buffer_size }}
read_rnd_buffer_size = {{ mysql_read_rnd_buffer_size }}
myisam_sort_buffer_size = {{ mysql_myisam_sort_buffer_size }}
thread_cache_size = {{ mysql_thread_cache_size }}
query_cache_size = {{ mysql_query_cache_size }}
# Try number of CPU's * 2 for thread_concurrency.
thread_concurrency = {{ mysql_thread_concurrency }}
# InnoDB settings.
innodb_file_per_table = {{ mysql_innodb_file_per_table }}
innodb_buffer_pool_size = {{ mysql_innodb_buffer_pool_size }}
innodb_additional_mem_pool_size = {{ mysql_innodb_additional_mem_pool_size }}
innodb_log_file_size = {{ mysql_innodb_log_file_size }}
innodb_log_buffer_size = {{ mysql_innodb_log_buffer_size }}
innodb_flush_log_at_trx_commit = {{ mysql_innodb_flush_log_at_trx_commit }}
innodb_lock_wait_timeout = {{ mysql_innodb_lock_wait_timeout }}
[mysqldump]
quick
max_allowed_packet = {{ mysql_mysqldump_max_allowed_packet }}
[mysqld_safe]
log-error = /var/log/mysqld.log
pid-file = /var/run/mysqld/mysqld.pid

@ -0,0 +1,3 @@
[client]
user=root
password={{ mysql_root_password }}

@ -1,7 +0,0 @@
---
mysql_user_home: /root
mysql_root_password: root
# Pass in a comma-separated list of repos to use (e.g. "remi,epel"). Used only
# for RedHat systems (and derivatives).
mysql_enablerepo: ""