Simple use of Mysql (1). Use of mysql
If you query these problems, IT means that you are a programmer who is or is preparing to engage in IT. For a programmer, the program that won't use the linux system isn't a good programmer! Because windows is crazy sometimes, and I believe that there is no habit that cannot be changed. So the following are all used in linux:
Install mysql command: $Sudo apt-get install-y mysql-server
Run the following command to view the mysql version: $Mysql-V(Note that-V is in uppercase; otherwise, the following error will occur)
Start mysql command: $Sudo service mysql start(For other functions such as shutdown and restart, you only need to replace start with the corresponding stop, restart, and other letters)
This command can be used only with the root permission. After the command is started successfully, no prompt is displayed. For linux, no news is good news. So don't worry, it has been started successfully.
(Root permission: from the "Account" perspective, it refers to the identity of the "System Administrator", that is, a Super User with the highest permissions. From the directory perspective, it refers to the "root directory", that is, "/".
Obviously this section refers to the first case: System Administrator .)
After starting, enter the mysql command: $Mysql-u username-p Password
For the first login, the username is usually root. After the password is installed, the system will prompt you to enter it. After entering mysql, the prompt in the command line will change to "mysql> ". Because mysql commands are a little different from linux commands, mysql commands always end. This requires a little attention. (The above password can be directly entered after-p or the second line, the difference is that the second line of the password appears in an invisible form)
After entering mysql, first check the database:>Show databases;(Do not drop the Semicolon)
The system will contain several data items, such as performance_schema, information_schema, and mysql. It is best not to delete these built-in databases to avoid exceptions.
After checking the database, there are two possibilities: either creating a new database or deleting a database, so I will record the two together, when using it, you can know that they are at the same level.
Create a database command:>Create database name;
Delete A database command:>Drop database name; (the database name "fuck" is used as an instance in the slice)
In order to cooperate with the next step, we chose to create a new database named "newone". The problem arises. So many databases, if you want to add some data to "newone, so how does mysql know that you want to use this database instead of other databases? Run the following command:>Use Database Name;
Take the database newone as an example. After the database is successfully switched, the system will prompt that the database has been switched. For example, if the hotel owner gives the key to the room you want in many hotels, you can enter the room freely now.
Whether it's a new house or a hotel room, we should first check the situation. Take a hotel as an example: such as the location of the bed, whether the light is adequate, whether the bathroom is large enough, whether the bed quilt has been cracked or not to change the etc.
This is also true for databases. When you come in, you should first check the "table" in the database. (It is not questionable that many tables can be placed in the database, just like you can store a variety of furniture in a room, check whether there are any tables or the tables you need ).
Run the following command to view a table:> Show tables;(Because it is a new table, it is like a new room, which is empty .)
Similar to adding furniture to a new house, we need to add tables to the database:
Create a new table:>Create table Name (field parameter); or>Create table if not exists table name (Field Parameter);
Delete an old table:>Drop table Name;Or>Drop table if exists table name;
Take the table name "person" as an example. The field parameters are briefly described in the second section.