MySQL Simple operation

Source: Internet
Author: User

1,mysql wakes up the database, mysql-uroot-p112212, creates a database: Create databases mldn CHARACTER SET UTF8; can also be written in lowercase: Create database Wang Charact  Er set utf8;3, view all databases: Show databases;5, using MLDN database: Use mldn;6, creating data table: Create TABLE News (Nid INT Auto_increment, title VARCHAR (+) is not NULL,(the function of NOT NULL is if the value of this property is ignored when inserting, error, not default null)    Content text,    CONSTRAINT pk_nid PRIMARY KEY (nid)  ) Engine=innodb; auto_increment : This column that represents NID can achieve autogrow, and the last EMGINE=INNODB indicates that the table supports transactional processing. 7, insert some elements into the table, insert into News (Title,context) VALUES ("Wangruirui", "Handsome"), set UTF8 directly sets the data in the form of supporting UTF8 data 8, Iterate through all the elements in the table: SELECT * from News;9, gets the length of the data after the last input: select last_insert_id (); This property is specific to a table of 10, paging operations: Uniform use, unified use limit, that is: in all query statements in the last block write limit, query limit start line, length select * FROM News limit 2, 5;               is a serial number, MySQL is starting from 0 11, database connection if you use MySQL to develop, so long must use the JDBC connection, and the process of JDBC connection, Need to configure the MySQL driver  12 delete a file in a database: Delete from news where nid=6; This uses the primary key attribute 13, the table that has been written will be saved on the database you are using, so when you restart your databases, you must first find your db, to find the table you created, 14, using PHP to connect to the database: <meta charset= "Utf-8"  /><?php$dbhost =  ' localhost:3306 ';  //  MySQL server host address $dbuser =  ' root ';             // mysql user name $dbpass =  ' 11221 ';Nbsp;         // mysql User name Password $conn = mysqli_connect ( $dbhost,  $dbuser,  $dbpass); if (!  $conn  ) {  echo  "Connection failed";} else{    echo  "connected successfully";}? >mysqli_connect (Host,user,password,dbname,port,socket); Host: optional, specify host name or IP address, username: optional, specify MySQL username, password : optional, password; dbname: Optional, specify the database to be used by default, port: optional, specify the port number to attempt to connect to the MySQL server, socket: optional, specify socket or named pipe to use,15. Create a database using a PHP script:
$conn = Mysqli_connect ($dbhost, $dbuser, $dbpass);
$sql = "CREATE Database Us";$add =mysqli_query ($conn, $sql);a database was successfully created locally;16. Delete a database:Drop Databases < database name >;Drop DB if exists < database name >; prevent database from being present error
17. Connect to the database:mysqli_select_db ($link, database name);mysqli_select_db ($conn, "mldn"); 18,use php Select database:mysqli_select_db ($conn, "mldn"); 19, make PHP create TABLE $addcontent= "  CREATE TABLE PHP (".  "ID INT auto_increment,".  "Name VARCHAR (+) is not NULL,".  "Sex VARCHAR () not NULL,". "PRIMARY KEY (ID)) Engine=innodb charset=utf8;"; $addttable =mysqli_query ($conn, $addcontent); Mysqli_close ($conn);20,php inserting data:INSERT into PHP (Id,name,sex) VALUES (12, "Shen Fan", "female");//contain Chinese when must remember to change the encoding format, mysqli_query ($conn, "Set names UTF8");

MySQL Simple operation

Related Article

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.