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

Mysql basic knowledge learning

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

1 description

Database commands are case-insensitive, for example, "CREATE DATABASE test" and "create database test" are equally valid.

2 connect to the database

1) connect to the MYSQL on the local computer

Connect to the database can use phpadmin management platform, can also use the command line mode, this time I use the environment built by wamp, wamp comes with mysql database and tools, through the command line to operate mysql. Command to access the mysql database: mysql-u root-p

2) Connect to the MYSQL on the remote host

Suppose the IP of the remote host is 1.1.1.1, the user name is root, and the password is root. Type the following command:

Mysql-h 110.110.110.110Muru root-p root

3 database command

1) create a database test

Create database test

2) create data table persons

Create tablepersons

(

Firstnamevarchar (8)

Lastnamevarchar (8)

Age int

)

3) insert a new record in the data table

Insert into persons (age,firstname,lastname) values (25 Zhangjie San)

4) query all data in persons table

Select * from persons

5) conditional query, query the results from the database, query the data with an age field of 25 in the persons table.

Select * from personswhere age=25

6) sort order by, sort in ascending order by age field. Order by is sorted in ascending order by default. If you want to sort in descending order, add DESC at the back door.

Select * from personsorder by age

7) alternative use of order by, if order by is followed by a specific number, it indicates that it is sorted by which column of the table. For example, order by 1 indicates that it is sorted by the first column of the table. If the number after order by is greater than the number of columns of the table, it will report an error. This usage is usually used in SQL injection to determine the number of fields in the database table.

Select * from personsorder by 1

8) modify the data in the table: modify the value of the age in the persons table where the firstname field is xiao

Update personsset age=100 where firstname='xiao'

9 Delete the data in the database: delete the data with an age of 100 in the persons table

Delete from persons where age=100

10) Delete the data table, delete the persons data table

Drop tablepersons

11) delete the database and export the test1 database

Drop tabletest1

12) View the database

Show databases

13) View the data sheet

Show tables

14) check what fields are in the data table: see what fields are in the users table

Show columns from users

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