Linux system under Mysql using a simple tutorial (a) _mysql

Source: Internet
Author: User
Tags create database

If you are inquiring about these related questions, you are a program ape that is or is preparing to engage in it, for a program ape, a program that will not use the Linux system apes are not a good program ape Oh! Because Windows is sometimes really crazy, and I believe that there is no habit can not be changed. So the following are used in Linux systems:

Install MySQL command:$ sudo apt-get install-y mysql-server

View the version command for MySQL (note-V is uppercase or the following error will occur ): $ mysql-v


start mysql command (Other functions such as shutdown, restart, etc.) can be replaced by the corresponding Stop,restart and other letters. : $sudo service MySQL start

This command requires root permission to be used, no prompts after startup success, no news is good news for Linux, so don't worry, it has started successfully.

(Root permissions: If the "account" point of view, it refers to the "system administrator" identity, that is, Superuser, with the highest privileges. In the context of a directory, it refers to the "root directory", which is "/"

Obviously this paragraph refers to the first case: System administrator. )

After startup, enter the MySQL command for:$ mysql-u username -P password

First login, the user name is generally root, the password after the installation system will prompt you to enter. After successfully entering MySQL, the prompt in the command line becomes "mysql>". Because the MySQL command is a little different from the Linux command, the MySQL command always ends with ";". This is something that needs a little attention. (The above password can be directly lost after the-p, you can also lose in the second row, the difference is that the second line of the password in the form of invisible)

After entering MySQL, first check the database :> show databases; (Note semicolon ";" Do not fall)
The system will bring a few data, such as Performance_schema, Information_schema,mysql. It is best not to delete these self-contained databases lest they be abnormal.


There are two possibilities after viewing the database, either by building a new database yourself or by deleting a database, so I'll record the two together and know that they are the same level when you use them.

Create a database command:> CREATE database name;

Delete a database command:> drop database name; (This is an instance of the database name "Fuck" in the following picture)

In order to match the next step, we choose to build a new database, named "Newone", then the problem, so many databases, add you want to "Newone" to add some data, then how does MySQL know you want to use this database, rather than other databases? This requires using the command :> use database name ;

The following illustration takes a database newone as an example; After a successful switch to the database, the system prompts the database to switch. Like when you are in a hotel in many rooms, the hotel owner gives you the key to the room you want, and now you are free to enter the room.

Whether it is a new house or a hotel room, we should first look at the situation after we go in. Take the hotel as an example: the location of the bed, whether the light is sufficient, whether the toilet is large enough, the bed quilt is snapped has not replaced etc.

This is also true for databases, in which you first have to look at the tables in your database (there are a lot of tables in the database that you can put in, like a room with a variety of furniture, to see if there are any tables or tables you need).

View Table command :>show tables; (because it's a newly-built table, it's like a newly bought room, it's empty.) )

Similar to adding furniture for new homes, we want to add tables for the database:

Create a new table:> CREATE TABLE name (field parameters); or >CREATE table if not EXISTS table name (field parameters);

Deletes an old table:>drop table name , or >drop table if exists table name ;

The following illustration takes a table name of person as an example, and for field parameters, a brief description is given in the second section.

The above is a small set to introduce the Linux system under the MySQL use method of simple tutorial related knowledge, hope to help everyone, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

Related Article

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.