Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
What can be wrong in this syntax? I want to create a user and grant some rights in a MySQL database (8.0) using the latest DBD driver
my $user = 'somename'; my $password="0123"; my $db ="test"; my $host="localhost"; print "Connecting to terminology database $db as $user... "; my $dsn = "DBI:mysql:$db:$host:$port"; my %attr = (PrintError=>0, RaiseError=>1); my $dbh = DBI->connect($dsn,$Superuser,$pass, \%attr); print "done!\n"; my $sql; print "Creating user $user\n"; $sql = 'CREATE USER ?@? IDENTIFIED BY ?'; $dbh->do($sql, undef, $user, "localhost", $password); print "done!\n"; print "Granting user $user some rights\n"; $sql = 'GRANT ALL ON $db.* TO ?@? IDENTIFIED BY ?'; $dbh->do(q{GRANT ALL ON ?.* TO ?@? IDENTIFIED BY ?}, {}, $db, $use +r, $host, $password); print "done!\n";
I connect to the database as "root", so it should have all the privileges. I get the following
Connecting to terminology database test as root... done! Creating user somename done! Granting user somename some rights DBD::mysql::db do failed: You have an error in your SQL syntax; check +the manual that corresponds to your MySQL server version for the righ +t syntax to use near ''test'.* TO 'somename'@'localhost' IDENTIFIED B +Y '0123'' at line 1
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: MySQL syntax error GRANT
by poj (Abbot) on Oct 02, 2018 at 19:38 UTC | |
by Anonymous Monk on Oct 02, 2018 at 19:50 UTC | |
|
Re: MySQL syntax error GRANT
by Paladin (Vicar) on Oct 02, 2018 at 18:54 UTC | |
by Anonymous Monk on Oct 02, 2018 at 19:04 UTC |