MySQL database terminal - common operation command codes

MySQL database terminal - common operation command codes

1. Add users

 //Create a new usercreate user username identified by 'password'; 
//View existing users and host names select user,host from mysql.user; 

2. Change the username and host

 //Change the username rename user 'original username'@'host' to 'new username'@'host'; 

3. Change your password

 //Change password mysqladmin -u user -p original password password new password 

4. Delete User

 //Delete user drop user username@'host'; 

5. Query all users and hosts

 //View existing users and host names select user,host from mysql.user;

6. View the database

 //View the database SHOW DATABASES; 

7. Create a database

 //Create a database CREATE DATABASE database name; 

8. View database definition information

 //View the database definition information SHOW CREATE DATABASE database name; 

9. Delete the database

 //Delete the database DROP DATABASE database name; 

10. Refresh permissions

 //Flush the MySQL privilege table FLUSH PRIVILEGES; 

11. Common commands are as follows

 //Login to mysql -u user -p password mysql -u user -p password -h host IP
 
 
//Change the command name prompt \u@\h \d
prompt mysql \d>
prompt mysql (\d)>
 
//Display the current server versionSELECT VERSION();
//Display the current dateSELECT NOW();
//Display the current userSELECT USER();
//Set the client encoding SET NAMES gbk;
//Show the opened database SELECT DATABASE();
//View the port show global variables like 'port';
 
//View existing users and host names select user,host from mysql.user;
 
//Create a new usercreate user username identified by 'password'; 
 
//Delete user drop user username@'host';
 
//Change the username rename user 'original username'@'host' to 'new username'@'host';
 
//Change password mysqladmin -u user -p original password password new password update mysql.user set password = password('password') where user = 'user' and host = 'host';
 
//Authorize grant all privileges on zhangsanDb.* to zhangsan@'%' identified by 'zhangsan';
all privileges: All privileges.
select: Read permission.
delete: Delete permission.
update: Update permission.
create: Create permission.
drop: delete database and table permissions.
 
Username@host represents the authorized user and the IP address that the user is allowed to log in. There are several types of Host:
localhost: This user is only allowed to log in locally and cannot log in remotely.
%: Allow remote login from any machine except the local machine.
192.168.52.32: The specific IP means that the user is only allowed to log in from the specific IP.
 
//View the information of newly added database permissions select user,Db,host,select_priv,insert_priv,update_priv,delete_priv from mysql.db where user='zhangsan';
 
//Flush the MySQL privilege table FLUSH PRIVILEGES;
 
//Create a database CREATE DATABASE database name;
CREATE DATABASE IF NOT EXISTS database name; -- Create it if it does not exist. CREATE DATABASE IF NOT EXISTS database name CHARACTER SET gbk;
//Modify the database ALTER DATABASE database name CHARACTER SET = utf8;
//View the database SHOW DATABASES;
//View the database definition information SHOW CREATE DATABASE database name;
//Delete the database DROP DATABASE database name;
//If the database exists, delete it DROP DATABASE IF EXISTS database name;
//Switch database USE database name;
//View all tables in the database SHOW TABLES;
//View a database table SHOW TABLES FROM database name;
//View the table structure DESC table name;
SHOW COLUMNS FROM table name;
//View the table statement SHOW CREATE TABLE table name;
//Delete table DROP TABLE table name;
 
Modify table // delete column alter TABLE table name DROP column name;
//Change the name of the table RENAME TABLE table name TO new table name;
//Modify the table character set alter TABLE table name CHARACTER SET character set //Modify the column name alter TABLE table name CHANGE column name new column name column type;
//Add columns alter table table name add column name column type;

This is the end of this article about MySQL database terminal - common operation command codes. For more relevant MySQL database common operation command codes, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Python MySQL database basic operations and project examples
  • MySQL database aggregate query and union query operations
  • Detailed basic operations on data tables in MySQL database
  • MySQL database operations and data types
  • MySQL learning database operation DML detailed explanation for beginners
  • MySQL learning to create and operate databases and table DDL for beginners
  • MySQL database data table operations

<<:  A few things about favicon.ico (it’s best to put it in the root directory)

>>:  Text pop-up effects implemented with CSS3

Recommend

In-depth understanding of the use of Vue

Table of contents Understand the core concept of ...

Docker deploys mysql to achieve remote connection sample code

1.docker search mysql查看mysql版本 2. docker pull mys...

Vue local component data sharing Vue.observable() usage

As components become more detailed, you will enco...

Public free STUN servers

Public free STUN servers When the SIP terminal us...

How to use nginx as a proxy cache

The purpose of using cache is to reduce the press...

Reasons and solutions for MySQL failing to create foreign keys

When associating two tables, a foreign key could ...

Introduction to MySQL Connection Control Plugin

Table of contents 1. Introduction to the connecti...

How to build a drag and drop plugin using vue custom directives

We all know the drag-and-drop feature of HTML5, w...

Vue2.x configures routing navigation guards to implement user login and exit

Table of contents Preface 1. Configure routing na...

Summary of common Linux distribution mirror source configuration

I have been researching Linux recently and tried ...

How to use ES6 class inheritance to achieve a gorgeous ball effect

Table of contents introduce Implementation steps ...

【HTML element】Detailed explanation of tag text

1. Use basic text elements to mark up content Fir...

How to add double quotes in HTML title

<a href="https://www.jb51.net/" titl...

Metadata Extraction Example Analysis of MySQL and Oracle

Table of contents Preface What is metadata Refere...