MySQL is an open source relational database management system that is widely used in software development and data processing. MySQL has the advantages of high reliability, high performance, ease of use and flexibility. Therefore, learning MySQL commands and mastering their use is very important to improve the efficiency of software development and the accuracy of data processing. The following provides you with a quick reference manual for MySQL common commands to help you quickly query and master MySQL common commands.
To access the MySQL database, you first need to log in to MySQL using the command line tool. The method to log in to MySQL is to enter the following command on the command line:
mysql -u username-p
Among them, the username is the username that has been created in MySQL. After entering the command, it will ask You enter your password. After entering the password correctly, you can log in to the MySQL database.
To query all databases that exist in the MySQL database, you can use the following command:
show databases;
This command will list all databases. If a database has been created, you can enter the database through the following command:
use database name;
To create a new For a MySQL database, you can use the following command:
create database database name;
You can check whether the database is successfully created by using the following command:
show databases;
To delete a MySQL database, you can use the following command:
drop database database name;
Deleting a database requires caution , the data cannot be recovered after deletion. So please think carefully before proceeding.
To query all data tables existing in the MySQL database, you can use the following command:
show tables;
This command will list all data tables.
To create a new MySQL data table, you can use the following command:
create table table name (attribute list);
For example, if you want to create a data table named "students" that contains attributes such as students' names, ages, genders, etc., you can use the following command:
create table students (name varchar(20), age int, sex varchar(10));
In this command, name, age and sex are attributes of the data table, representing name, age and gender respectively. varchar(20) indicates that the attribute is a varchar type with a length of 20, and int indicates that the attribute is an integer.
To modify the structure of the MySQL data table, you can use the following command:
alter table table name [add|drop|modify |rename] attribute name [attribute type];
For example, if you want to add an address attribute to the data table named "students", you can use the following command:
alter table students add address varchar(50);
To insert data into the MySQL data table, you can use the following command:
insert into Table name values (attribute value list);
For example, when inserting student data with the name "Tom", age "18" and gender "male", you can use the following command:
insert into students values ('Tom', 18, 'Male');
To query data from the MySQL data table, you can use the following Command:
select attribute list from table name where condition;
For example, to query the data of all students whose age is less than 20 in the "students" data table, you can use the following command:
select * from students where age < 20;
To update the data in the MySQL data table, you can use the following command:
update table name set attribute name = attribute value where condition;
For example, to change the age of the student named "Tom" in the "students" data table to 20 years old, you can use the following command:
update students set age=20 where name = 'Tom';
To delete data from the MySQL data table, you can use the following Command:
delete from table name where condition;
For example, to delete all student data whose age is greater than or equal to 20 years old from the "students" data table, you can use the following command:
delete from students where age >= 20;
The above are some examples from the MySQL Common Commands Quick Reference Manual. MySQL has many other common commands and advanced commands, which need to be queried and used according to actual needs. Mastering these common MySQL commands can help improve the efficiency of software development, and can also help data processing work be more accurate and efficient.
The above is the detailed content of MySQL Common Commands Quick Reference Manual. For more information, please follow other related articles on the PHP Chinese website!