Home >Backend Development >PHP Tutorial >Simple operations of the mysql database that need to be used in php, phpmysql_PHP tutorial
Several DOScommands
In the DOS environment, there is no semicolon after the command. In the MySQL environment, there is a semicolon after the command
Enter drive letter:
Syntax: Drive letter:
Enter a folder under the drive letter
Syntax: cd Path
Parent directory: ../
Enter the root directory: /
Host Host -h
Username Username -u
Password Password -p
Port Port -P
E:wampbinmysqlmysql5.6.17binmysql -hlocalhost -uroot -p -P3306
If the port number is 3306, the port number can be omitted.
If the link is local MySQL, the database address can also be omitted.
E:wampbinmysqlmysql5.6.17binmysql -uroot -p
2. Exit the database
A) exit;
B) quit;
C) q;
Grammar:
Create database Database name;
B)If the created database already exists, an error will be reported;
C)Check when creating, if it does not exist, create it;
Syntax: create database if not exists database name;
D) Specify the character encoding when creating the database
Syntax: create database Database name charset=Character encoding;
Syntax: show databases;
Syntax: show create database Database name;
Change the character encoding of the database
syntax: alter database database name charset=Character encoding;
A)Syntax; drop database Database name;
B)If you delete a non-existing database, an error will be reported.
C)Before deleting, it is necessary to determine whether the database exists, and only delete it if it exists.
Syntax: drop database if exists Database name;
A) syntax: use database name;
A line is also called a record, and a line is a record.
Columns are also called fields, and a column is a field. Fields are also called attributes.
A table contains multiple fields.
Grammar:
Create table Table name(
Field1 Data type [null | not null] [default] [auto increment] [primary key],
Field2 Data Type
..........
)
Not null :Not empty
Default: Default value
auto increment:Automatic increase
Primary key: Primary key
(Features: cannot be repeated, cannot be empty, a table can only have one primary key, and the primary key can be composed of multiple fields)
Int:Plastic surgery
Decimal(Total number of digits, number of decimal places): Save decimal
Char(): Character (fixed length)
Varchar(): Character (variable length)
text : Large text
Syntax: show tables;
Syntax: show create table Table name [G];
G: means table and create tablefield vertical arrangement
Descrip Table name; (you can description as desc
Describe:Describe
Syntax: drop table table name;
Delete multiple tables: 🎜>....;
3.8Create complex tables
A) Syntax: inset into table name (field name1, field name2...)values(value1, value2.....) B)The inserted fields can be inconsistent with the order of the fields in the database, but the order of the values and the inserted fields must be consistent C) When the inserted value is consistent with the order and number of fields in the data table, the inserted field can be omitted . D)Insertion of automatic growth Insert into stu values(null,'Li Qingzhao','female','Shanghai',78); E)Insertion of default value Insert into stu values(null,'Xin Qiji','male',default,90); syntax : update table name set field1=value1, field2=value2 wherecondition Example: Change Li Bai’s gender to female. Update stu set stu_sex = 'Where stu_name =' Li Bai "; Make all genders female. Update stu set stu_sex = 'female'; A) Grammar: Select The name From Table [where condition ] [order by Sort] [limit Limit starting position, number of records obtained]; Sort: Ascending asc Descending order desc The starting position in Limit starts from 0. B)Operator i.Comparison operator Operators Description > >= < <= = is equal to <> is not equal to
Logical operators
and 与 or 或 not 非 Example: 1.Query the names and genders of all students select stu_name,stu_sex from stu; 2.Query all information of all students. select * from stu; 3. Query the information of all boys. select * from stu where stu_sex='Male'; 4. Query the information of all girls and boys in Beijing. select * from stu where stu_sex='Female' or (stu_sex='Male' and stu_address='Beijing'); 5.
select * from stu limit 2; .
select * from stu limit 1,2;
select * from stu order by stu_score desc limit 2;
4.4 [where conditions];
.
Delete from stu where stu_name=’Li Bai’;
Delete all data in the table.
delete from stu;
http://www.bkjia.com/PHPjc/1071504.html www.bkjia.com true4. Data operations
4.1Insert data (increase)
4.2Modify data (change)
4.3Query data (check)
and
and
or
or
not
Non
syntax: delete from
table name