On 21/08/2014 12:07, Bill Kenworthy wrote:
Hi,
I am building some VM's using scripts and want to run "emerge --config
mariadb" automaticly. However it asks for a new root password (entered
twice) as part of the process - I was going to make an expect script to
enter the password for me ... but I thought someone might know a better way?
You can execute mysql_install_db directly instead of relying on
distro-specific voodoo. Something like this should do the trick:-
#!/bin/bash
set -e
# Use SELECT PASSWORD('<password>') to generate a hash
password_hash="*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19"
# Do nothing if MySQL appears to have been configured
[[ -f /var/lib/mysql/ibdata1 ]] && exit 0
# Initialize the database
mysql_install_db
# Set root password, delete spurious root accounts, drop test database
mysql -B <<-SQL
SET PASSWORD FOR 'root'@'%' = '${password_hash}';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
DELETE FROM mysql.user WHERE Host != '%';
FLUSH PRIVILEGES;
DROP DATABASE test;
SQL
--Kerin