echo 
echo "*** configure MySQL ***"
echo 

yum -y install mysql-server

/etc/init.d/mysqld start >/dev/null 2>&1

mysqladmin -u root password 'passw0rd'

#echo "DELETE FROM user WHERE Host = 'thirdlane.local' and user = 'root';" | /usr/bin/mysql --user=root --password=passw0rd mysql

# add account for service scripts
#echo "GRANT ALL PRIVILEGES ON *.* TO 'localroot'@'localhost';" | /usr/bin/mysql --user=root --password=passw0rd mysql

echo mysql -uroot -ppassw0rd pbxconf >  /usr/local/sbin/mydb
chmod +x /usr/local/sbin/mydb

# save original MySQL config and replace it with customized

mv /etc/my.cnf /etc/my.cnf.orig

cat >> /etc/my.cnf <<-EOF
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

max_allowed_packet = 32M
max_connections = 200
query_cache_size=64M
thread_cache_size=32
tmp_table_size=64M
max_heap_table_size=16M
sort_buffer_size=2M
log_slow_queries=/var/log/mysql-slow-queries.log
table_cache=1024
key_buffer_size=32M
wait_timeout=2678400
myisam_max_sort_file_size=4294967296

innodb_buffer_pool_size=32M

innodb_file_per_table=1

sort_buffer_size = 5M
read_rnd_buffer_size = 1M

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

EOF

/etc/init.d/mysqld restart
