How to Change Users in MariaDB from the Command Line (Secure Methods)

2024-07-27

However, there are workarounds to achieve a similar outcome:




This approach involves opening separate terminal windows and connecting to MariaDB with different usernames in each.

  • Session 1 (initial user):
mysql -u username1 -p  # Replace 'username1' with your actual username
  • Session 2 (different user):

Open a new terminal window and run:

mysql -u username2 -p  # Replace 'username2' with your desired username

This allows you to work with different user accounts simultaneously.

system command (Less Secure):

Warning: This method is less secure as it involves typing the password within the MariaDB session.

mysql -u current_user -p  # Replace 'current_user' with your actual username

# Enter your password when prompted

USE your_database;  # Replace 'your_database' with the database you want to use

system 'mysql -u desired_user -p your_database';  # Replace 'desired_user' with the target username and 'your_database' with the database

# Enter the password for 'desired_user' when prompted (less secure)

This code first connects to MariaDB with your current user. Then it uses the system command to launch another mysql session with the desired username and database.




  1. Using GRANT to extend privileges:

This approach focuses on managing user permissions instead of switching users. If a user requires additional access for specific tasks, you can grant them the necessary privileges without needing to switch accounts entirely.

Here's an example:

mysql -u current_user -p  # Replace 'current_user' with your actual username

# Enter your password when prompted

USE your_database;  # Replace 'your_database' with the database

GRANT SELECT, INSERT ON your_table TO desired_user;  # Replace 'desired_user' and 'your_table' with specifics

FLUSH PRIVILEGES;

This code grants the user desired_user the SELECT and INSERT privileges on the table your_table. This allows them to perform specific actions within the database without needing to switch accounts.

  1. Advanced: Using mysql_native_password plugin (MariaDB 10.4+):

Note: This approach requires MariaDB version 10.4 or later and involves some technical knowledge.

MariaDB 10.4 introduced the ability to configure multiple authentication plugins per user account. This allows for a more secure transition strategy. Here's a general idea (consult MariaDB documentation for specifics):

  1. Configure two authentication plugins for a user:

    • Existing method (e.g., mysql_native_password).
    • New, more secure method (e.g., sha256_password).

This allows a gradual migration to a more secure authentication method while still providing a temporary fallback option.


mariadb



Grant All Privileges in MySQL/MariaDB

In simple terms, "granting all privileges on a database" in MySQL or MariaDB means giving a user full control over that specific database...


MAMP with MariaDB: Configuration Options

It's a local development environment that bundles Apache web server, MySQL database server, and PHP scripting language for macOS...


MySQL 5 vs 6 vs MariaDB: Choosing the Right Database Server

MySQL 6.x is a newer series with more advanced features, but less widely adopted.MySQL 5.x is a mature series with many stable versions (e.g., 5.6)...


Beyond Backups: Alternative Approaches to MySQL to MariaDB Migration

There are two main approaches depending on your comfort level:Data Directory Copy (For experts):(Only if using MyISAM or InnoDB storage engines)Stop MySQL server...


MySQL vs MariaDB vs Percona Server vs Drizzle: Choosing the Right Database

Here's an analogy: Imagine MySQL is a popular recipe for a cake.Drizzle would be a whole new recipe inspired by the original cake...



mariadb

MySQL Large Packet Error Troubleshooting

Common Causes:Large Data Sets: When dealing with large datasets, such as importing a massive CSV file or executing complex queries involving many rows or columns


Single vs. Multiple Row Inserts in MySQL/MariaDB

Multiple Single INSERT Statements:This approach can be more readable and maintainable for smaller datasets.Multiple statements are executed sequentially


MySQL Data Export to Local File

LOCAL: This keyword specifies that the file should be created on the local filesystem of the server, rather than a remote location


MariaDB for Commercial Use: Understanding Licensing and Support Options

Commercial License: Typically refers to a license where you pay a fee to use software for commercial purposes (selling a product that uses the software)


Fixing 'MariaDB Engine Won't Start' Error on Windows

Error starting the database engine: This indicates MariaDB isn't running properly on Windows.Windows: The operating system where MariaDB is installed