*Open the database in the terminal: Method 1. Run the cmd terminal as an administrator to open the database: net start mysql57 (service name) ==> Connect to the database: mysql -u username -p ==> Enter the password
Method 2. In Open the database in mysql-client: enter the password directly to enter.
*Logout: exit
*Remote connection to the database: mysql -h ip address -u Username of the other party -p ==> Enter the password of the other party
*Database type: Relational database :
MySQL , Oracle, etc
; A semicolon should be added at the end of the command;
drop database demo; delete database demo
use demo switch database # To operate the database, you must first choose to use a database
select database; view the currently used database
*Table operation: show tables; view all tables # view tables also add s
create table demo(column1,column2,...); create table demo Example: create table demo(id int auto_increment primary_key, name varchar(20))
drop table demo; delete table demo
desc demo; view table structure
show create table demo; View the statement used to create the table demo
rename table demo to newdemo; Change the table name of the table demo to newdemo
*Data operation: Add: insert into table name values(...); insert full column
insert into table name values(...),(...),...; insert multiple pieces of data in the whole column
insert into table name(column 1, column 2,...) values(value 1, value 2,...) Default insert
and delete: delete from table name where condition; delete the data in the table (warning: if the where condition is not added later, all the data in the table will be deleted) # Example: delete from student where id=4;
Change: update table name set column 1 = value 1, column 2 = value 2,...where conditions; modify the data in the table (warning: all columns will be modified without conditions) # Example: update student set name= tom,age=18 where id=7;
check: select * from table name; check all data in a certain table (where * represents all columns, if you only want to query some columns, you can separate them with commas, for example select name, age from table name;)
conditional query: a. Syntax: select * from table name where condition;
b. Comparison operators (=, >, <, >=, <=, !=): Example: select * from student where id >=3;
c. Logical operators (and, or, not): Example: select * from student where id>=3 and gender=0; Query students whose id>=3 and gender is female
d. Fuzzy query: like : % means any number of arbitrary characters, _ means one arbitrary character
Example: select * from student where name like "周%"; => get results such as Jay Chou, Stephen Chow...
select * from student where name like "周_" ; => Get results like Zhou Xun...
e. Range query: Example: select * from student where id in (2,7,12); # Query students with id 2,7,12
select * from student where id between 5 and 10; # Query id in 5- Students between 10
f. Empty query: Example: select * from student where address is null; # Query students whose address is empty (not null is not null)
g. Priority: parentheses > not > comparison operator > logic operator; and > or => use () to change the priority
h. Sort: select * from table name order by column 1 asc/desc, column 2 asc/desc, ... ; # asc ascending desc descending
Add, delete, modify and check MySQL database
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=325890958&siteId=291194637
Recommended
Ranking