SlideShare a Scribd company logo
http://www.tutorialspoint.com/mysql/mysql-administration.htm Copyright © tutorialspoint.com
MYSQL ADMINISTRATIONMYSQL ADMINISTRATION
Running and Shutting down MySQL Server:
First check if your MySQL server is running or not. You can use the following command to check
this:
ps -ef | grep mysqld
If your MySql is running, then you will see mysqld process listed out in your result. If server is not
running, then you can start it by using the following command:
root@host# cd /usr/bin
./safe_mysqld &
Now, if you want to shut down an already running MySQL server, then you can do it by using the
following command:
root@host# cd /usr/bin
./mysqladmin -u root -p shutdown
Enter password: ******
Setting Up a MySQL User Account:
For adding a new user to MySQL, you just need to add a new entry to user table in database
mysql.
Below is an example of adding new user guest with SELECT, INSERT and UPDATE privileges with
the password guest123; the SQL query is:
root@host# mysql -u root -p
Enter password:*******
mysql> use mysql;
Database changed
mysql> INSERT INTO user
(host, user, password,
select_priv, insert_priv, update_priv)
VALUES ('localhost', 'guest',
PASSWORD('guest123'), 'Y', 'Y', 'Y');
Query OK, 1 row affected (0.20 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 1 row affected (0.01 sec)
mysql> SELECT host, user, password FROM user WHERE user = 'guest';
+-----------+---------+------------------+
| host | user | password |
+-----------+---------+------------------+
| localhost | guest | 6f8c114b58f2ce9e |
+-----------+---------+------------------+
1 row in set (0.00 sec)
When adding a new user, remember to encrypt the new password using PASSWORD() function
provided by MySQL. As you can see in the above example the password mypass is encrypted to
6f8c114b58f2ce9e.
Notice the FLUSH PRIVILEGES statement. This tells the server to reload the grant tables. If you don't
use it, then you won't be able to connect to mysql using the new user account at least until the
server is rebooted.
You can also specify other privileges to a new user by setting the values of following columns in
user table to 'Y' when executing the INSERT query or you can update them later using UPDATE
query.
Select_priv
Insert_priv
Update_priv
Delete_priv
Create_priv
Drop_priv
Reload_priv
Shutdown_priv
Process_priv
File_priv
Grant_priv
References_priv
Index_priv
Alter_priv
Another way of adding user account is by using GRANT SQL command; following example will add
user zara with password zara123 for a particular database called TUTORIALS.
root@host# mysql -u root -p password;
Enter password:*******
mysql> use mysql;
Database changed
mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
-> ON TUTORIALS.*
-> TO 'zara'@'localhost'
-> IDENTIFIED BY 'zara123';
This will also create an entry in mysql database table called user.
NOTE: MySQL does not terminate a command until you give a semi colon (;) at the end of SQL
command.
The /etc/my.cnf File Configuration:
Most of the cases, you should not touch this file. By default, it will have the following entries:
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
[mysql.server]
user=mysql
basedir=/var/lib
[safe_mysqld]
err-log=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
Here, you can specify a different directory for error log, otherwise you should not change any
entry in this table.
Administrative MySQL Command:
Here is the list of important MySQL commands, which you will use time to time to work with MySQL
database:
USE Databasename : This will be used to select a particular database in MySQL workarea.
SHOW DATABASES: Lists the databases that are accessible by the MySQL DBMS.
SHOW TABLES: Shows the tables in the database once a database has been selected with
the use command.
SHOW COLUMNS FROM tablename: Shows the attributes, types of attributes, key
information, whether NULL is permitted, defaults, and other information for a table.
SHOW INDEX FROM tablename: Presents the details of all indexes on the table, including
the PRIMARY KEY.
SHOW TABLE STATUS LIKE tablenameG: Reports details of the MySQL DBMS
performance and statistics.

More Related Content

PPT
Raj mysql
PPSX
Execute sql query or sql command sql server using command prompt
PDF
MySql Restore Script
TXT
Intalacion de owncloud
DOCX
Multiple instances second method
PDF
How to export import a mysql database via ssh in aws lightsail wordpress rizw...
PDF
Instalar PENTAHO 5 en CentOS 6
PPT
Mysql
Raj mysql
Execute sql query or sql command sql server using command prompt
MySql Restore Script
Intalacion de owncloud
Multiple instances second method
How to export import a mysql database via ssh in aws lightsail wordpress rizw...
Instalar PENTAHO 5 en CentOS 6
Mysql

What's hot (18)

PDF
External Language Stored Procedures for MySQL
PDF
How To Manage Linux User on RHEL 7
PDF
MySql cheat sheet
PDF
Pluggable database tutorial 2
PDF
How To Install and Configure GNome on CentOS 7
PDF
Deploy agent in em12c
PDF
MySQL replication & cluster
PDF
instaling
PPT
Apache
PDF
Mysql connection
PDF
Cache management obiee 10g
PDF
How to Install MariaDB Server or MySQL Server on CentOS 7
DOC
Tomcat ssl 設定
PDF
Firebird
PDF
How To Install and Configure Open SSH Server on Ubuntu
PDF
How To Install OpenFire in CentOS 7
PDF
Install and Configure RSyslog – CentOS 7 / RHEL 7
ODP
feature toggles for ops
External Language Stored Procedures for MySQL
How To Manage Linux User on RHEL 7
MySql cheat sheet
Pluggable database tutorial 2
How To Install and Configure GNome on CentOS 7
Deploy agent in em12c
MySQL replication & cluster
instaling
Apache
Mysql connection
Cache management obiee 10g
How to Install MariaDB Server or MySQL Server on CentOS 7
Tomcat ssl 設定
Firebird
How To Install and Configure Open SSH Server on Ubuntu
How To Install OpenFire in CentOS 7
Install and Configure RSyslog – CentOS 7 / RHEL 7
feature toggles for ops
Ad

Viewers also liked (16)

PDF
U C2007 My S Q L Performance Cookbook
PDF
The Peoper Care and Feeding of a MySQL Server for Busy Linux Admin
PDF
Managing MySQL with Ansible
PDF
Making MySQL Administration a Breeze - A Look Into a MySQL DBA's Toolchest
PDF
SAP HANA Cookbook for MySQL Developers
PDF
MySQL Monitoring 101
PDF
MySQL Performance Metrics that Matter
PDF
Modern MySQL Monitoring and Dashboards.
PPT
Extended Essay
DOCX
Rancangan tahunan matematik tingkatan 5 2013
PPT
MySQL 5.7: Performance Schema Improvements
ODP
MySQL Administration and Monitoring
PPT
Basics Of English Grammar 2 Ppt
PPTX
A comprehensive English grammar guide for EFL/ESL teachers
PDF
A comprehensive grammar of the english language quirk greenbaum leech svartvik
PDF
Bildwörterbuch deutsch
U C2007 My S Q L Performance Cookbook
The Peoper Care and Feeding of a MySQL Server for Busy Linux Admin
Managing MySQL with Ansible
Making MySQL Administration a Breeze - A Look Into a MySQL DBA's Toolchest
SAP HANA Cookbook for MySQL Developers
MySQL Monitoring 101
MySQL Performance Metrics that Matter
Modern MySQL Monitoring and Dashboards.
Extended Essay
Rancangan tahunan matematik tingkatan 5 2013
MySQL 5.7: Performance Schema Improvements
MySQL Administration and Monitoring
Basics Of English Grammar 2 Ppt
A comprehensive English grammar guide for EFL/ESL teachers
A comprehensive grammar of the english language quirk greenbaum leech svartvik
Bildwörterbuch deutsch
Ad

Similar to Mysql administration (20)

PDF
Getting started with my sql
PPTX
My sql administration
PDF
SULTHAN's PHP, MySQL & wordpress
PDF
BITS: Introduction to MySQL - Introduction and Installation
PPTX
MySQL DBA OCP 1Z0-883
PPT
PPTX
Using Mysql.pptx
PDF
Mysqlsecurityoptionsjan2021
PPT
My sql presentation
PDF
My sql università di enna a.a. 2005-06
PPT
PPT
Mysqlppt3510
PPT
Mysqlppt3510
PDF
Mysql tutorial
PPT
My sql with querys
PPTX
Php mysq
PDF
Percona Live '18 Tutorial: The Accidental DBA
PPT
Mysql grand
PDF
How to Install MySQL on Debian 12 In Just 8 Steps.pdf
Getting started with my sql
My sql administration
SULTHAN's PHP, MySQL & wordpress
BITS: Introduction to MySQL - Introduction and Installation
MySQL DBA OCP 1Z0-883
Using Mysql.pptx
Mysqlsecurityoptionsjan2021
My sql presentation
My sql università di enna a.a. 2005-06
Mysqlppt3510
Mysqlppt3510
Mysql tutorial
My sql with querys
Php mysq
Percona Live '18 Tutorial: The Accidental DBA
Mysql grand
How to Install MySQL on Debian 12 In Just 8 Steps.pdf

Recently uploaded (20)

PPTX
Introduction to Information and Communication Technology
PDF
WebRTC in SignalWire - troubleshooting media negotiation
PDF
The New Creative Director: How AI Tools for Social Media Content Creation Are...
PPTX
522797556-Unit-2-Temperature-measurement-1-1.pptx
PDF
How to Ensure Data Integrity During Shopify Migration_ Best Practices for Sec...
PPTX
SAP Ariba Sourcing PPT for learning material
PPTX
international classification of diseases ICD-10 review PPT.pptx
PDF
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
PPTX
Introuction about ICD -10 and ICD-11 PPT.pptx
PPTX
E -tech empowerment technologies PowerPoint
PPTX
June-4-Sermon-Powerpoint.pptx USE THIS FOR YOUR MOTIVATION
PDF
Decoding a Decade: 10 Years of Applied CTI Discipline
PDF
RPKI Status Update, presented by Makito Lay at IDNOG 10
PDF
An introduction to the IFRS (ISSB) Stndards.pdf
PDF
Testing WebRTC applications at scale.pdf
PPTX
INTERNET------BASICS-------UPDATED PPT PRESENTATION
PPTX
Power Point - Lesson 3_2.pptx grad school presentation
DOCX
Unit-3 cyber security network security of internet system
PDF
Introduction to the IoT system, how the IoT system works
PPTX
Introuction about WHO-FIC in ICD-10.pptx
Introduction to Information and Communication Technology
WebRTC in SignalWire - troubleshooting media negotiation
The New Creative Director: How AI Tools for Social Media Content Creation Are...
522797556-Unit-2-Temperature-measurement-1-1.pptx
How to Ensure Data Integrity During Shopify Migration_ Best Practices for Sec...
SAP Ariba Sourcing PPT for learning material
international classification of diseases ICD-10 review PPT.pptx
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
Introuction about ICD -10 and ICD-11 PPT.pptx
E -tech empowerment technologies PowerPoint
June-4-Sermon-Powerpoint.pptx USE THIS FOR YOUR MOTIVATION
Decoding a Decade: 10 Years of Applied CTI Discipline
RPKI Status Update, presented by Makito Lay at IDNOG 10
An introduction to the IFRS (ISSB) Stndards.pdf
Testing WebRTC applications at scale.pdf
INTERNET------BASICS-------UPDATED PPT PRESENTATION
Power Point - Lesson 3_2.pptx grad school presentation
Unit-3 cyber security network security of internet system
Introduction to the IoT system, how the IoT system works
Introuction about WHO-FIC in ICD-10.pptx

Mysql administration

  • 1. http://www.tutorialspoint.com/mysql/mysql-administration.htm Copyright © tutorialspoint.com MYSQL ADMINISTRATIONMYSQL ADMINISTRATION Running and Shutting down MySQL Server: First check if your MySQL server is running or not. You can use the following command to check this: ps -ef | grep mysqld If your MySql is running, then you will see mysqld process listed out in your result. If server is not running, then you can start it by using the following command: root@host# cd /usr/bin ./safe_mysqld & Now, if you want to shut down an already running MySQL server, then you can do it by using the following command: root@host# cd /usr/bin ./mysqladmin -u root -p shutdown Enter password: ****** Setting Up a MySQL User Account: For adding a new user to MySQL, you just need to add a new entry to user table in database mysql. Below is an example of adding new user guest with SELECT, INSERT and UPDATE privileges with the password guest123; the SQL query is: root@host# mysql -u root -p Enter password:******* mysql> use mysql; Database changed mysql> INSERT INTO user (host, user, password, select_priv, insert_priv, update_priv) VALUES ('localhost', 'guest', PASSWORD('guest123'), 'Y', 'Y', 'Y'); Query OK, 1 row affected (0.20 sec) mysql> FLUSH PRIVILEGES; Query OK, 1 row affected (0.01 sec) mysql> SELECT host, user, password FROM user WHERE user = 'guest'; +-----------+---------+------------------+ | host | user | password | +-----------+---------+------------------+ | localhost | guest | 6f8c114b58f2ce9e | +-----------+---------+------------------+ 1 row in set (0.00 sec) When adding a new user, remember to encrypt the new password using PASSWORD() function provided by MySQL. As you can see in the above example the password mypass is encrypted to 6f8c114b58f2ce9e. Notice the FLUSH PRIVILEGES statement. This tells the server to reload the grant tables. If you don't use it, then you won't be able to connect to mysql using the new user account at least until the server is rebooted. You can also specify other privileges to a new user by setting the values of following columns in
  • 2. user table to 'Y' when executing the INSERT query or you can update them later using UPDATE query. Select_priv Insert_priv Update_priv Delete_priv Create_priv Drop_priv Reload_priv Shutdown_priv Process_priv File_priv Grant_priv References_priv Index_priv Alter_priv Another way of adding user account is by using GRANT SQL command; following example will add user zara with password zara123 for a particular database called TUTORIALS. root@host# mysql -u root -p password; Enter password:******* mysql> use mysql; Database changed mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP -> ON TUTORIALS.* -> TO 'zara'@'localhost' -> IDENTIFIED BY 'zara123'; This will also create an entry in mysql database table called user. NOTE: MySQL does not terminate a command until you give a semi colon (;) at the end of SQL command. The /etc/my.cnf File Configuration: Most of the cases, you should not touch this file. By default, it will have the following entries: [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock [mysql.server] user=mysql basedir=/var/lib [safe_mysqld] err-log=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid Here, you can specify a different directory for error log, otherwise you should not change any entry in this table.
  • 3. Administrative MySQL Command: Here is the list of important MySQL commands, which you will use time to time to work with MySQL database: USE Databasename : This will be used to select a particular database in MySQL workarea. SHOW DATABASES: Lists the databases that are accessible by the MySQL DBMS. SHOW TABLES: Shows the tables in the database once a database has been selected with the use command. SHOW COLUMNS FROM tablename: Shows the attributes, types of attributes, key information, whether NULL is permitted, defaults, and other information for a table. SHOW INDEX FROM tablename: Presents the details of all indexes on the table, including the PRIMARY KEY. SHOW TABLE STATUS LIKE tablenameG: Reports details of the MySQL DBMS performance and statistics.