MySQL Introductory learning (vi)

Source: Internet
Author: User
Tags modify mysql mysql in backup
MySQL MySQL primer learning (vi)
--Modification and backup, batch processing

Sometimes we have to modify and delete database tables and databases, which can be implemented in the following ways:

1. Add one column:
Add a column in the MyTable table in the previous example to indicate whether single singles:
Mysql> ALTER TABLE mytable add column single char (1);

2, modify the record
Modify the Abccs single record to "Y":
mysql> Update mytable set single= ' y ' where name= ' Abccs ';

Now let's see what's going on:
Mysql> select * FROM MyTable;
+----------+------+------------+-----------+--------+
| name | sex | Birth | birthaddr | Single |
+----------+------+------------+-----------+--------+
| Abccs |f | 1977-07-07 | Our | y |
| Mary |f | 1978-12-12 | USA | NULL |
| Tom |m | 1970-09-02 | USA | NULL |
+----------+------+------------+-----------+--------+

3, increase the record
I've already talked about how to add a record to make it easier to see and repeat with this:
mysql> INSERT INTO MyTable
-> VALUES (' abc ', ' F ', ' 1966-08-17 ', ' o ', ' n ');
Query OK, 1 row affected (0.05 sec)
Check this out:
Mysql> select * FROM MyTable;
+----------+------+------------+-----------+--------+
| name | sex | Birth | birthaddr | Single |
+----------+------+------------+-----------+--------+
| Abccs |f | 1977-07-07 | Our | y |
| Mary |f | 1978-12-12 | USA | NULL |
| Tom |m | 1970-09-02 | USA | NULL |
| ABC |f | 1966-08-17 | Our | n |
+----------+------+------------+-----------+--------+


3, delete the record
Delete a record in the table with the following command:
Mysql> Delete from mytable where name= ' abc ';
Delete Deletes a record from the table that satisfies the condition given by the where.

Show the results again:
Mysql> select * FROM MyTable;
+----------+------+------------+-----------+--------+
| name | sex | Birth | birthaddr | Single |
+----------+------+------------+-----------+--------+
| Abccs |f | 1977-07-07 | Our | y |
| Mary |f | 1978-12-12 | USA | NULL |
| Tom |m | 1970-09-02 | USA | NULL |
+----------+------+------------+-----------+--------+

4, delete the table:
mysql> DROP TABLE * * * * * * (table 1 name), * * * Table 2 name;
You can delete one or more tables and use them carefully.

5, the deletion of the database:
mysql> drop database name;
Use caution.

6, the database backup:
Back to Dos:
Mysql> quit
D:mysqlbin
Use the following command to back up the database Abccs:
Mysqldump--opt ABCCS>ABCCS.DBB
ABCCS.DBB is the backup file for your database Abccs.

7. Use MySQL in batch processing mode:

First, create a batch file Mytest.sql, which reads as follows:
Use Abccs;
SELECT * FROM MyTable;
Select Name,sex from mytable where name= ' Abccs ';

Run the following command under DOS:
D:mysqlbin MySQL < Mytest.sql
The execution results are displayed on the screen.

If you want to see the results and have a lot of output, you can use this command:
MySQL < Mytest.sql | More

We can also output the results to a file:
MySQL < mytest.sql > mytest.out


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.