Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the basic commands for operating MySQL

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

This article is mainly about what are the basic commands for operating MySQL. If you are interested, let's take a look at this article. I believe it is of some reference value to you after reading the basic commands for operating MySQL.

Operating system: CentOS

Database system: MySQL

[root@sky9896~] # mysql-h localhost-P 3306-uroot-p # Note the P before the port number is the size

Mysql > select version (), current_date; # retrieves the current database version and current time

+-+ +

| | version () | current_date | |

+-+ +

| | 5.5.52-cll-lve | 2017-08-09 |

+-+ +

1row in set (0.00 sec)

Mysql > use employees # Open the database

Databasechanged

Mysql > select database (); # query the current database

+-+

| | database () |

+-+

| | employees |

+-+

1row in set (0.00 sec)

Mysql > show tables; # shows all the tables in the database

+-+

| | Tables_in_employees |

+-+

| | departments |

| | dept_emp |

| | dept_manager |

| | employees |

| | salaries |

| | titles |

+-+

6rows in set (0.00 sec)

Mysql > create table employees_2 (# create tables

-> emp_no int (11) NOT NULL

-> birth_date date NOT null

-> first_name varchar (14) not null

-> last_name varchar (16) not null

-> gender enum ('Maureen F') not null

-> hire_date date not null

-> primary key (emp_no)

->) engine=innodb default charset=latin1

QueryOK, 0 rows affected (0.19 sec)

Mysql > desc employees_2; # shows the table structure

+-+ +

| | Field | Type | Null | Key | Default | Extra | |

+-+ +

| | emp_no | int (11) | NO | PRI | NULL |

| | birth_date | date | NO | | NULL |

| | first_name | varchar (14) | NO | | NULL |

| | last_name | varchar (16) | NO | | NULL |

| | gender | enum ('Mitchell dagger F') | NO | | NULL | |

| | hire_date | date | NO | | NULL |

+-+ +

6rows in set (0.02 sec)

Mysql > create table T1 (an integer,b char (10))

QueryOK, 0 rows affected (0.11 sec)

Mysql > show tables

+-+

| | Tables_in_employees |

+-+

| | departments |

| | dept_emp |

| | dept_manager |

| | employees |

| | employees_2 |

| | salaries |

| | T1 |

| | titles |

+-+

8rows in set (0.00 sec)

Mysql > alter table T1 rename T2; # modify the table name

QueryOK, 0 rows affected (0.05 sec)

Mysql > show tables

+-+

| | Tables_in_employees |

+-+

| | departments |

| | dept_emp |

| | dept_manager |

| | employees |

| | employees_2 |

| | salaries |

| | T2 |

| | titles |

+-+

8rows in set (0.00 sec)

Mysql > desc T2

+-+ +

| | Field | Type | Null | Key | Default | Extra | |

+-+ +

| | a | int (11) | YES | | NULL |

| | b | char (10) | YES | | NULL |

+-+ +

2rows in set (0.00 sec)

Mysql > alter table T2 modify a tinyint notnull,change b c char (20); # modify list

QueryOK, 0 rows affected (0.25 sec)

Records:0 Duplicates: 0 Warnings: 0

Mysql > desc T2

+-+ +

| | Field | Type | Null | Key | Default | Extra | |

+-+ +

| | a | tinyint (4) | NO | | NULL |

| | c | char (20) | YES | | NULL |

+-+ +

2rows in set (0.00 sec)

Ysql > alter table T2 add d timestamp

QueryOK, 0 rows affected (0.19 sec)

Records:0 Duplicates: 0 Warnings: 0

Mysql > desc T2

+-- +

| | Field | Type | Null | Key | Default | Extra | |

+-- +

| | a | tinyint (4) | NO | | NULL |

| | c | char (20) | YES | | NULL |

| | d | timestamp | NO | | CURRENT_TIMESTAMP | on updateCURRENT_TIMESTAMP | |

+-- +

3rows in set (0.00 sec)

Mysql > alter table T2 add index (d), add index (a); # add index

Mysql > show keys from T2

Mysql > insert into employees (emp_no,birth_date,first_name,last_name,gender,hire_date) values ('1111112 / 8 / 9 / 2017 / 8 / 9 / 2017 / 08 / 09 / 2017)

QueryOK, 1 row affected (0.09 sec)

Mysql > select * from employees where emp_no=1111112

+-+ +

| | emp_no | birth_date | first_name | last_name | gender | hire_date | |

+-+ +

| | 1111112 | 2017-08-09 | wu | haiming | M | 2017-08-09 |

+-+ +

1row in set (0.00 sec)

What are the details of the above basic commands on operating MySQL? are they helpful to you? If you want to know more about it, you can continue to follow our industry information section.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report