Mysql Common commands and learning experiences

Source: Internet
Author: User
Tags mysql commands
Mysql Common commands and learning experiences, learning some basics that php friends need to know, to facilitate future development.

Mysql Common commands and learning experiences, learning some basics that php friends need to know, to facilitate future development.

1. PHP steps for database connection:
1. Establish a connection with the database:
$ Conn = mysql_connect ("localhost: 3306", "username", "pass ");
Three parameters: the first is the database server host name and the port localhost: 3306. If the host name or port is set to php by default. the value set in ini. The last two are the usernames and passwords used to connect to the database server. The default value is php. the value set in ini.
2. Submit the query statement:
A. Use the mysql_select_db () function to select the database to be accessed.
Eg:
Mysql_select_db ("mydb ");
The function returns the logical value true or false based on the Operation's success or failure.
B. Execute SQL statements
The mysql_query () function has two parameters. The first parameter is an SQL statement, and the second parameter is the connection number generated by the mysql_connect () function.
Eg:
$ Result = mysql_query ("select * from address", $ conn );
After the function submits an SQL statement, the query result is generated and the result number is returned.
3. Content in the returned result
Ii. Common mysql commands
1. Start mysql
Mysql-u root-p
2. Change the password:
Mysqladmin-u username-p old password New password
3. Display commands
The Code is as follows:
Show databases;
Use mydb;
Show tables;
Describe tablename;
Create database databasename;
Create table tablename;
Drop table tablename;
Drop database databasename;
Delete from tablename;
Select * from tablename;
Insert into tablename values ('','');

4. Import mysql from a file
Mysql-u root-p </usr/local/info/mydb. SQL (where/usr/local/info/mydb. SQL is the database file storage directory)
5. convert text data to the database
Format of text data: field data is separated by the tab key, and the null value is replaced by \ n.
Eg:
3 rose:
Data Import command load data local infile \ "file name \" into table Name
Note: It is best to copy the file to the/mysql/bin directory and use the use command to open the database where the table is located.
6. Time Format
Declare time variables using datetime in mysql database
Eg:
Time datetime; // the input data format: 12:20:50
Getting system time in php (in YYYY-MM-DD HH: MM: SS format ):
$ T = time ();
$ Time = date ('Y-m-d H: I: s', $ t );
7. unique specifying unique attributes

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.