Mysql classic high-compulsive format/command line operation (fast) (recommended)
Because I have to learn to build servers and databases, I have recently started to learn SQL by myself. As for writing databases, I use the basic Mysql database. Although Mysql has been eliminated by Internet companies, they are all using Nosql, SQL server Waiting for the sql language, finally decided to start from the basics. After a simple decision, I wrote it using the highly compelling cmd command line. The installation method of Mysql database will not give a detailed tutorial here. There are many installation tutorials on the Internet that you can choose to install.
1. The first step is to create a library in Mysql
Take Mysql5.0 as an example, After installation, log in to Mysql from the command line:
Enter in the command line:
mysql -u root(user name) -p
Then enter the password according to the prompt and log in Database;
After logging in, enter show databases to see which libraries are in the database:
These three libraries are included after mysql is installed. You don’t need to use them. Then create your own database to use:
Enter create database Cheung, then use the database you created, enter use Cheung ;
The appearance of the above interface means that the database we are currently using is Cheung, and the preparation is ok. Next, we will start the formal SQL statement exercise.
2. Learn how to create a table below:
Enter the following operations on the command line to create a database Table, see that some operations will add single quotation marks to the name of each data, this does not need to be added, the effect of the two is the same:
This means that the table tab to be used has been created, and we can pass Enter: desc tab
to check whether the table you see is correct
Be sure to add a comma to separate each data entry, otherwise there will be a table creation error ERROR, this It is usually very embarrassing, so you must pay more attention to the details. Don't add more parentheses between the last parenthesis and the data, because adding it will cause an error.
3. Update the structure of the table in the database
Update the definition of the table and add a row to the table using alter table + Table name command:
If you want to delete a column in the table, you need to use the keyword Column. The specific operation is as follows:
If you want to delete the entire table, just enter:
< img alt="" src="/uploads/allimg/210824/1022493604-6.jpgimg.php1.cn/3cccf/189d8/882/df1ef6c160daaaf2.png" />
4. Use Insert to insert data< /strong>
Look at the structure of the current tab table first:
To insert data into the table, you must use the Insert statement in the format:
Insert into table name (column name 1, column name 2,...) values (value 1, value 2,...)
The following shows the next set of inserting a complete set of data:
Attention, I am here The value of id can be increased without setting in advance, that is, it is not written when the table is created:
id int not null auto_increment
So the id in the table The column cannot be added by itself, so it is necessary to write the id item when inserting data. No It will report an error.
The next thing to do is to insert multiple sets of data into the created table at the same time:
When these operations were written for the first time, they were all done after a lot of hard work, and finally they were worth the effort. The caring person, after my death at 3 o'clock in the middle of the night, I finally knocked out the correct answer.
It is relatively easy to query the data in the table, so I won’t say more here
5. Use update statement to update a column
The format is:
update table name set attribute 1 = new value 1, attribute 2 = new value 2 where attribute 3 = ?
The format is not difficult to understand, the key is to He uses skillfully.
Finally Just delete the table data:
and finally empty the entire table:
Such a complete Mysql command line high-force operation is completed, I have not been exposed to similar database languages in the process of learning, so I started directly The command line, I stepped on a lot of pits in the process, and I will help you clear mines here. If you have similar problems in the future, you can solve them, and I will continue to learn other sql languages in the future.
The above is the detailed explanation and integration of Mysql command line operation introduced by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message. The editor will reply to you in time. Thank you very much for your support to the website!Content recommendation: free high-definition PNG material download
This article is published by www.internetweblist.com and does not represent the position of www.internetweblist.com/：http://www.internetweblist.com/programming/82413.html