The following articles mainly describe the correct operation steps of the MySQL database, including the query statements, the correct operation steps for creating the MySQL database, and the actual operation procedures for creating tables, the following is a detailed description of the specific content. I hope you will find some gains.
Note that the displayed results of all examples are the results of the following steps in order.
Query statement
1. view the MySQL database version number and the current server date.
- MySQL (the best combination with PHP)> select version (), current_date; Operation Method 1)
- MySQL (best combination with PHP)> select version ()
- ->, Current_date; Operation Method 2)
The operation statements are separated by commas (,) and separated by commas (;). line breaks do not affect the operation.
2. view all databases on the server
- MySQL (the best combination with PHP)> show databases;
Create a database
1. Of course, the MySQL database name "asb" cannot already exist)
- MySQL (the best combination with PHP)> create database asb;
2. Select a database to make it the database for the current operation
- MySQL (best combination with PHP)> use asb;
After the selection is successful, the following information is displayed:
- Database changed
You can even directly select the database to be operated when logging on to the MySQL (the best combination with PHP) database by using window commands. The premise is that the asb database exists)
- Bin> MySQL (best combination with PHP) asb-u uesername-p
- Enter password :******
3. view the name of the currently operated MySQL database
- MySQL (the best combination with PHP)> select database ();
The result is as follows:
- +------------+
- | database() |
- +------------+
- | asb |
- +------------+
- 1 row in set (0.00 sec)
Create a table
1. use "create table" to create a table. If not, use 'use' to select the database to create the table)
- MySQL (best combination with PHP)> create table emp (emp_id varchar (6)
- ->, Emp_name varchar (10)
- ->, Emp_age int
- ->, Emp-sal int
- ->, Emp_bir date
- ->, Emp_sex varchar (5)
- -> );
2. Check the tables in the current MySQL database to check whether the "emp" table in the previous example has been successfully created)
MySQL (the best combination with PHP)> show tables;
If it is successful, it will be shown as follows:
- +---------------+
- | Tables_in_asb |
- +---------------+
- | emp |
- +---------------+
- 1 row in set (0.00 sec)
3. view the data table structure
- MySQL (the best combination with PHP)> describe emp;
The running result is shown as follows:
- +----------+-------------+------+-----+---------+-------+
- | Field | Type | Null | Key | Default | Extra |
- +----------+-------------+------+-----+---------+-------+
- | emp_id | varchar(6) | YES | | NULL | |
- | emp_name | varchar(10) | YES | | NULL | |
- | emp_age | int(11) | YES | | NULL | |
- | emp_sal | int(11) | YES | | NULL | |
- | emp_bir | date | YES | | NULL | |
- | emp_sex | varchar(5) | YES | | NULL | |
- +----------+-------------+------+-----+---------+-------+
The above content is an introduction to MySQL database operations. I hope you will have some gains.