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