Home Database Mysql Tutorial MySQL常用命令 MySQL处理数据库和表的命令_MySQL

MySQL常用命令 MySQL处理数据库和表的命令_MySQL

May 30, 2016 pm 05:10 PM
mysql connection

学习如何管理和导航MySQL数据库和表是要掌握的首要任务之一,下面的内容将主要对MySQL的数据库和表的一些常用命令进行总结,一些我们不得不掌握的命令,一些信手拈来的命令。
一、处理数据库

代码如下:

drop [temporary] table [if exists] tbl_name [, tbl_name, ...]

8、更改表结构
我们会发现,我们会经常修改和改进表结构,特别是在开发初期;但是,每次进行修改时不必都先删除再重新创建表。相反,可以使用alter语句修改表的结构。利用这个语句,可以再必要时删除、修改和增加列。和create table一样,alter table提供了很多子句、关键字和选项。这里只是会说一些简单的使用,比如在表tb_demo表中插入一列,表示email,代码如下:

mysql> alter table tb_demo add column email varchar(45);
Query OK, 0 rows affected (0.14 sec)
Records: 0 Duplicates: 0 Warnings: 0
Copy after login

新的列放在表的最后位置。不过,还可以使用适当的关键字(包括first、after和last)来控制新列的位置。如果想修改表,比如,刚刚加的email,我想加入一个not null控制,代码可以是这样的:

mysql> alter table tb_demo change email email varchar(45) not null;
Query OK, 0 rows affected (0.11 sec)
Records: 0 Duplicates: 0 Warnings: 0
Copy after login

如果觉的这个email这列没有存在的必要了,可以使用下面的代码删除它,例如:

mysql> alter table tb_demo drop email;
Query OK, 0 rows affected (0.09 sec)
Records: 0 Duplicates: 0 Warnings: 0
Copy after login

这篇文章大体上总结了与MySQL常用的一些命令,主要是学习Mysql处理数据库和表的常用命令,希望对大家有帮助。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1273
29
C# Tutorial
1253
24
How to connect Navicat for MySQL to a local MySQL database - How to connect Navicat for MySQL to a local MySQL database How to connect Navicat for MySQL to a local MySQL database - How to connect Navicat for MySQL to a local MySQL database Mar 04, 2024 pm 07:30 PM

The article brought to you in this chapter is about the NavicatforMySQL software. Do you know how NavicatforMySQL connects to the local MySQL database? Then, the editor brings you the method of NavicatforMySQL to connect to the local MySQL database. Interested users can read below. Take a look. Open the computer where Navicatformysql has been installed, and then click the "Connect" option in the upper right corner. In the pop-up new connection window, you can enter the connection name and set the host name to the local database, so just use "localhost", Just leave the password blank. Then if the connection to the convenient database is successful,

How to solve the problem of slow Mysql connection in Docker How to solve the problem of slow Mysql connection in Docker Feb 19, 2024 pm 03:09 PM

After using Docker to deploy MySQL, the connection speed is slow. Through online searches, I found that the problem may be caused by the lack of modules such as DNS resolution during the minimum container installation. Therefore, there will be a problem of super slow connection when connecting. We directly add this sentence skip-name-resolve and directly modify the docker-compose.yml configuration. The configuration is as follows version: "3" services: mysql: image: mysql: latestcontainer_name: mysql_composerestart: alwaysports:-3306:3306command:--default-a

Analysis of the impact of MySQL connection number on database performance Analysis of the impact of MySQL connection number on database performance Mar 16, 2024 am 10:09 AM

Analysis of the Impact of MySQL Connection Number on Database Performance With the continuous development of Internet applications, databases have become an important data storage and management tool to support application systems. In the database system, the number of connections is an important concept, which is directly related to the performance and stability of the database system. This article will start from the perspective of MySQL database, explore the impact of the number of connections on database performance, and analyze it through specific code examples. 1. What is the number of connections? The number of connections refers to the number of client connections supported by the database system at the same time. It can also be managed

Optimizing the high concurrency performance of MySQL connections in Python programs Optimizing the high concurrency performance of MySQL connections in Python programs Jun 30, 2023 pm 12:27 PM

How to optimize the high concurrency performance of MySQL connections in a Python program? Abstract: MySQL is a relational database with powerful performance, but in the case of high concurrency, the connection and query operations of Python programs may affect the performance of the system. This article will introduce some optimization techniques to improve the performance of Python programs and MySQL databases. Use a connection pool: In high concurrency situations, frequently creating and closing database connections will consume a lot of system resources. Therefore, using connection pooling can effectively reduce

How to test the high concurrency performance of MySQL connections on the command line? How to test the high concurrency performance of MySQL connections on the command line? Jun 30, 2023 pm 07:25 PM

How to test the high concurrency performance of MySQL connections from the command line? With the continuous popularization of Internet applications, the high concurrency performance of databases has become one of the focuses of many demands. As a popular open source database, MySQL has also received widespread attention for its high concurrency performance. Before testing the high concurrency performance of MySQL connections, we need to clarify some concepts and preparations: Concurrent connections: refers to multiple clients establishing connections with the database at the same time, and these connections perform database operations at the same time. Connection limit: MySQ

In-depth understanding of the concept and importance of MySQL connection numbers In-depth understanding of the concept and importance of MySQL connection numbers Mar 16, 2024 am 10:27 AM

As a commonly used relational database management system, MySQL is widely used in the field of Web development. When using MySQL, an important concept is the number of connections. This article will delve into the concept of MySQL connection numbers and their importance, and illustrate them with specific code examples. 1. The concept of MySQL connection number In MySQL, the number of connections refers to the number of clients connected to the MySQL server at the same time. When a client establishes a connection with the MySQL server, a number of connections will be occupied. My

How to test the update performance of a MySQL connection from the command line? How to test the update performance of a MySQL connection from the command line? Jun 29, 2023 am 08:36 AM

How to test the update performance of a MySQL connection from the command line? When performing performance testing of MySQL database, it is often necessary to test the connection and update performance of the database. This article will introduce how to use command line tools to perform update performance testing of MySQL connections. First, make sure you have installed MySQL and the MySQL command line tool. Step 1: Create a test database and table. Enter the following command on the command line to create a new test database and table: mysql-uroot-pCREATE

MySQL connection is reset, how to ensure the health of the connection pool through connection keepalive? MySQL connection is reset, how to ensure the health of the connection pool through connection keepalive? Jun 29, 2023 am 11:26 AM

MySQL connection is reset, how to ensure the health of the connection pool through connection keepalive? When using the MySQL database, you often encounter situations where the connection is reset, causing the database connection to be interrupted, which is very unreliable for the application. In order to solve this problem, you can ensure the health of the connection pool by keeping the connection alive. Connection keep-alive means sending a specific query statement when the connection is idle to keep the connection active and prevent the connection from being actively closed by the server. This specific query statement can be a simple SE

See all articles