Learn php-(14) MySQL database basic operations 1

Source: Internet
Author: User
Tags learn php mysql command line

Mention of the database, I believe are not unfamiliar. The more common are SQL Server, Oracle, Access, SQLite, and so on. And of course, PHP's golden partner, MySQL database. Of course I'm writing about some of the basics of MySQL, and I haven't studied this database in depth. Further study will take some time. But now the basis of learning to meet my current learning needs.

I. MySQL INTRODUCTION 1, what is MySQL

MySQL is a secure, cross-platform, efficient database system that is tightly integrated with mainstream programming languages such as PHP and Java. The database system was developed, released and supported by the Swedish MySQL AB company, which was established by the MySQL initial developer David Axmark and Michael Monty Widenius in 1995. The symbol of MySQL, a dolphin named Sakila, represents the speed, ability, precision, and quality of the MySQL database.

2. mysql Features① Powerful, MySQL5 supports transactions, views, stored procedures, and triggers② supports cross-platform, MySQL supports at least 20 development platforms, including Linux, Windows, FreeBSD, Ibmaix, etc. ③ running Speed fast④ supports object-oriented, PHP supports a mixed programming approach, which can be divided into purely object-oriented, purely process-oriented, object-oriented, and process-oriented blending of three ways. ⑤ security Highs, flexible and secure permissions with a password system that allows for basic host authentication. When connecting to the server, all password transfers are encrypted, thus ensuring the security of the password. ⑥ cost is low, MySQL is a completely free product. ⑦ supports a variety of development languages, including Php,asp.net, Java, Python, C, C + +, Perl, and more. ⑧ Data Inventory reserve capacity is large⑨ supports powerful built-in functions that cover almost all of the features in Web application development. Supports a large number of extension libraries, such as MysqliSecond, use MySQL statement to manipulate databaseHere I am working with the command line of the MySQL database. First open a command line tool that comes with MySQL, MySQL5.6 command lines Client. After opening, enter the password, the interface is as follows:
This starts the database operation using the MySQL command line. 1. View the database syntax: show databases; (Don't forget the semicolon)
This is my database, if you use it for the first time, there should be nothing. 2. Create a database CREATE database name;For example, I want to create a database called Test, I should write: Create database test;
Now that you're looking at the database, you'll have a test database. 3, select the database in the use of their own data when the first choice of this database. Statement: Use database name; For example, I want to work with the test database, I should select this database first. I should do this:
Now the operation is done in this database. 4. Delete Database drop database name;I'm not going to delete it here. I want to use this database to operate. Third, use the MySQL statement to manipulate the database table 1, create a database table to create a table to use the Create Tables command, first of all, the table row is a record, the column is a property, or a field. A table contains at least one column. Each table needs to set a primary key, which is a unique identifying field for each record, that is, the primary key is a property (field), each record must be different on this property, and no other fields are required. So if I want to create a table with the table named student, in this table you need to have the following fields, ID (this is the primary key, ID can uniquely identify a student), name (name), email (email), Address, tel (mobile). We can create this:
2. View table structure syntax: Describe data table name, or abbreviated to DESC table name. For example, I want to see the table I just created.
Of course, you can also see a single column, just add the name of the column you want to see after the table name. 3. Modify the table structure syntax: ALTER TABLE table name modification statement (multiple bars separated by commas);For example, I want to modify in the table above, add a column, age, type int, not NULL. Delete the Tel column. Change address varchar (45) to varchar (60). Then I should write:
In fact, there are many changes to the statement, I also can not remember, the Internet to check. 4. View database Tables syntax: show tables;

5. Renaming a table Syntax: Table name to rename table name to want;For example, I want to change student to Tb_student.
6. Delete a table Syntax: drop table name;To avoid the error of deleting a nonexistent table, you should write this: drop table if exists name;I will not delete it here. 7. Inserting data syntax: INSERT into table name (column name 1, column Name 2, ...) VALUES (insert a value of 1, insert a value of 2, ...);For example, I insert a piece of data into the Tb_student table:
Note that the ID is auto_crement, which is self-growing, so you don't have to assign a value to it when you insert it. 8. Inquiry Form Record syntax: Select the column to query (* indicates all columns are listed) From table name criteria for where query (multiple conditions separated by commas) column name of GROUP by group column name by which order by is sorted conditions under which the having group is queried limit when displayedThe query table record is the most used statement. There is no way to do this one by one description. The next PHP statement will be seen in the MySQL operation. 9, change the record Syntax: Update table name set column name = new value (multiple column modifications are separated by commas) where condition;For example, I want to change Xiaoming's address to ' Dalian, China ':
10. Delete Records syntax: Delete from table name where condition;For example, I want to delete Xiao Ming's record:


These are the basic operation of the database statement, the actual operation will also appear more complex statements, but all are composed of these basic statements, then the next one to write the use of Workbench visual Operation database. Then there is the PHP statement to manipulate the data.

Edge Learning php-(14) MySQL database basic operations 1

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.