MYSQL语法(MySQL syntax)

1. 常用SQL语句查询:

查询当前数据库版本: select version();查询当前数据库用户: select user();查询当前路径: select @@basedir;查询所有数据库: show databases;选择一个数据库: use + 数据库名;查询当前数据库: select database();查询所有表名: show tables;创建一个数据库: create database 数据库名;删除一个数据库: drop database 数据库名;查询一个表的结构: desc 表名;

2. MySQL常见的注释符:

■ #         ■ –空格        ■ /**/

3. SQL中符号运用:

■ = 赋值 ■or/|| 逻辑或 ■&&/And 逻辑与 ■NOT/! 逻辑非 ■+、-、*、/ 运算符 加减乘除 ■xor 逻辑异或

4. 内联注释符及特性:

5. 常见的空格符号:

6. 注入中常见的sql函数:(以下为重点记忆部分)

1)extractvalue()函数 //对xml文档进行查询的函数 语法:extractvalue(目标xml文档,xml路径).语句:select extractvalue(‘anything’,concat(‘~’,(select user())));2)updatexml() //语法updatexml(目标xml文档,xml路径,更新的内容)语句:select updatexml(‘anything’,concat(‘~’,(select version())),’xxx’);3)substr()函数 //从字符串 s 的 start 位置截取长度为 length 的子字符串,select substr(user(),1,2);语句:select substr(user(),1,2);4)into outfile()函数是用来导出文件的(进行恶意代码的导入导出)

7. Mysql常见的数据类型:

1)数值类型2)日期和时间类型3)字符串类型4)MYSQL整数类型5)MYSQL小数类型6)MYSQL字符串类型

8. SQL中的增删改查:

1)添加数据:insert2)删除数据:delete3)修改数据:update4)查询数据:select

9. 退出数据库方法:(如果无法退出就在quit后面加分号;即可)

EXIT –方法1quit –方法2\q –方法3ctrl+c –方法4

注意:sql语句最后需要有分号;结尾

10. MySQL连接:

1)点击phpStudy中的MySQL管理器,点击选择PhpMyAdmin打开2)命令行:输入mysql出错后,进行明文连接mysql -h 127.0.0.1 -uroot -proot3)在mysql目录下输入常用SQL语句查询即可

11. select * from student;(*是匹配所有字符的意思)

12. 对查询结果进行排序:带 order by关键字

————————

1. < strong > common SQL statement query: < / strong >

Query the current database version: select version(); Query current database user: select user(); Query current path: select @@basedir; Query all databases: show databases; Select a database: Use + database name; Query current database: select database(); Query all table names: show tables; Create a database: Create database database name; Delete a database: Drop database database name; Query the structure of a table: Desc table name;

2. Common notes for MySQL: < / strong >

■ # ■ — space ■/**/

3. Symbol application in SQL: < / strong >

■ = assignment ■ or / | logical or ■ & amp& amp;/ And logic and ■ not /! Logical non ■ +, -, *, / operators addition, subtraction, multiplication and division ■ XOR logical XOR

4. Inline annotators and features: < / strong >

5. Common space symbols: < / strong >

6. Common SQL functions in injection: < / strong > (the following is the key memory part)

1) Extractvalue() function / / function syntax for querying XML documents: extractvalue (target XML document, XML path) Statement: select extractvalue (‘anything ‘, concat (‘ ~ ‘, (select user()); 2) Updatexml() / / syntax updatexml (target XML document, XML path, updated content) statement: select updatexml (‘anything ‘, concat (‘ ~ ‘, (select version()),’xxx’); 3) Substr() function / / intercepts a substring of length from the start position of the string s, and selects substr (user(), 1,2); Statement: select substr (user(), 1,2); 4) The into outfile() function is used to export files (import and export malicious code)

7. Common MySQL data types: < / strong >

1) Numeric type 2) date and time type 3) string type 4) MySQL integer type 5) MySQL decimal type 6) MySQL string type

8. Add, delete, modify query in SQL: < / strong >

1) Add data: insert2) delete data: delete3) modify data: Update4) query data: Select

9. Exit database method: < / strong > (if you cannot exit, add a semicolon after quit)

Exit — Method 1quit — Method 2 \ Q — Method 3ctrl + C — Method 4

< strong > note: a semicolon is required at the end of the SQL statement; End < / strong >

10. MySQL connection: < / strong >

1) Click MySQL manager in phpstudy and select phpMyAdmin to open 2) command line: after entering mysql, connect in clear text MySQL – H 127.0.0.1 – uroot – proot3) enter common SQL statements in MySQL directory to query

11. select * from student; (* means to match all characters)

12. Sort query results: with the keyword order by