Installs and configures MySQL client or server.
- Debian, Ubuntu
- CentOS, Red Hat, Fedora
Requires Opscode's openssl cookbook for secure password generation.
Requires a C compiler and Ruby development package in order to build mysql gem with native extensions. On Debian and Ubuntu systems this is satisfied by installing the "build-essential" and "ruby-dev" packages before running Chef. See USAGE below for information on how to handle this during a Chef run.
Resources and Providers
The cookbook contains a LWRP,
mysql_database which can be used to manage databases through calls to the MySQL API. The mysql gem is installed to make this usable. The provider currently supports three actions:
flush_tables_with_read_lock- sends the sql command "flush tables with read lock", used for setting up mysql master/slave replication.
unflush_tables- sends the sql command "unflush tables", used for setting up master/slave replication.
create_db- specify a database to be created.
query- send an arbitrary query to the database, this should be used with care. Pass the SQL statement to use with the
For example see the USAGE section below.
mysql[:server_root_password]- Set the server's root password with this, default is a randomly generated password with
mysql[:server_repl_password]- Set the replication user 'repl' password with this, default is a randomly generated password with
mysql[:server_debian_password]- Set the debian-sys-maint user password with this, default is a randomly generated password with
mysql[:bind_address]- Listen address for MySQLd, default is node's ipaddress.
mysql[:datadir]- Location for mysql data directory, default is "/var/lib/mysql"
mysql[:ec2_path]- location of mysql datadir on EC2 nodes, default "/mnt/mysql"
Performance tuning attributes, each corresponds to the same-named parameter in my.cnf; default values listed
On client nodes,
This will install the MySQL client libraries and development headers on the system. It will also install the Ruby Gem
mysql, so that the cookbook's LWRP (above) can be used. This is done during the compile-phase of the Chef run. On platforms that are known to have a native package (currently Debian, Ubuntu, Red hat, Centos, Fedora and SUSE), the package will be installed. Other platforms will use the RubyGem.
This creates a resource object for the package and does the installation before other recipes are parsed. You'll need to have the C compiler and such (ie, build-essential on Ubuntu) before running the recipes, but we already do that when installing Chef :-). If you want to be able to access a MySQL database via Ruby within another recipe, you could do so, like so:
mysql_database "create application_production database" do host "localhost" username "root" password node[:mysql][:server_root_password] database "application_production" action :create_db end
This will connect to the MySQL server running on localhost as "root" and password as
mysql[:server_root_password] attribute (see below) and create the database specified with the
database parameter. The provider will attempt to determine whether the database exists first.
On server nodes,
On Debian and Ubuntu, this will preseed the mysql-server package with the randomly generated root password from the attributes file. On other platforms, it simply installs the required packages. It will also create an SQL file, /etc/mysql/grants.sql, that will be used to set up grants for the root, repl and debian-sys-maint users.
On EC2 nodes,
ec2_path doesn't exist we look for a mounted filesystem (eg, EBS) and move the datadir there.
The client recipe is already included by server and 'default' recipes.
For more infromation on the compile vs execution phase of a Chef run:
License and Author
Copyright:: 2009-2011 Opscode, Inc
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.