On 21/08/14 22:24, Kerin Millar wrote:
> 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
>
Tkx, it worked but I ended up with a simple:
echo 'password:)' > a && echo 'password:)' >> a && emerge --config
mariadb < a && rm a
Whilst I can understand the reluctance to make auto-entering passwords
easy for security reasons, there are use-cases for quick build/config
throwaway solutions in a safe environment where its just a pain :)
BillK