MySQL for beginners

A summary of commands to get beginners started with MySQL or MariaDB.

To start the MySQL monitor type

mysql or sudo mysql

The mysql monitor will start.

mysql>

Exit

Use the exit command to leave the MySQL monitor.

mysql> exit
Bye


Show databases

Show all databases currently in use:

mysql> show databases;

+----------------------------+
| Database                           |
+----------------------------+
| information_schema      |
| database1                           |
| database2                          |
+----------------------------+

3 rows in set (0.01 sec)





Create database

To create a database use the create database command

mysql> create database new_database_name;
Query OK, 1 row affected (0.00 sec)

Drop database

To drop or delete  a database us the drop database command

mysql> drop database new_database_name;
Query OK, 0 rows affected (0.01 sec)

Create user

To create or add a user to MySQL use the create user command

mysql> create user 'new_user'@'localhost' IDENTIFIED BY 'user_password';
Query OK, 0 rows affected (0.01 sec)

Drop user

To remove or drop a user from MySQL use the drop user command

mysql> drop user 'new_user'@localhost;
Query OK, 0 rows affected (0.00 sec)

Grant privileges

To give read write access and connection rights to users use the grant privileges command.
To give all privileges use:

mysql> grant all privileges on new_database_name.* to 'new_user'@'localhost';
Query OK, 0 rows affected (0.00 sec)

Revoke privileges

To revoke all access read and write privileges for a user use revoke all privileges

mysql> revoke all privileges, grant option from 'new_user'@'localhost';
Query OK, 0 rows affected (0.00 sec)

 

 

Taxonomy