Configure the mysql environment under windows and use navicat to visualize the database to easily write sql statements.

MySQL connects to local

MySQL download

Directly download the system's own application store and install the latest version.

MySQL connection

  • Edit the environment variable, find the bin directory in the folder where Mysql Server is located, and add it to the PATH path

    C:\Program Files\MySQL\MySQL Server 8.0\bin
    或者
    D:\MY SQL\bin
    
  • Enter pymysql -V on the command line to check the version number to see if it succeeds. If successful, it means that the path to mysql is already in path.
    Insert image description here

  • If you can view the version number, it means the environment variable is set successfully.
    Insert image description here

  • Database login

mysql -h localhost -u root -p test
-h 主机名or ip地址 -u 用户名 -p选择数据库

Insert image description here

Basic SQL operation statements

Create and view database

Note that adding; a semicolon after each statement indicates the end.

  • After entering mysql, the current existing database will be displayed: show databases;

Insert image description here

  • Create a new database:

    #语法:
    CREATE DATABASE [IF NOT EXISTS] 数据库名 [DEFAULT CHARACTER SET 字符集 COLLATE 排序规则字符集]#创建数据库:
    CREATE DATABASE [IF NOT EXISTS] mydb1;
    
  • Enter a database: use 数据库名; Query the current database name: select database();
    Insert image description here

Delete database

DROP DATABASE [IF EXISTS] mydb1;

Modify database

ALTER DATABASE mydb1 CHARACTER SET utf8

Insert, delete, modify data

EnterINSERT INTO 表名(列名1,列名2, …) VALUES(值1, 值2)

INSERT INTO stu (sid, sname, age, gender) 
VALUES
('s_1001', 'zhangSan', 23, 'male');

INSERT INTO stu (sid, sname) 
VALUES
('s_1001', 'zhangSan') ;

Revise: UPDATE 表名 SET 列名1=值1, … 列名n=值n [WHERE 条件]

UPDATE stu SET sname='zhangSanSan', age='32', gender='female' WHERE sid='s_1001';

UPDATE stu SET sname='wangWu', age='30' WHERE age>60 OR gender='female';

UPDATE stu SET sname='liSi', age='20' WHERE age>50 AND gender='male';

UPDATE stu SET gender='female' WHERE gender IS NULL;

UPDATE stu SET age=age+1 WHERE sname='zhaoLiu';

delete: DELETE FROM 表名 [WHERE 条件]

DELETE FROM stu WHERE sid='s_1001';

DELETE FROM stu WHERE sname='chenQi' OR age > 30;

--删除所有  慎用
DELETE FROM stu;

Graphical interface display database

Navicat basic operations

Connect to local mysql database

Click on the upper left corner to connect and enter your username and password to connect

Insert image description hereInsert image description here

Write sql statement

In the query on the left, you can create a new query and then write SQL statements in it to operate the table; you can choose to save the query statement as A specific name to facilitate next query.

Insert image description here

For the sql statement written by , you can select part of it to execute, avoiding the disadvantage of needing to execute it all every time.
用鼠标选择一部分语句,点击上方,运行即可。

Insert image description here

If it is a new view, you can view it in the view on the left column.

Guess you like

Origin blog.csdn.net/m0_63669388/article/details/134095845