Reading:  

Beginners guide to MySQL and MariaDB


Adding Users

There are various types of queries for specific tasks that can be used to accomplish those tasks. One of them is to create a user. This is a basic task that has to be accomplished from day to day.

Let's check how to create a database user

Setting Up a MySQL User Account:

Adding new user into MySQL involves adding new entry into user table in mysql database. Add new user guest with INSERT, SELECT and UPDATE privileges with password guest121.

USE mysql;
INSERT INTO user (host, user, password,select_priv, insert_priv, update_priv,ssl_cipher,x509_issuer,x509_subject,authentication_string) VALUES ('localhost', 'guest',PASSWORD('guest121'), 'Y', 'Y', 'Y','','','','');
 


USE mysql basically is telling the mysql server that we want to work with database named mysql database, which holds user information and other related meta data related in form of tables.

Here is a screenshot showing successful completion of our query.

Add user MYSQL

FLUSH PRIVELEGES will refresh the grant table, this means that you will start using the newly created user straight away. Other way is to restart your MySQL service, which we doubt if an efficient way.

There are other privileges to a new user by setting values of following columns in user table to 'Y' when executing INSERT query or can be update later using UPDATE query.

  • Select_priv
  • Insert_priv
  • Update_priv
  • File_priv
  • Grant_priv
  • References_priv
  • Index_priv
  • Alter_priv
  • Delete_priv
  • Create_priv
  • Drop_priv
  • Reload_priv
  • Shutdown_priv
  • Process_priv

You can use GRANT statement on an existing user to update their privileges, to get an idea please check this link for official MySQL document on GRANT statement

Some of other useful statements that you will end up using are

Administrative MySQL Command:

The list of important MySQL commands are:

  • USE Database name: This command is used to select particular database in MySQL workarea.
  • SHOW DATABASES: Shows list of databases.
  • SHOW TABLES: Shows list of tables in the database.
  • SHOW COLUMNS FROM tablename: Shows attributes, key information, types of attributes whether NULL is permitted, defaults and other information for a table.
  • SHOW INDEX FROM tablename: Shows details of all indexes on table, including PRIMARY KEY.

For a full coverage please check this document up

In the next part of this tutorial, we will explore MySQL connections using MySQL client, PHP and C#

Description

In this tutorial, we will cover few topics that will give you a heads on start to build your knowledge on. Topics that we will cover briefly but still providing enough information are listed below

  • Overview
  • Installing on Linux and Windows
  • Some useful admin queries for starters
  • Connection
  • Create Database
  • Drop Database
  • Select Database
  • Data Type
  • Create Table
  • Drop Table
  • Inserting and Selecting data
  • Where Clause
  • Updating and deleting data
  • Like Clause
  • Sorting Result
  • Using Joins
  • Brief introduction to Regex, Transactions and Indexes
  • Alter Command
  • Temporary Tables
  • Database Info
  • Using Sequence
  • Database Export and Import
  • Resetting MySQL/MariaDB Administrator password


Audience

Absolute beginners looking to get a sneak peak into what MySQL. Please remember that this is not a full on guide but a quick introduction to the subject.

Learning Objectives

Get to know MySQL and MariaDB

Author: Subject Coach
Added on: 23rd Jun 2015

You must be logged in as Student to ask a Question.

None just yet!