Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

โ€œInvest in yourself โ€” your confidence is always worth it.โ€

Explore Cosmetic Hospitals

Start your journey today โ€” compare options in one place.

MySQL Commands & Query Cheatsheet Example

List All Users in a MySQL Database Server

Are you looking for the MySQL SHOW USERS command? Unfortunately, MySQL does not have the SHOW USERS command like SHOW DATABASES, SHOW TABLES, etc., therefore to list all users in a MySQL database server, you use the following query:

> mysql -u root -p
Enter password: ***********
mysql> use mysql;
Database changed
mysql> SELECT user FROM user;
Code language: PHP (php)

Show current user

To get the information on the current user, you use the user() function as shown in the following statement:

mysql> SELECT user();

Show current logged users

To list all users that are currently logged in the MySQL database server, you execute the following statement:

SELECT 
    user, 
    host, 
    db, 
    command 
FROM 
    information_schema.processlist;Code language: CSS (css)

How to change a mysql user password?

$ mysql -u root -p
mysql> use mysql;

- The syntax is as follows for mysql database server version 5.7.5 or older:
mysql> SET PASSWORD FOR 'user-name-here'@'hostname' = PASSWORD('new-password');

- For mysql database server version 5.7.6 or newer use the following syntax:
mysql> ALTER USER 'user'@'hostname' IDENTIFIED BY 'newPass';

- You can also use the following sql syntax:
mysql> UPDATE mysql.user SET Password=PASSWORD('new-password-here') WHERE USER='user-name-here' AND Host='host-name-here';Code language: JavaScript (javascript)

How To Enable & Disable Remote Access to MySQL

Locate mysql config file such as my.cnf and Add "bind-address = 0.0.0.0" if you want to mysql should be accessible from localhost

[mysqld]
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
datadir         = /var/lib/mysql
log-error       = /var/log/mysql/error.log
bind-address            = 127.0.0.1

- Restart mysql to make it effective


Locate mysql config file such as my.cnf and Add "bind-address = 0.0.0.0" if you want to mysql should be accessible from localhost

[mysqld]
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
datadir         = /var/lib/mysql
log-error       = /var/log/mysql/error.log
bind-address            = 0.0.0.0

- Restart mysql to make it effective
Code language: JavaScript (javascript)

Mysql backup a Database using mysqldump

Generate the backup of a single database
$ mysqldump -u root -p sakila > file_20200424.sql

Generate the backup of multiple databases or all the databases
$ mysqldump -u root -p --databases sakila employees > file.sql

Generate the backup of database structure
$ mysqldump -u root -p --no-data sakila > file.sql

Generate the backup of a specific table
$ mysqldump -u root -p sakila actor payment > file.sql

How to run mysql command without login using shell?


mysql -u root --password='Gshnd$26#12' -e "create database testdb"
mysql -u root --password='Gshnd$26#12' -e "use testdb"
mysql -u datadog --password=Gsh534shs -e "show slave status"
mysql -u root --password='Gshnd$26#12' -e "use testdb" && "create table raju (customer_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, first_name TEXT, last_name TEXT)"
Code language: JavaScript (javascript)

mySql Query basic Example


$ mysql -u root -p

create database testdb

use testdb

CREATE TABLE shop (
    article INT UNSIGNED  DEFAULT '0000' NOT NULL,
    dealer  CHAR(20)      DEFAULT ''     NOT NULL,
    price   DECIMAL(16,2) DEFAULT '0.00' NOT NULL,
    PRIMARY KEY(article, dealer));
INSERT INTO shop VALUES
    (1,'A',3.45),(1,'B',3.99),(2,'A',10.99),(3,'B',1.45),
    (3,'C',1.69),(3,'D',1.25),(4,'D',19.95);

SELECT * FROM shop ORDER BY article;
Code language: JavaScript (javascript)

How to create user in mysql


$ CREATE USER 'sammy'@'localhost' IDENTIFIED BY 'DevOpsSchool$123';
$ GRANT ALL PRIVILEGES ON *.* TO 'sammy'@'localhost' WITH GRANT OPTION;
$ FLUSH PRIVILEGES;
$ exit
$ mysql -u sammy -pCode language: PHP (php)

GRANT with database name wildcard & Pattern in MySQL?


If I use back-tics instead of single quotes in the syntax, it appears to work just fine:

mysql > grant all on `projectA\_%`.* to `projectA`@`%`;
mysql > GRANT ALL PRIVILEGES ON `my%`.* TO rajesh@'localhost' WITH GRANT OPTION;Code language: JavaScript (javascript)

How to change root password?

Option #1 
$ mysql -u root
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('password');
mysql> flush privileges;
mysql> exit;

Option #2
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Rajesh$123sa332' USING 'mysql_native_password';
mysql> flush privileges;

Option #3
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('Rajesh$123sa332');
mysql> flush privileges;

Option #4
mysql > ALTER USER 'root'@'localhost' IDENTIFIED BY 'Rajesh$123sa332';
mysql> flush privileges;Code language: PHP (php)

mysql command to import database

$ mysql -u galaxy_dbuser -p galaxy_database < file.sql

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services โ€” all in one place.

Explore Hospitals
I'm Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

Top 10 Patch Management Tools in 2026: Features, Pros, Cons & Comparison

Introduction: The Importance of Patch Management in 2026 In 2026, as cyber threats evolve and technology becomes more complex, patch management tools are critical for maintaining cybersecurity…

Read More

Top 10 Remote Monitoring & Management (RMM) Tools in 2026: Features, Pros, Cons & Comparison

Introduction In today’s fast-paced, technology-driven world, businesses rely on the seamless functioning of their IT infrastructure. This makes Remote Monitoring & Management (RMM) tools essential for managing,…

Read More

Top 10 Server Management Tools in 2026: Features, Pros, Cons & Comparison

Introduction Server management tools are essential for businesses in 2026 to maintain the performance, reliability, and security of their IT infrastructure. These tools help streamline the management…

Read More

Top 10 Endpoint Management Tools in 2026: Features, Pros, Cons & Comparison

Introduction In 2026, businesses of all sizes are increasingly reliant on a variety of devicesโ€”laptops, desktops, mobile devices, and other endpointsโ€”that connect to their networks. With the…

Read More

Top 10 Disaster Recovery Tools in 2026: Features, Pros, Cons & Comparison

Introduction In 2026, disaster recovery (DR) is more crucial than ever. Businesses rely heavily on digital infrastructure, and even brief disruptions can lead to significant financial losses,…

Read More

Top 10 Backup & Recovery Tools in 2026: Features, Pros, Cons & Comparison

Introduction In todayโ€™s digital world, data is the backbone of virtually every business operation. As the amount of critical data grows, so does the need for robust…

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
0
Would love your thoughts, please comment.x
()
x