mysql_change_user(3)

πŸ“¦
version 13.0.2 Β· 4 versions
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, centos-stream 10, debian trixie, fedora 43, fedora 44, nixpkgs unstable, opensuse-leap 16.0, ubuntu questing, ubuntu resolute, ubuntu stonking

✨ mysql_change_user β€” the glow-up your connection needed πŸ’…

okay so bestie, this one lives in the MariaDB Connector/C manual, and it's literally about swapping out who you're logged in as without yeeting the whole connection. iconic behavior honestly.


πŸŽ€ NAME πŸŽ€

mysql_change_user β€” changes user and default database


🌸 SYNOPSIS 🌸

#include <mysql.h>

my_bool mysql_change_user(MYSQL * mysql,
                          const char * user,
                          const char * passwd,
                          const char * db);

πŸ¦‹ DESCRIPTION πŸ¦‹

It changes the user and the default database of the current connection. no new connection, no drama, just a little identity shift ✨

But listen β€” for the user swap to actually work, you gotta hand over a valid username and password, and that user needs sufficient permissions to get into the database they're asking for. If authorization fails for literally any reason, the current user's authentication stays exactly as it was. no take-backs, the old you is still logged in. πŸ’€


πŸ’– PARAMETERS πŸ’–

  • mysql β€” a connection identifier, which was previously allocated by mysql_init(3) and connected by mysql_real_connect(3). your main character connection 🫢
  • user β€” the user name for server authentication
  • passwd β€” the password for server authentication
  • db β€” the default database. if you want, you can pass the NULL value, which means you're only changing the user and not selecting a database at all. and if you do that and then change your mind about wanting a database? just use the mysql_select_db(3) function. no cap 🧚

πŸ’… NOTES πŸ’…

  • mysql_change_user will always cause the current database connection to behave as if it was a completely new database connection, regardless of whether the operation was completed successfully. yes, even if it flopped. this reset includes performing a rollback on any active transactions, closing all temporary tables, and unlocking all locked tables. it's giving factory reset fr fr 😭
  • To prevent denial of service and brute-force attacks, the server will block the connection if mysql_change_user() failed three times in a row. so like… maybe don't spam it? πŸ™ˆ

⭐ RETURN VALUE ⭐

Returns zero on success, nonzero if an error occurred. simple as that, bestie.


🌈 SEE ALSO 🌈


Version 3.4 of the MariaDB Connector/C manual, bestie β€” that's the whole page, you ate it, periodt. πŸ‘‘πŸ’œ

πŸ“¦ where this page comes from