Use terminal operations database on MacOS to __ database

Source: Internet
Author: User
Tags create database
using the terminal operations database on MacOS

Using terminal operations database on MacOS to create a new database in terminal Access database Select the database you want to use delete the specified database create a datasheet in a database view datasheet information desc method Show Columns method manage datasheet Information Delete Datasheet

preparatory work

1. Install MySQL and have username and password.
2, MySQL has been on your Mac to open. Content Introduction

For the MacOS on the use of terminals on the database to do the following specific steps to introduce. accessing the database at the terminal to create a new database Select the database to use Delete the specified database create a datasheet in a database View data table information Managing data table information Delete data table accessing the database at the terminal

Open the terminal, in between the database access through the terminal, we first through the following command to check whether the MySQL server has been opened.

Ps-ef | grep mysqld

If the MySQL server is already open, the terminal appears as follows:

Use the following command to access the MySQL server that is already open.

/usr/local/mysql/bin/mysql-u root-p

/usr/local/mysql/bin/mysql is the MySQL installation path, root is your MySQL username, the two need to adjust according to their own situation.

Enter the password for the user name after the carriage return.

When the connection succeeds, the terminal appears as follows:

to create a new database

Create Database mydb_2017050601;

Where mydb_2017050601 is the name of the new database.

At this point we look at all the databases through the following statements.

show databases;

The terminal appears as follows:

You can see that the database we just created has been built successfully. Select the database to use

Use mydb_2017050601;

The terminal appears as follows:

Indicates that the specified database selection was successful. Delete the specified database

Drop database mydb_2017050601;

The terminal appears as follows:

At this point we look at the database again, showing the results as follows:

You can see that the database we created earlier has been successfully deleted. create a datasheet in a database

To better demonstrate the content later, we create a new database mydb_2017050602. Then select the database by using the use language.

Then we create a table named EMP for this database. The code is as follows:

Create Taleb EMP (
    empid Numeric (18,0) primary key,
    DeptID numeric (18,0) References Dept (DeptID),
    ename varchar (ten),
    job varchar (a),
    hiredate datetime);

Carriage return, the terminal appears as follows:

Indicates that the data table was created successfully. View data table information

Here are two ways to view a datasheet: desc method Show columns method desc method

    DESC EMP;

The EMP indicates that the statement looks at all the properties of the table named EMP.

The results of the terminal display are as follows:

You can also view the specified properties in a table by using the following statement.

    Desc EMP Empid;

Empid is the property name.

The terminal appears as follows:

Show Columns Method

    Show Columns form EMP;

The terminal appears as follows:

Managing data table information

Make changes to the EMP table by using the following statement:

ALTER TABLE EMP add empadministrator varchar NOT NULL,
    Modify Job Nvarcher (30);

To view the EMP table information again after modification:

View all data tables in the current database by using the following statement:

    Show tables;

The terminal appears as follows:

The following language changes indicate that the EMP is EMP1:

    Rename table emp to EMP1;

When you change the data table again, the terminal displays the following results:

Delete data table

drop table emp1;

Look at the datasheet again and the terminal displays the results as follows:

This blog content to end, welcome correction.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.