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

Layui implements the login interface verification code

This article example shares the specific code of ...

Tips for adding favicon to a website: a small icon in front of the URL

The so-called favicon, which is the abbreviation o...

Explanation of the problem of selecting MySQL storage time type

The datetime type is usually used to store time i...

How to choose transaction isolation level in MySQL project

introduction Let's start with our content. I ...

How to change $ to # in Linux

In this system, the # sign represents the root us...

Detailed explanation on how to modify the default port of nginx

First find out where the configuration file is wh...

MYSQL stored procedures, that is, a summary of common logical knowledge points

Mysql stored procedure 1. Create stored procedure...

In-depth analysis of the slow query problem of MySQL Sending data

Through an example, I shared with you the solutio...

Detailed tutorial on building an ETCD cluster for Docker microservices

Table of contents Features of etcd There are thre...

MySQL uses covering index to avoid table return and optimize query

Preface Before talking about covering index, we m...

Example code of implementing starry sky animation with CSS3 advanced LESS

This article introduces the sample code of advanc...

Html Select uses the selected attribute to set the default selection

Adding the attribute selected = "selected&quo...

MySQL 8.0.20 installation and configuration tutorial under Docker

Docker installs MySQL version 8.0.20 for your ref...