Database Basics and Operations

Source: Internet
Author: User

Databases: Database;

Tables: Table;

Fields: field, column columns;

Row: row, recording record;

Temporarily stop the service: net stop WAMPMYSQLD64

Start service: net start WAMPMYSQLD64

Log in to the database:

Note: After logging into the database system, you need to use "set names encoded name;" To set the " environment variable " of the current connection database. The encoding of the "client" itself that is currently dealing with the database. Generally speaking :

is fixed in the CMD client Use GBK encoding,

and The PHP page, is the page file encoding (now the mainstream is UTF8)

Mysql-u root-p

Exit:quiet/exit

To back up the database:

must be a command to exit the database execution specify to the specific file name

Mysql-h localhost-u root-p z_shop > folder path \ filename. sql

Basic Grammar Rules

Single-line comment: #注释内容

Single-line comment: --note content (note that there is a space after two "--")

Multiline Comment:/ * Comment content */

Modify end symbol (default;)

Delimiter: We recommend not to modify!!! Recommended not to modify!!! Recommended not to modify!!!

Basic Flow:

1. Connect to the database:

$mylink = mysql_connect ("localhost", ' root ', ' 123 ');

New mysqli (server address, user name, password, database name);

2, set the connection code (usually UTF8)

Mysql_set_charset ("UTF8"); can also be used:mysql_query ("Set names UTF8");

3. Select the database (if necessary)

mysql_select_db ("database name"); also available:mysql_query ("Use database name ");

4, execute the SQL command.

$result = mysql_query (" almost any SQL statement ");

The results returned usually need to be handled in two different situations:

4.1: If it is a statement with no return data:

4.1.1 if $result is true, the execution succeeds

4.1.2 If the $result is false, it indicates that the execution failed

4.2: If there is a statement that returns data:

4.2.1 If the $result is false, it indicates that the execution failed

4.2.2 Otherwise, the execution succeeds and you need to continue extracting the data from the results and showing it.

Supplemental SQL statements:

Set names GBK;

Use database name;

Show databases:

Desc Table Name: Displays the "structure information" of a table and returns a result set (similar to a select statement)

add php to operate MySQL functions:

$record = mysql_fetch_array ( result set $result);

$n 1 = mysql_num_rows ( result set $result): Gets the number of rows in the result set

$n 2 = mysql_num_fields ( result set $result): Gets the number of columns of the result set

Mysql_field_name ( result set $result, $i): Gets the first field name in the result set ( I from 0 start)

Database definition: Grammatical form:

Create DATABASE [if not EXISTS] db name [CharSet Character set ] [collate character Collation ] ;

Description

1,if notexists: Used to determine if the database name exists and does not execute if it exists

2, Character set: The character encoding name used when the intent data is stored in this database, usually UTF8, or GBK.

3, character collations are not usually set, but instead use the default rules for the set of character sets (each character set has a default collation);

What is collation: a rule that sets the order in which all characters in a character set are ordered.

Example: Create Database php1218 charset UTF8;

Displays all the available character sets in MySQL:

Show CharSet;

Show all the available collations in MySQL:

Show collation;

To modify a database:

alter database name Character Set= new Character Set collate= new proofing set;

To Delete a database:

DROP Database database name;

Select (enter) a database : use database name;

In general, you must first "enter" the database for the data tables and data in the data.

Show all databases: show databases;

to display the CREATE statement for a database :

Show create database name;

Database Basics and Operations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.