mysql_change_user(3)
β¨ 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 bymysql_init(3)and connected bymysql_real_connect(3). your main character connection π«Άuserβ the user name for server authenticationpasswdβ the password for server authenticationdbβ the default database. if you want, you can pass theNULLvalue, 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 themysql_select_db(3)function. no cap π§
π NOTES π
mysql_change_userwill 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
- alpine 3.22: mariadb-doc 11.4.13-r0 Β· GPL-2.0-or-later
- alpine 3.23: mariadb-doc 11.4.13-r0 Β· GPL-2.0-or-later
- alpine 3.24: mariadb-doc 11.8.9-r0 Β· GPL-2.0-only
- arch rolling: mariadb 13.0.2-2 Β· GPL-2.0-only
- arch rolling: mariadb-lts 12.3.3-2 Β· GPL-2.0-only
- centos-stream 10: mariadb-connector-c-doc 3.4.4-2.el10 Β· LGPL-2.1-or-later
- debian trixie: libmariadb-dev 1:11.8.6-0+deb13u1 Β· GPL-2.0-only
- fedora 43: mariadb-connector-c-doc 3.4.5-2.fc43 Β· LGPL-2.1-or-later AND PHP-3.0 AND PHP-3.01
- fedora 43: mariadb-connector-c-doc 3.4.9-2.fc43 Β· LGPL-2.1-or-later AND PHP-3.0 AND PHP-3.01 AND LicenseRef-Fedora-Public-Domain
- fedora 44: mariadb-connector-c-doc 3.4.8-3.fc44 Β· LGPL-2.1-or-later AND PHP-3.0 AND PHP-3.01
- fedora 44: mariadb-connector-c-doc 3.4.9-2.fc44 Β· LGPL-2.1-or-later AND PHP-3.0 AND PHP-3.01 AND LicenseRef-Fedora-Public-Domain
- nixpkgs unstable: mariadb-server 11.8.8
- opensuse-leap 16.0: libmariadb-devel 3.4.9-160000.1.1 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: libmariadb-devel 3.4.9-160000.1.1 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: libmariadb-devel 3.4.9-160000.1.1 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: libmariadb-devel 3.4.9-160000.1.1 Β· LGPL-2.1-or-later
- ubuntu questing: libmariadb-dev 1:11.8.3-1build1
- ubuntu resolute: libmariadb-dev 1:11.8.6-5 Β· GPL-2.0-only
- ubuntu resolute: libmariadb-dev 1:11.8.6-5ubuntu0.1 Β· GPL-2.0-only
- ubuntu stonking: libmariadb-dev 1:11.8.9+ds-4ubuntu2 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms