The following articles mainly introduce the correct procedures for MySQL database operations, as well as descriptions of some things worth attention during the installation process. At the same time, I would like to give you some advice, in the actual installation process, you must remember your password, which is the key to log on to MySQL in the future.
MySQLDatabase Operation 1. log on to the MySQL database server
To log on to MySQL, you need to switch to the bin directory of MySQL under dos and perform the following operations:
Syntax format:
- MySQL-h host_name-u user_name-p password-the local host-h and host_name can be saved)
My Experience:
C: \ program files \ MySQL server 4.1 \ bin> MySQL-u root-p
Enter password :******
First Enter the user name and password login requirements plus-p), press Enter, and then "Enter password:" appears, then Enter the password and press Enter, so that you can
Log on to MySQL. Otherwise, the logon fails.
After successful login, the following information is displayed:
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 1 to server version: 4.1.10-nt
- Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
- MySQL>
Mark "MySQL>". When you see the top cell on the far left of the window, you can enter the command to perform the operation.
MySQL> \ s view version information
MySQL> \ q or MySQL> quit
MySQL> \ h or MySQL> help to view commands related to other database servers)
MySQLDatabase Operations 2. Database Operations
Note that the displayed results of all examples are the results of the following steps in order.
2.1 query statement
2.1.1 view the MySQL database version number and the current server date
- MySQL> select version (), current_date; Operation Method 1)
- MySQL> select version ()
- ->, Current_date; Operation Method 2)
※Operation statements are separated by commas (,) and separated by commas (;). The operation ends. line breaks do not affect the operation process.
2.1.2 view all databases on the server
- MySQL> show databases;
2.2 create a database
2.2.1 creating a database, of course, the database name "asb" cannot already exist)
- MySQL> create database asb;
2.2.2 select a database to make it the database for the current operation
- MySQL> 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 database using window commands, provided that the asb database exists)
- bin>MySQL asb -u uesername -p
- Enter password:******
2.2.3 view the name of the database currently operated
- MySQL> select database();
The result is as follows:
- +------------+
- | database() |
- +------------+
- | asb |
- +------------+
- 1 row in set (0.00 sec)
2.3 create a table
2.3.1 "create table" is used to create a table in the current database. If not, use 'use' to select the database for which the table is to be created)
- MySQL> 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.3.2 check the tables in the current database to check whether the "emp" table in the previous example is successfully created)
- MySQL> show tables;
If it is successful, it will be shown as follows:
- +---------------+
- | Tables_in_asb |
- +---------------+
- | emp |
- +---------------+
- 1 row in set (0.00 sec)
2.3.3 view the structure of a data table
- MySQL> 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.