Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- use lib '/var/www/imscp/engine/PerlLib';
- use iMSCP::Bootstrapper;
- use iMSCP::Database;
- use iMSCP::Debug;
- use Servers::sqld;
- iMSCP::Bootstrapper->getInstance()->boot();
- my $password = shift;
- defined $password && $password ne '' or fatal('You must provide a password for the SQL root user');
- my $sqlServer = Servers::sqld->factory();
- my $db = iMSCP::Database->factory();
- for my $host('localhost', '127.0.0.1', '::1') {
- my $qrs = $db->doQuery( 1, 'SELECT 1 FROM mysql.user WHERE user = ? AND host = ?', 'root', $host );
- ref $qrs eq 'HASH' or fatal( $qrs );
- if(%{$qrs}) {
- $qrs = $db->doQuery( 'd', 'DROP USER ?@?', 'root', $host );
- ref $qrs eq 'HASH' or fatal( sprintf( 'Could not drop the %s@%s SQL user: %s', 'root', $host, $qrs ) );
- }
- $sqlServer->createUser('root', $host, $password);
- $qrs = $db->doQuery( 'g', 'GRANT ALL ON *.* TO ?@? WITH GRANT OPTION', 'root', $host );
- unless (ref $qrs eq 'HASH') {
- fatal( sprintf( 'Could not GRANT privileges: %s', $qrs ) );
- }
- }
- 1;
- __END__
Add Comment
Please, Sign In to add comment