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

MySQL whole table encryption solution keyring_file detailed explanation

illustrate MySql Community Edition supports table...

Detailed explanation of how to customize the style of CSS scroll bars

This article introduces the CSS scrollbar selecto...

MySQL uses variables to implement various sorting

Core code -- Below I will demonstrate the impleme...

Practice of dynamically creating dialog according to file name in vue+el-element

Table of contents background accomplish 1. Encaps...

MySql 8.0.16-win64 Installation Tutorial

1. Unzip the downloaded file as shown below . 2. ...

Will css loading cause blocking?

Maybe everyone knows that js execution will block...

Interpretation of syslogd and syslog.conf files under Linux

1: Introduction to syslog.conf For different type...

Detailed explanation of jquery tag selector application example

This article example shares the specific code of ...

JavaScript Factory Pattern Explained

Table of contents Simple Factory Factory Method S...

How to deploy Angular project using Docker

There are two ways to deploy Angular projects wit...

Introduction to HTML method of opening link files using hyperlinks

a and href attributes HTML uses <a> to repr...

JavaScript to implement search data display

This article shares the data display code for Jav...

Detailed explanation of CSS3 text shadow text-shadow property

Text shadow text-shadow property effects: 1. Lowe...

Enabling and configuring MySQL slow query log

Introduction MySQL slow query log is an important...