LittleBizzy

Dominate local SEO with a regional SlickStack cloud server for just $39/month!  Order Now
LittleBizzy
Technical SEO & Cloud Server Experts

MySQL 5.6 Configuration (WordPress Optimized)

Optimizing MySQL configurations is without question the most difficult and debated of any typical server configuration process. While other software such as Ubuntu, Nginx, or PHP are generally quite similar over the course of several releases, MySQL (and other SQL derivatives) can change drastically between version releases. And, unlike some other server applications, changing a single setting in your MySQL configuration can have extremely positive or negative consequences. It is VERY common for a single misconfigured setting to suddenly crash MySQL or totally prevent the service from even starting up.

If your MySQL database crashes often, one option is to add a swap file to your server. However, this really is a “cheap trick” as its essentially turning your hard drive space into pseudo-RAM for the server to use. A better and safer idea is to upgrade your server to the proper amount of physical RAM that your website requires, and then make sure your MySQL 5.6 configuration is setup appropriately, paying special attention to innodb_buffer_pool_size

There are so many things you can address when optimizing MySQL 5.6, but here are a few important ones:

sudo nano /etc/mysql/my.cnf
## most important setting, should be around 50% of available RAM (with no SWAP file)
## should also be slightly larger than total database size if possible
innodb_buffer_pool_size = 256M
## do not set to avoid the risk of MySQL connection issues
#max_connections = 100

wait_timeout=60
innodb_flush_neighbors=0
expire_logs_days=10
#timezone=GMT
#character-set-server=utf8mb4
#collation-server=utf8mb4_unicode_ci
#skip-character-set-client-handshake
skip-name-resolve
query_cache_size = 0 #default in 5.6
#max_connect_errors=100000
#interactive_timeout= dont set this ie for dumping etc will make errors

mysqlcheck http://www.thegeekstuff.com/2011/12/mysqlcheck/
https://www.digitalocean.com/community/questions/mysql-on-ubuntu-keeps-crashing
https://www.percona.com/blog/2014/01/28/10-mysql-settings-to-tune-after-installation/

Using MySQLTuner to Optimize MySQL configuration


http://pastie.org/8665237#7

http://tools.percona.com/

Converting SQL tables to innoDB:

ALTER TABLE `wp_bp_user_blogs_blogmeta` ENGINE=InnoDB;
ALTER TABLE `mm_actions` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

sudo chown -R www-data:www-data /var/log/nginx;
sudo chmod -R 755 /var/log/nginx;

sudo chown -R mysql:mysql /var/log/mysql;
sudo chmod -R 755 /var/log/mysql;

root@localhost
[email protected]
root@::1 only for root
root@% only for root

select host, user, password from mysql.user;

CREATE USER example@localhost IDENTIFIED BY ‘xxxxx’;
GRANT ALL PRIVILEGES ON database.* TO example@localhost;
CREATE USER [email protected] IDENTIFIED BY ‘xxxxx’;
GRANT ALL PRIVILEGES ON database.* TO [email protected];

CREATE USER society@::1 IDENTIFIED BY ‘x5PnhKM73vqteEY’;
GRANT ALL PRIVILEGES ON newdatabase.* TO newuser@::1;

UPDATE mysql.user SET Grant_priv=’Y’, Super_priv=’Y’ WHERE User=’root’;

== default on new 5.6

=== default mysql config ===
 
#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# – “/etc/mysql/my.cnf” to set global options,
# – “~/.my.cnf” to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with –help to get a list of available options and with
# –print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
# This will be passed to all mysql clients
# It has been reported that passwords should be enclosed with ticks/quotes
# escpecially if they contain “#” chars…
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
# Here is entries for some specific programs
# The following values assume you have at least 32M ram
# This was formally known as [safe_mysqld]. Both versions are currently parsed.
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0
[mysqld]
#
# * Basic Settings
#
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address = 127.0.0.1
#
# * Fine Tuning
#
key_buffer = 16M
max_allowed_packet = 16M
thread_stack = 192K
thread_cache_size = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover = BACKUP
#max_connections = 100
#table_cache = 64
#thread_concurrency = 10
#
# * Query Cache Configuration
#
query_cache_limit = 1M
query_cache_size = 16M
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file = /var/log/mysql/mysql.log
#general_log = 1
#
# Error log – should be very few entries.
#
log_error = /var/log/mysql/error.log
#
# Here you can see queries with especially long duration
#log_slow_queries = /var/log/mysql/mysql-slow.log
#long_query_time = 2
#log-queries-not-using-indexes
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
# other settings you may need to change.
#server-id = 1
#log_bin = /var/log/mysql/mysql-bin.log
expire_logs_days = 10
max_binlog_size = 100M
#binlog_do_db = include_database_name
#binlog_ignore_db = include_database_name
#
# * InnoDB
#
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI “tinyca”.
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem
[mysqldump]
quick
quote-names
max_allowed_packet = 16M
[mysql]
#no-auto-rehash # faster start of mysql but no tab completition
[isamchk]
key_buffer = 16M
#
# * IMPORTANT: Additional settings that can override those from this file!
# The files must end with ‘.cnf’, otherwise they’ll be ignored.
#
!includedir /etc/mysql/conf.d/

About the Author

Jesse

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *