Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Database installation process and basic SQL statements under Linux

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Mysql installation startup

1. Centos install mysql, enter commands on the network (there are other installation methods, such as source code and rpm package)

After successful installation:

Note: under root users

two。 When you start mysqld (server), you can see that the network part of mysql server is based on tcp, and it is speculated that mysql can be used locally and across networks (not to mention cross-network here)

Note: password can be set to empty here.

Create users and Authorization

1. Create a user

: CREATE USER 'username'@'host' IDENTIFIED BY' password'

two。 Authorization

Description: privileges-user's operation rights, such as SELECT, INSERT, UPDATE, etc. If you want to grant the permissions, use ALL.;databasename-database name, tablename- table name, and if you want to grant the user the appropriate operation permissions on all databases and tables, you can use *, such as *. *.

GRANT privileges ON databasename.tablename TO 'username'@'host'

3. Set and change user password

SET PASSWORD FOR 'username'@'host' = PASSWORD (' newpassword'); if it is the current login user, use SET PASSWORD = PASSWORD ("newpassword")

Example: SET PASSWORD FOR 'pig'@'%' = PASSWORD ("123456")

4. Revoke user rights

REVOKE privilege ON databasename.tablename FROM'username'@'host'

Description: privilege, databasename, tablename-same as authorization section

5. Delete user

DROP USER 'username'@'host'

Basic concept

RDBMS [Relational Database Management system (Relational Database Management System)]

Some terms of RDBMS:

Database: a database is a collection of associated tables. .

Data table: a table is a matrix of data. A table in a database looks like a simple spreadsheet.

Column: a column (data element) contains the same data, such as postcode data.

Row: a row (= tuple, or record) is a set of related data, such as a piece of data that a user subscribes to.

Redundancy: storing twice as much data, redundancy can make the system faster.

Primary key: the primary key is unique. There can be only one primary key in a data table. You can use the primary key to query data.

Foreign keys: foreign keys are used to associate two tables.

Compound key: compound key (compound key) uses multiple columns as a single index key, which is generally used for composite indexes.

Indexes: use indexes to quickly access specific information in database tables. An index is a structure that sorts the values of one or more columns in a database table. A catalogue similar to a book.

Referential integrity: referential integrity requires that references to entities that do not exist are not allowed in the relationship. And entity integrity is the integrity constraint that the relational model must meet in order to ensure the consistency of the data.

Common operation of mysql

1. Access to the local database (test)

two。 Show the current database and create / delete the database

Show databases

Note: the semicolon cannot be reduced.

Create and display:

Create database ""

Delete and display:

Command: drop databases ""

3. View selected database table information (table creation)

Example: create a menu with dates (key), breakfast, lunch, and dinner.

CREATE TABLE table_name (column_name column_type)

Display the table:

4. Insert data in the MySQL table use INSERT INTO SQL statements to insert data.

Example: insert 8-1 to 8-4 breakfast, lunch and evening meals in the table.

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

The insertion results show:

5. Query the specified record

SELECT field1, field2,...fieldN table_name1, table_ name2...[WHERE Clause] [OFFSET M] [LIMIT N]

6.where statement

SELECT field1, field2,...fieldN FROM table_name1, table_ name2...[WHERE condition1 [AND [OR]] condition2.

7. Modify data

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

8. Delete data

DELETE FROM table_name [WHERE Clause]

Example: delete the record that dinner is apple

9.LINK clause

It is the basic syntax for reading data from a table, similar to the "=" of where.

SELECT field1, field2,...fieldN table_name1, table_name2...WHERE field1 LIKE condition1 [AND [OR]] filed2 = 'somevalue'

10.MySQL sorting

If we need to sort the data we read, we can use the ORDER BY clause of MySQL to set which field and which way you want to sort, and then return the search results.

SELECT field1, field2,...fieldN table_name1, table_name2...ORDER BY field1, [field2...] [ASC [DESC]]

Example: sort in descending order (Note: ASC of DESC stands for descending and ascending order, respectively)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report