mysql| Create | data | Database Once you understand some of the most basic operations commands, let's learn how to create a database and database table.
1. Use the show statement to find out what databases are currently on the server:
Mysql> show DATABASES; +----------+
| Test | +----------+ 3 rows in Set (0.00 sec)
2. Create a database Abccs
mysql> CREATE DATABASE Abccs;
Note that different operating systems are sensitive to case sensitivity.
3, select the database you created
Mysql> Use Abccs
Database changed
At this point you have entered the database Abccs you have just created.
4. Create a database table
First look at what tables are present in your database:
Mysql> show TABLES;
Empty Set (0.00 sec)
Indicates that there are no database tables in the database you just established. Next, create a database table MyTable:
We are going to create a birthday table for your employees whose contents include the employee's name, sex, date of birth, and city of birth.
Mysql> CREATE TABLE mytable (name VARCHAR (), Sex CHAR (1),
-> birth DATE, Birthaddr VARCHAR (20));
Query OK, 0 rows Affected (0.00 sec)
Because the column value of name and Birthadd is variable, select varchar, which is not necessarily 20 in length. You can choose any length from 1 to 255, and you can use the ALTER TABLE statement if you want to change its word size later. The gender can be represented by a single character: "M" or "F", so char (1) is selected, and the birth column uses the date data type.
Once we've created a table, we can look at the results we just made and show you what tables are in the database:
Mysql> show TABLES; +---------------------+
| +---------------------+
5, show the structure of the table:
Mysql> DESCRIBE mytable;
| +-------------+-------------+------+-----+---------+-------+
4 rows in Set (0.00 sec)
6, add the record to the table
We first use the Select command to view the data in the table:
Mysql> select * FROM MyTable;
Empty Set (0.00 sec)
This indicates that the table you just created has not been recorded.
Add a new record:
mysql> INSERT INTO mytable-> values (′abccs′,
′f′,′1977-07-07′,′china′); Query OK,
1 row affected (0.05 sec)
and then use the Select command above to see what has changed. We can add all employee records to the table in this way, one by one.
7, loading data into a database table in text
If you type it in one piece, it's cumbersome. We can add all the records to your database table in the form of a text file. Create a text file "Mysql.txt", each containing a record, separated by a locator (tab), and given in the order of the columns listed in the CREATE TABLE statement, for example:
Abccs F 1977-07-07 Mary F 1978-12-12 USA Tom M 1970-09-02 USA
Use the following command to convert text The file "Mytable.txt" is mounted to the MyTable table:mysql> load DATA local INFILE "mytable.txt" into table pet;
Use the following command to see if data has been entered into a database table:mysql> select * FROM MyTable;