Home Database Mysql Tutorial MySQL之终端(Terminal)管理数据库、数据表、数据的基本操作

MySQL之终端(Terminal)管理数据库、数据表、数据的基本操作

Jun 07, 2016 pm 04:08 PM
mysql database

MySQL有很多的可视化管理工具,比如ldquo;mysql-workbenchrdquo;和ldquo;sequel-pro-rdquo;。 现在我写MySQL的终端命令操作的

MySQL有很多的可视化管理工具,比如“mysql-workbench”和“sequel-pro-”。 现在我写MySQL的终端命令操作的文章,是想强化一下自己对于MySQL的理解,总会比使用图形化的理解透彻,因为我本来就比较喜欢写代码。同时写出来这些文章,是想要给大家当个参考,希望也能对大家有所帮助,有所提升,这就是我为什么要写终端操作MySQL的文章了。 

注意:MySQL数据库命令不区分大小写。但在MAC的终端,如果你想使用tab自动补全命令,那么你就必须使用大写,这样MAC的终端才会帮你补全命令,否则你按N遍tab都不会有响应。 

1、数据库(database)管理

1.1 create 创建数据库

1.2 show 查看所有数据库

1.3 alter 修改数据库

1.4 use 使用数据库

1.5 查看当前使用的数据库

1.6 drop 删除数据库

2、数据表(table)管理

2.1 create 创建表

2.2 show 显示表

2.3 desc 查看表结构

2.4 alter 修改表结构(增、删、改)

2.4.1 insert 在表中添加列(字段)

2.4.2 alter 修改表(列)字段

2.4.3 delete 删除表(列)字段

2.4.4 rename 重命名表名

2.5 create 利用已有数据创建新表

3、数据的操作及管理

3.1 增加数据(增)

3.2 删除数据(删)

3.3 修改数据(改)

3.4 查询数据(查)

1、数据库(database)管理

1.1 create 创建数据库

create database firstDB;

1.2 show 查看所有数据库

mysql> show databases; information_schema mysql rows in set (0.00 sec) 

1.3 alter 修改数据库

alter 命令修改数据库编码:

默认创建的数据库默认不支持中文字符,如果我们需要它支持中文字符,则将它的编码设置为utf8格式:

mysqltestDB CHARACTER SET UTF8; Query OK, 1 row affected (0.00 sec)

1.4 use 使用数据库

mysql> use firstDB; Database changed

1.5 查看当前使用的数据库

mysql(); () firstdb row in set (0.00 sec) 

1.6 drop 删除数据库

mysql firstDB; Query OK, 0 rows affected (0.00 sec) 

2、数据表(table)管理

我们首先创建一个数据库,,提供我们往后的使用:

mysql testDB; Query OK, 1 row affected (0.00 sec)

创建后记得用use命令进入(使用)数据库,不然后面的操作都会不成功的。 

2.1 create 创建表

mysql PEOPLE ( -> ID int AUTO_INCREMENT PRIMARY KEY, -> NAME varchar(20) not null, , -> BIRTHDAY datetime); Query OK, 0 rows affected (0.01 sec)

2.2 show 显示表

显示当前数据库所有的数据表

mysql> show tables; Tables_in_testdb PEOPLE row in set (0.00 sec) 

2.3 desc 查看表结构

mysql> desc PEOPLE -> ; Field Extra ID auto_increment (AGE BIRTHDAY YES rows in set (0.01 sec) 

2.4 alter 修改表结构(增、删、改)

默认创建的表不支持中文字符,所以需将表编码设置为utf8:

mysql> ALTER TABLE KEYCHAIN CONVERT TO CHARACTER SET UTF8; Query OK, 1 row affected (0.02 sec) Records: 1 Duplicates: 0 Warnings: 0

2.4.1 insert 在表中添加列(字段)

mysqlPEOPLE add star BOOL; Query OK, 0 rows affected (0.02 sec) Records: 0 Duplicates: 0 Warnings: 0

提示:在MySQL里,布尔类型会自动转换为tinyint(1)类型。

我们不妨使用desc去查看一下PEOPLE表结构:

mysql> desc PEOPLE; Field Extra ID auto_increment (AGE BIRTHDAY YES star rows in set (0.00 sec)

现在,你该相信我了吧?

2.4.2 alter 修改表(列)字段

mysqlPEOPLE MODIFY star int; Query OK, 0 rows affected (0.01 sec) Records: 0 Duplicates: 0 Warnings: 0

我们再次使用desc查看PEOPLE表结构:

mysql> desc PEOPLE; Field Extra ID auto_increment (AGE BIRTHDAY YES star rows in set (0.00 sec) 

2.4.3 delete 删除表(列)字段

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
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)

PHP development practice: Use PHPMailer to send emails to users in the MySQL database PHP development practice: Use PHPMailer to send emails to users in the MySQL database Aug 05, 2023 pm 06:21 PM

PHP development practice: Use PHPMailer to send emails to users in the MySQL database Introduction: In the construction of the modern Internet, email is an important communication tool. Whether it is user registration, password reset, or order confirmation in e-commerce, sending emails is an essential function. This article will introduce how to use PHPMailer to send emails and save the email information to the user information table in the MySQL database. 1. Install the PHPMailer library PHPMailer is

Go language and MySQL database: How to separate hot and cold data? Go language and MySQL database: How to separate hot and cold data? Jun 18, 2023 am 08:26 AM

As the amount of data continues to increase, database performance has become an increasingly important issue. Hot and cold data separation processing is an effective solution that can separate hot data and cold data, thereby improving system performance and efficiency. This article will introduce how to use Go language and MySQL database to separate hot and cold data. 1. What is hot and cold data separation processing? Hot and cold data separation processing is a way of classifying hot data and cold data. Hot data refers to data with high access frequency and high performance requirements. Cold data

How to perform incremental data backup of MySQL database using Go language How to perform incremental data backup of MySQL database using Go language Jun 17, 2023 pm 02:28 PM

As the amount of data increases, database backup becomes more and more important. For the MySQL database, we can use the Go language to achieve automated incremental backup. This article will briefly introduce how to use Go language to perform incremental backup of MySQL database data. 1. Install the Go language environment. First, we need to install the Go language environment locally. You can go to the official website to download the corresponding installation package and install it. 2. Install the corresponding library. The Go language provides many third-party libraries for accessing MySQL databases, among which the most commonly used ones are

To what extent can I develop MySQL database skills to be successfully employed? To what extent can I develop MySQL database skills to be successfully employed? Sep 12, 2023 pm 06:42 PM

To what extent can I develop MySQL database skills to be successfully employed? With the rapid development of the information age, database management systems have become an indispensable and important component in all walks of life. As a commonly used relational database management system, MySQL has a wide range of application fields and employment opportunities. So, to what extent do MySQL database skills need to be developed to be successfully employed? First of all, mastering the basic principles and basic knowledge of MySQL is the most basic requirement. MySQL is an open source relational database management

How to use MySQL database for time series analysis? How to use MySQL database for time series analysis? Jul 12, 2023 am 08:39 AM

How to use MySQL database for time series analysis? Time series data refers to a collection of data arranged in time order, which has temporal continuity and correlation. Time series analysis is an important data analysis method that can be used to predict future trends, discover cyclical changes, detect outliers, etc. In this article, we will introduce how to use a MySQL database for time series analysis, along with code examples. Create a data table First, we need to create a data table to store time series data. Suppose we want to analyze the number

MySQL database and Go language: How to perform data caching? MySQL database and Go language: How to perform data caching? Jun 17, 2023 am 10:05 AM

In recent years, the Go language has become increasingly popular among developers and has become one of the preferred languages ​​for developing high-performance web applications. MySQL is also a popular database that is widely used. In the process of combining these two technologies, caching is a very important part. The following will introduce how to use Go language to handle the cache of MySQL database. The concept of caching In web applications, caching is a middle layer created to speed up data access. It is mainly used to store frequently requested data to

How to use MySQL database for image processing? How to use MySQL database for image processing? Jul 14, 2023 pm 12:21 PM

How to use MySQL database for image processing? MySQL is a powerful relational database management system. In addition to storing and managing data, it can also be used for image processing. This article will introduce how to use a MySQL database for image processing and provide some code examples. Before you begin, make sure you have installed a MySQL database and are familiar with basic SQL statements. Create a database table First, create a new database table to store the image data. The structure of the table can be as follows

How to make reliable MySQL database connection using Go language? How to make reliable MySQL database connection using Go language? Jun 17, 2023 pm 07:18 PM

With the large amount of data that needs to be stored and processed, MySQL has become one of the most commonly used relational databases in application development. The Go language is becoming more and more popular among developers due to its efficient concurrency processing and concise syntax. This article will lead readers to implement reliable MySQL database connection through Go language, allowing developers to query and store data more efficiently. 1. Several ways for Go language to connect to MySQL database. There are usually three ways to connect to MySQL database in Go language, which are: 1. Third-party library

See all articles