Home > Backend Development > PHP Tutorial > Database search, addition, deletion and modification_PHP tutorial

Database search, addition, deletion and modification_PHP tutorial

WBOY
Release: 2016-07-13 17:01:16
Original
1291 people have browsed it

I haven't learned MySQL for a long time, and the operations of the database are nothing more than adding records, searching for records, deleting records, and modifying records.
The following commands are summarized and shared with everyone:
Connection command: mysql -h[host address] -u[user name] -p[user password]
Create database: create database [library name]
Show all databases: show databases;
Open a database: use [library name]
Currently selected library status: SELECT DATABASE();
Create a data table: CREATE TABLE [table name]([ Field name] [Field type]([Field requirements]) [Field parameters], ...);
Show data table fields: describe table name;
Current database table structure: show tables;
Change table
ALTER TABLE [table name] ADD COLUMN [field name] DATATYPE
Description: Add a column (there is no syntax to delete a column.
ALTER TABLE [table name] ADD PRIMARY KEY ([field name])
Description: Change the definition of the table and set a field as the primary key
ALTER TABLE [table name] DROP PRIMARY KEY ([field name])
Description: Delete the definition of the primary key.
Show columns from tablename;
Delete database: drop database [database name];
Delete table: drop table [table name];
Data operations.
Add: INSERT INTO [table name] VALUES('','',...data arranged in order);
Query: SELECT * FROM [table name] WHERE ([condition]);
Create index: CREATE INDEX [index file name] ON [table name] ([field name]);
Delete: DELETE FROM [table name] WHERE ([condition]);
Modify: UPDATE [ Table name] SET [Modify content such as name = 'Mary'] WHERE [Condition];
Import external data text:
1. Execute external sql script
Execute on the current database: mysql < input. sql
Execute on the specified database: mysql [table name] < input.sql
2. Data transfer command load data local infile "[file name]" into table [table name];
Back up database (under dos)
mysqldump --opt school>school.bbb

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631193.htmlTechArticleIt doesn’t take long to learn mysql, and the operations of the database are nothing more than adding records, searching for records, deleting records, and modifying records. The following commands are summarized and shared with everyone: Connection command: mys...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template