MySQL8.0 basic operation

MySQL basic operations

1. Start the service

1. Use ctrl+alt+delete to open the task manager, click on services, and find your MySQL service name. My MySQL service name is MySQL80.
Insert picture description here
2,

net start MySQL80

Start service

2. Turn off the service

net stop MySQL80

Insert picture description here

mysqladmin -u root -p shutdown

Insert picture description here

3. Modify user password

mysqladmin -u root -p password 12345

Insert picture description here

4. Log in

mysql -u root -p

Insert picture description here

5. Display version

show variables like 'version';

Insert picture description here

6. Create/Delete Database

Create database db1:

create database db1;

Show all databases:

show databases;

Delete the database db (the following operation is to avoid errors when performing a delete operation without db):

drop database if exists db;

Insert picture description here
Insert picture description here

7. Create/Delete Table

Operate under db1 database:

use db1;

Create a table user, which includes two attribute fields userID and userNname:

create table user (userID varchar(10),userNname varchar(10));

Delete table user1:

drop table if exists user1;

Insert picture description here
Insert picture description here

8. View all tables in the database

show tables;

Insert picture description here

9. View the attribute fields of the table

desc user;

Insert picture description here

10. Search for table data

1. Find all the data in the user table:

select * from user;

Insert picture description here
2. Find the data containing b in userName in the user table:Insert picture description here

11. Add operation to table data

insert into user values('001','a');

Insert picture description here

12. Modify the table data

Change the userName of the data with userID 004 in the user table to d:

update user set userName='d' where userID='004';

Insert picture description here

13. Delete operation on table data

Delete the data with userID 004 in the user table:

delete from user where userID='004';

Insert picture description here

14. Add table attribute fields

Add the userTel attribute field to the table user (the default is to add it at the end):

alter table user
add userTel varchar(10);

Insert picture description here
Add the userSchool attribute field after the userName attribute field:

alter table user
add userSchool varchar(10) after userName;

Insert picture description here
Add the userAddr attribute field to the user table to make it at the forefront:

alter table user
add userAddr varchar(10) first;

Insert picture description here

15. Delete the attribute field of the table

Delete the userAddr attribute field in the user table:

alter table user
drop userAddr;

Insert picture description here

16. Modify the attribute fields of the table

Change the userSchool attribute field in the table user to userS:

alter table user
change userSchool userS varchar(10);

Insert picture description here

17. Rename the table

Rename the user table to users:

alter table user
rename users;

Insert picture description here

18. Backup

Use output redirection to store mydb data to the path after >:

mysqldump -u root -p mydb > C:\mydb_backup.sql

Insert picture description here

19. Recovery

If the mydb database is deleted, first create an empty mydb database, and then use the following command to use input redirection to write the original backup database to mydb:

mysql -u root -p mydb < C:\mydb_backup.sql

Insert picture description here

Guess you like

Origin blog.csdn.net/Doigt_/article/details/108715810