Get the App
SLTechnology News&Howtos  ›  Database  › 

Basic operation of MySQL

Shulou Source: shulou.com Published: 2022-06-01 11:31:41 10月30日 Update

First, after installation

1After installation in root Linux, the password is empty. Use the following command to create the password.

[root@host] # mysqladmin-u root password "new_password"

2, connect to the MySQL server

[root@host] # mysql-u root-pEnter password:*

3. Exit quit or exit

[root@host] # quit [root@host] # exit II, database operation

1, view all databases

[root@host] # show databases

2, create the database

[root@host] # create database database name charset utf8

3. Delete the database

[root@host] # drop database database name

4. Switch the database

[root@host] # use database name

5. View the database you are using

[root@host] # select database (); III, table operation

1, view all tables in the database

[root@host] # show tables

2, create a table

Auto_increment: indicates self-growing primary key: primary key not null: not empty [root@host] # create table table name (column type)

Example

[root@host] # create table student (id int auto_increment primary key,name varchar (20) not null,gender tinyint not null,address varchar (40), isDelete tinyint default 0) ENGINE=InnoDB DEFAULT CHARSET=utf8

3, delete the table

[root@host] # drop table table name

4, view the table structure

[root@host] # desc table name; IV, data manipulation

1, insert data

INSERT INTO table_name (field1, field2,...fieldN) VALUES (value1, value2,...valueN)

2 where statement

SELECT field1, field2,...fieldN FROM table_name1, table_ name2...[WHERE condition1 [AND [OR]] condition2. You can use one or more tables in the query statement, using commas, splits, and where statements to set query conditions. You can specify any condition in the WHERE clause. You can specify one or more conditions using AND or OR. The WHERE clause can also be applied to SQL's DELETE or UPDATE commands. The WHERE clause is similar to the if condition in a program language, reading the specified data according to the field values in the MySQL table.

3. Query data

In the SELECT column_name,column_nameFROM table_ name [where Clause] [LIMIT N] [OFFSET M] query statement, you can use one or more tables, split the tables with commas (,), and use the where statement to set the query conditions. The SELECT command can read one or more records. You can use an asterisk (*) instead of other fields. The SELECT statement returns all the field data of the table. You can use the WHERE statement to include any condition. You can use the LIMIT property to set the number of records returned. You can specify the data offset to start the query with the SELECT statement through OFFSET. The offset is 0 by default.

4Query update query

UPDATE table_name SET field1=new-value1, field2=new-value2 [WHERE Clause]

5Die delete statement

DELETE FROM table_name [WHERE Clause] if no WHERE clause is specified, all records in the MySQL table will be deleted.

5meme like clause

%: any character of any length _: matches any single character SELECT field1, field2,...fieldN FROM table_nameWHERE field1 LIKE condition1 [AND [OR]] filed2 = 'somevalue'

Example

Mysql > use RUNOOB;Database changedmysql > SELECT * from runoob_tbl WHERE runoob_author LIKE'% COM' +-+ | runoob_id | runoob_title | runoob_author | submission_date | +- -- +-+ | 3 | Learning Java | RUNOOB.COM | 2015-05-01 | | 4 | Learning Python | RUNOOB.COM | 2016-03-06 | +- -+ 2 rows in set (0.01 sec)

Finally, there is a link to add users, delete users and authorized blogs on MySQL.

Tags: Data database statement query condition clause command multiple field between character password user comma offset learning middle finger single blog can be accessed through the Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple MariaDB NVidia MySQL Docker