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

Operations of adding, deleting, changing and searching in MYSQL Database

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

Share

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

Mysql has become one of the most popular relational databases, the latest version of mysql has reached 8.0. in addition, it is a good friend of php, and the former lamp architecture is all the rage. Today let's take a look at some operations in the database.

First of all, for the record, the version of mysql I demonstrated is 5.7.28.

Create a new database

First of all, teach you a skill, forget the library syntax how to do, MYSQL provides help to help you. For example, you forget the build statement and only know that the opening command is create. Then you can enter help craete on the client side of MySQL

Mysql > help create... Topics: CREATE DATABASE CREATE EVENT CREATE FUNCTION CREATE FUNCTION UDF...

Now that we know the first two words of the database-building statement, move on to help to see what the specific syntax looks like.

Mysql > help create database... CREATE {DATABASE | SCHEMA} [IF NOT EXISTS] db_name [create_specification]... create_specification: [DEFAULT] CHARACTER SET [=] charset_name | [DEFAULT] COLLATE [=] collation_name.

Now we know what the specific grammar is.

Syntax:

Create database [if not exists] database name [[charset character set name] [collate proofreading set name]]

If not exists indicates that the database is not created until it does not exist.

Character set this has the same meaning as the html character set, usually choosing utf8 or utf8mb4

Proofreading set this is related to character alignment and sorting.

Let's complete the establishment of a job library

Mysql > CREATE DATABASE IF NOT EXISTS jobs-> CHARSET utf8-> COLLATE utf8_general_ci;Query OK, 1 row affected (0.01sec)

View the database

When a library is built, you need to check to see if it is really built.

The syntax for viewing the database is as follows:

Show databases [like patter]

This command can show all the databases, and you can find the database by schema.

Now let's see how many libraries there are at present.

Mysql > SHOW DATABASES;+-+ | Database | +-+ | information_schema | | jobs | | mysql | | performance_schema | | sys | +-+ 5 rows in set (0.00 sec)

So if I want to find out which libraries end in s, how to find them?

Mysql > SHOW DATABASES LIKE'% rows in set + | Database (% s) | +-+ | jobs | | sys | +-+ 2 rows in set (0.00 sec)

Select a database

If we want to create tables in the database, or add or delete data, the first thing we must do is to select the database. These operations are meaningful and can be performed correctly only if the database is selected.

The operation of selecting a database is very simple and the syntax is as follows:

Use database name mysql > USE jobs;Database changed

In this way, the library jobs is selected.

Modify the library

When I find that the character set or proofreading set is not set up correctly, how can I change it?

Syntax:

ALTER DATABASES library name CHASET character set name COLLATE proofreading set name

As you can see, the modification is basically the same as the new operation, except that CREATE has been changed to ALTER.

Delete Library

The name of the library established before is jobs, but now I think the last s can be left out. So can I change the name of the library? Sorry, the name of the library cannot be changed, so we can only delete the library jobs, and then re-establish the library job.

Delete library syntax:

DROP DATABASE [IF EXISTS] library name mysql > DROP DATABASE IF EXISTS jobs;Query OK, 0 rows affected (0.01 sec) mysql > CREATE DATABASE job-> CHARSET utf8mb4-> COLLATE utf8mb4_general_ci;Query OK, 1 row affected (0.00 sec)

Note: deletion is an extremely dangerous operation. It would be miserable if you really delete the library and run away!

These are the details of MYSQL database operations (additions, deletions, changes and queries). Please pay attention to other related articles for more.

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