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

Explain in detail the use of Mysql basic syntax

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

Share

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

MYSQL introduction

MySQL is a relational database management system developed by the Swedish company MySQL AB and currently belongs to the products of Oracle. MySQL is one of the most popular relational database management systems. In terms of WEB applications, MySQL is the best RDBMS (relational database management system) application software.

Why use MYSQL?

Because of its small size, high speed and low total cost of ownership, the most important thing is that it is free, which saves development costs for many small and medium-sized enterprises.

I believe that many code friends in the entry to the grammar is still very strange, do not know how to use, I will give you a collective analysis of the actual operation of some basic grammar.

1. Create a database

CREATE DATABASE database name

two。 Create a table-here I created a user table for testing (id we use here as primary key, username user name, userpass user password, job job position, department department, name real name) this is a basic user table

CREATE TABLE `user` (`id` int (11) NOT NULL, `username` varchar (11) DEFAULT NULL, `userpass` varchar (50) DEFAULT NULL, `job` varchar (11) DEFAULT NULL, `department` varchar (11) DEFAULT NULL, `name` varchar (11) DEFAULT NULL, PRIMARY KEY (`id`) ENGINE=InnoDB DEFAULT CHARSET=utf8

Create a signin check-in table (id primary key, signindate check-in time, uid user name, name name)

DROP TABLE IF EXISTS `signin`; CREATE TABLE `signin` (`id` int (11) NOT NULL AUTO_INCREMENT, `signindate` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `uid` varchar (50) DEFAULT NULL, `name` varchar (50) DEFAULT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8

3. Let's talk about some specific operation syntax.

a. Insert data-insert syntax

INSERT INTO `user`VALUES ('1Qing,' admin', '21232f297a57a5a743894a0e4a801fc3,' system maintenance', 'system administrator', 'system administrator'); INSERT INTO `signin` VALUES ('1Qing,' 2018-05-10 16 purge 42pur32, 'admin',' Xiao Ming')

b. Modify data-update syntax (change the name value to Xiaoming according to username)

Update user set name=' Xiaoming 'where username='admin'

c. Delete data-delete syntax (delete data with ID 1)

Delete from user where id=1

d. Query data-select syntax (according to the condition query, here is to query the data whose username value is admin or name value is Xiaoming, when either condition is satisfied)

Select id,username,job,department,name from user where username='admin' or name=' Xiaoming'

e. Query data-select syntax (statistics on how much data is in the admin table)

Select count (*) from user

f. Query syntax-select syntax (paged query, query the first page of 10 conditional data)

Select id,username,job,department,name from user order by id desc limit 10,1

g. Query syntax-select syntax (left join left outer join, associated query user's check-in record, if there is no check-in record, it will return data in the user table)

Select u.id,u.username,s.signindate from user u left join signin s on u.username=s.uid

Summary

The above is the use of the basic grammar of Mysql introduced by the editor. I hope it will be helpful to you. If you have any questions, please leave a message for me. The editor will reply you in time. Thank you very much for your support to the website!

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