In daily website maintenance and management, a lot of SQL statements are used. Here are some commonly used commands for your reference. 1. Display database 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:
|
<<: How to deploy Confluence and jira-software in Docker
>>: Detailed explanation of JS variable storage deep copy and shallow copy
This article example shares the specific code of ...
Compared with Windows system, Linux system provid...
1. What is a proxy server? Proxy server, when the...
view: When a temporary table is used repeatedly, ...
Table of contents question: There are 2 tokens in...
When using CSS pseudo-elements to control element...
This article example shares the specific code of ...
Elasticsearch is very popular now, and many compa...
To achieve the following goals: Mysql database wi...
1. The three files /etc/hosts, /etc/resolv.conf a...
<br />The color of a web page is one of the ...
Table of contents Overview What are Generics Buil...
vmware vsphere 6.5 is the classic version of vsph...
Scenario You need to use the xshell tool to conne...
This article shares the installation and configur...