Common commands of Mysql_PHP tutorial
1. Connect to MYSQL.
Format: mysql -h host address -u username -p user password
1. Example 1: Connect to MYSQL on this machine.
First open the DOS window, then enter the directory mysqlbin, and then type the command mysql -uroot -p. After pressing Enter, you will be prompted to enter the password. If MYSQL has just been installed, the super user root does not have a password, so directly Press Enter to enter MYSQL. The prompt for MYSQL is: mysql>
2. Example 2: Connect to MYSQL on the remote host. Assume that the IP of the remote host is: 110.110.110.110, the user name is root, and the password is abcd123. Then type the following command:
mysql -h110.110.110.110 -uroot -pabcd123
(Note: u and root do not need to add spaces, the same applies to others)
3 , Exit the MYSQL command: exit (Enter)
2. Change the password.
Format: mysqladmin -u username -p old password password new password
1. Example 1: Add a password ab12 to root. First enter the directory mysqlbin under DOS, and then type the following command
mysqladmin -uroot -password ab12
Note: Because root does not have a password at the beginning, the -p old password item can be omitted .
2. Example 2: Change the root password to djg345.
mysqladmin -uroot -pab12 password djg345
3. Add new users. (Note: Unlike the above, the following are commands in the MYSQL environment, so they are followed by a semicolon as the command terminator)
Format: grant select on database.* to username@login host identified by "Password"
Example 1. Add a user test1 with the password abc, so that he can log in on any host and have query, insert, modify, and delete permissions on all databases. First connect to MYSQL as the root user, and then type the following commands:
grant select,insert,update,delete on *.* to test1@"%" Identified by "abc";
But the user added in Example 1 is very dangerous. If someone knows the password of test1, then he can log in to your mysql database on any computer on the Internet and do whatever he wants with your data. Solution See example 2.
Example 2, add a user test2 with password abc, so that he can only log in on localhost, and can query, insert, modify, and delete the database mydb (localhost refers to the local host, that is, the MYSQL database The host where it is located), so that even if the user knows the password of test2, he cannot directly access the database from the Internet, and can only access it through the web page on the MYSQL host.
grant select,insert,update,delete on mydb.* to test2@localhost identified by "abc";
If you don’t want test2 to have a password, you can type another command to delete the password .
grant select,insert,update,delete on mydb.* to test2@localhost identified by "";
In the previous article we talked about login, adding users, password changes and other issues. In the next article, we will take a look at the database operations in MYSQL. Note: You must first log in to MYSQL. The following operations are performed at the MYSQL prompt, and each command ends with a semicolon.
1. Operation skills
1. If you forget to add a semicolon after pressing Enter when typing a command, you don’t need to type the command again, just type a semicolon and press Enter. . In other words, you can divide a complete command into several lines and use a semicolon as the end mark.
2. You can use the cursor up and down keys to call out previous commands. But an old version of MYSQL that I used before does not support it. I am currently using mysql-3.23.27-beta-win.
2. Display command
1. Display the database list.
show databases;
At the beginning there were only two databases: mysql and test. The mysql library is very important. It contains MYSQL system information. When we change passwords and add new users, we actually use this library for operations.
2. Display the data tables in the library:
use mysql; //Open the library, it will be familiar to those who have learned FOXBASE
show tables;
3. Display the structure of the data table:
describe table name;
4. Create database:
create database name;
5 , Create table:
use database name;
create table table name (field setting list);
6. Delete database and table:
drop database database name;
drop table table name;
7. Clear the records in the table:
delete from table name;
8. Display the records in the table:
select * from table name;
3. An example of creating a database, creating a table and inserting data
drop database if exists school; / /If SCHOOL exists, delete it
create database school; //Create library SCHOOL
use school; //Open library SCHOOL
create table teacher //Create table TEACHER
(
id int(3) auto_increment not null primary key,
name char(10) not null,
address varchar(50) default ' Shenzhen',
year date
); //End of table creation
//The following are the inserted fields
insert into teacher values('', 'glchengang','Shenzhen No.1 Middle School','1976-10-10');
insert into teacher values('','jack','Shenzhen No.1 Middle School','1975-12-23' ; And make it the primary field primary key (2) Set NAME to a character field of length 10 (3) Set ADDRESS to a character field of length 50, and the default value is Shenzhen. What is the difference between varchar and char? I can only wait for a future article to talk about it. (4) Set YEAR as the date field.
If you type the above command at the mysql prompt, it will work, but it is not convenient for debugging. You can write the above command as it is into a text file, assuming it is school.sql, then copy it to c:\, enter the directory \mysql\bin in DOS state, and then type the following command:
mysql - uroot -p password
If successful, a blank line will be left blank and nothing will be displayed; if there is an error, there will be a prompt. (The above command has been debugged, you only need to remove the // comment to use it).
4. Transfer text data to the database
1. The format that text data should conform to: field data are separated by tab keys, and null values are replaced by \n.
Example:
3 rose Shenzhen No. 2 Middle School 1976-10-10
4 mike Shenzhen No. 1 Middle School 1975-12-23
2. Data input command load data local infile "file name" into table table name;
Note: You'd better copy the file to the \mysql\bin directory, and first use the use command to open the library where the table is located.
5. Back up the database: (The command is executed in the \mysql\bin directory of DOS)
mysqldump --opt school>school.bbb
Note: Back up the database school Back up to the school.bbb file. School.bbb is a text file. You can choose any file name. Open it and see what new discoveries you will make.
Postscript: In fact, the operation of MYSQL database is similar to that of other SQL databases. You'd better find a book about SQL. I only introduce some basic ones here. In fact, that’s all I know, haha. The best MYSQL tutorial is the "MYSQL Chinese Reference Manual" translated by "Yan Zi". It is not only free and available for download on every relevant website, but it is also the most authoritative. Unfortunately, it is not in chm format like "PHP4 Chinese Manual", which is not convenient when searching for function commands.
http://www.bkjia.com/PHPjc/314742.html

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.

In PHP, use the clone keyword to create a copy of the object and customize the cloning behavior through the \_\_clone magic method. 1. Use the clone keyword to make a shallow copy, cloning the object's properties but not the object's properties. 2. The \_\_clone method can deeply copy nested objects to avoid shallow copying problems. 3. Pay attention to avoid circular references and performance problems in cloning, and optimize cloning operations to improve efficiency.

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use