Common Commands

Common Commands

The following is a list of common commands technician use when interacting with MariaDB.

User Management

List all User Accounts

The following command will list all users and where each user can connect from.

select user,host from mysql.user;

Change Root Password

If you know your current MySQL password, you can log into MySQL and run the following command to change the root password.

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('password');

Create a New User Account

This command will create a new user. Don’t forget to run flush privileges; afterwards.

GRANT ALL PRIVILEGES ON mydatabase.* TO 'username'@'localhost' IDENTIFIED BY 'password';

Delete a User Account

Use the following command to delete a MySQL user.

drop user 'username'@'localhost';

Database Management

Create a New Database

The following command will create a new database called mydatabase.

create database mydatabase;

Delete a Database

The following command will delete the database called mydatabase.

drop database mydatabase;

Dump a Database

The following command will export the contents of the database to a file in your working directory.

mysqldump -u username -p mydatabase > mydatabase.sql