18 common commands in MySQL command line

18 common commands in MySQL command line

In daily website maintenance and management, a lot of SQL statements are used.
Proficient use has many benefits for website management, especially when managing a group of sites.

Here are some commonly used commands for your reference.

1. Display database
show databases
Display Table
show tables;

2. Create a user <br /> Create a root user with a password of 123

use mysql; 
grant all on *.* to root@'%' identified by '123' with grant option; 
commit;

3. Change password

grant all on *.* to xing@'localhost' identified by '123456' with grant option; 
update user set password = password('newpwd') where user = 'xing' and host='localhost'; 
flush privileges;

4. Create a database testdb:

create database testdb;

5. Preventive creation of database:

create database if not testdb;

6. Create a table:

use testdb; 
create table table1( 
username varchar(12), 
password varchar(20));

7. Preventive creation of table aaa:

create table if not exists aaa(ss varchar(20));

8. View the table structure:

describe table1;

9. Insert data into table1:

insert into table1(username,password) values 
('leizhimin','lavasoft'), 
('hellokitty','hahhahah'); 
commit;

10. Query table table1:

select * from table1;

11. Change data:

update table1 set password='hehe' where username='hellokitty'; 
commit;

12. Deleting data:

delete from table1 where username='hellokitty'; 
commit;

13. Add a column to the table:

alter table table1 add column( 
 sex varchar(2) comment 'Gender', 
 age date not null comment 'age' 
); 
commit;

14. Modify table structure

Create a table table1 from the query:

create table tmp as 
select * from table1;

15. Delete table table1:

drop table if exists table1; 
drop table if exists tmp;

16. Back up the database testdb

mysqldump -h 192.168.3.143 -u root -p pwd -x --default-character-set=gbk >C:\testdb.sql

17. Delete the database testdb

drop database testdb;

18. Restore the testdb database <br /> First, create the testdb database, and then use the following command to perform local recovery

mysql -u root -pleizhimin testdb <C:\testdb.sql

These 18 MYSQL commands are often used by administrators in daily maintenance. Proficient use of these commands will make your work very easy.

You may also be interested in:
  • Detailed explanation of how to use CMD command to operate MySql database
  • Mysql command line mode access operation mysql database operation

<<:  How to deploy Confluence and jira-software in Docker

>>:  Detailed explanation of JS variable storage deep copy and shallow copy

Recommend

Common operation commands of MySQL in Linux system

Serve: # chkconfig --list List all system service...

Explanation on whether to choose paging or loading in interactive design

The author of this article @子木yoyo posted it on hi...

Comprehensive summary of MYSQL tables

Table of contents 1. Create a table 1.1. Basic sy...

Similar to HTML tags: strong and em, q, cite, blockquote

There are some tags in XHTML that have similar fu...

HTML table border control implementation code

Generally, when we use a table, we always give it...

MySQL 4G memory server configuration optimization

As the number of visits to the company's webs...

Detailed explanation of semiotics in Html/CSS

Based on theories such as Saussure's philosop...

Solution for VMware Workstation Pro not running on Windows

After the National Day holiday, did any of you fi...

Detailed process of compiling and installing Storm on Kylin V10 server

1 Introduction Apache Storm is a free, open sourc...

...

js development plug-in to achieve tab effect

This article example shares the specific code of ...

Nginx uses ctx to realize data sharing and context modification functions

Environment: init_worker_by_lua, set_by_lua, rewr...

Difference between varchar and char types in MySQL

Table of contents aforementioned VARCHAR Type VAR...

WeChat Mini Programs Implement Star Rating

This article shares the specific code for WeChat ...

HTML implements a fixed floating semi-transparent search box on mobile

Question. In the mobile shopping mall system, we ...