Skip to content

MDEV-39290 mytop use invoking login as default user on Unix#4918

Open
aquilamacedo wants to merge 1 commit intoMariaDB:mainfrom
aquilamacedo:main
Open

MDEV-39290 mytop use invoking login as default user on Unix#4918
aquilamacedo wants to merge 1 commit intoMariaDB:mainfrom
aquilamacedo:main

Conversation

@aquilamacedo
Copy link
Copy Markdown
Contributor

mytop defaults the database user to root.

On Unix, the mysql and mariadb clients use the current OS login when no user is specified. Because of that difference, mytop may try to connect as root@localhost and fail on setups where local unix_socket access is configured for the normal user instead of root.

This patch changes the default on non-Windows systems to the invoking login name, using getpwuid($<) first, then LOGNAME, then USER, and finally root. Windows keeps the existing default of root.

It also updates the connection failure message and POD so the documented defaults match the actual behavior.

Jira ticket: Fixes MDEV-39290.

Testing

Manual checks on Debian 13 with MariaDB 11.8.6 client:

  1. As non-root, with no ~/.mytop and no -u:
    mytop -h 127.0.0.1 -P 65534 -b -s 1
    Result: error text shows username ... "testuser" and (default is "testuser").

  2. With both root@localhost and testuser@localhost using unix_socket:
    su - testuser -c 'mytop -b -s 1'
    Result: connects and prints status.

  3. As testuser, forcing -u root:
    su - testuser -c 'mytop -b -s 1 -u root'
    Result: uses root as requested, message still shows (default is "testuser").

  4. As root:
    sudo mytop -b -s 1
    Result: works with socket-authenticated root.

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.
@gkodinov gkodinov added the External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements. label Apr 9, 2026
Copy link
Copy Markdown
Member

@gkodinov gkodinov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution! This is a preliminary review.

LGTM. I'd also explore the possibility of a regression test, but that's highly optional.

Please stand by for the final review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements.

Development

Successfully merging this pull request may close these issues.

3 participants