From 6af73580a60c9ec0d3232ecb87e7afde5c6d9fe0 Mon Sep 17 00:00:00 2001 From: Aquila Macedo Date: Wed, 8 Apr 2026 11:19:44 -0300 Subject: [PATCH] MDEV-39290 mytop use invoking login as default user on Unix On non-Windows systems, use the invoking user's login name as the default MariaDB username instead of hardcoding root. Resolve the username from getpwuid($<), falling back to LOGNAME, USER, and finally root. Keep the existing root default on Windows. This makes mytop behave more like the mysql and mariadb clients and avoids confusing authentication failures on systems where local socket access is configured for the OS user rather than root. Also update the connection error text and POD to describe the actual default behavior. --- scripts/mytop.sh | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/scripts/mytop.sh b/scripts/mytop.sh index 593e8487858e8..22c99d57ef49d 100644 --- a/scripts/mytop.sh +++ b/scripts/mytop.sh @@ -72,6 +72,11 @@ sub cmd_s; sub cmd_S; sub cmd_q; +## Default username, matching mysql/mariadb on Unix +my $default_db_user = $WIN + ? 'root' + : ((getpwuid($<))[0] || $ENV{LOGNAME} || $ENV{USER} || 'root'); + ## Default Config Values my %config = ( @@ -99,7 +104,7 @@ my %config = ( slow => 10, ## slow query time socket => '', sort => 1, ## default or reverse sort ("s") - user => 'root', + user => $default_db_user, fullqueries => 0, ## shows untruncated queries usercol_width => 8, ## User column width dbcol_width => 9, ## DB column width @@ -285,7 +290,7 @@ if (not ref $dbh) Cannot connect to MariaDB/MySQL server. Please check the: * database you specified "$config{db}" (default is "") - * username you specified "$config{user}" (default is "root") + * username you specified "$config{user}" (default is "$default_db_user") * password you specified "$config{pass}" (default is "") * hostname you specified "$config{host}" (default is "localhost") * port you specified "$config{port}" (default is 3306) @@ -2252,7 +2257,9 @@ have two dashes `--'. Short arguments only have one '-'. =item B<-u> or B<--user> username -Username to use when logging in to the MariaDB server. Default: ``B''. +Username to use when logging in to the MariaDB server. On Unix, the default +is your login name (same as the C/C client). On Windows, the +default is ``B''. =item B<-p> or B<--pass> or B<--password> I @@ -2386,8 +2393,9 @@ command-line arguments are processed, so your command-line arguments will override directives in the config file. -Here is a sample config file C<~/.mytop> which implements the defaults -described above. +Here is a sample config file C<~/.mytop>. Omit C to keep the built-in +default (Unix login on non-Windows, same as C/C), the line +below is only if you want to connect as C explicitly. user=root pass=