MY SQL Common Order

xiaoxiao2021-03-06  115

First, connect mysql.

Format: mysql -h host address -u username -P user password

1, Example 1: Connect to MySQL on the unit.

First open the DOS window, then enter the directory mysqlbin, type the command mysql -uroot -p, then prompt you to lose your password, if you just install MySQL, the superuser root is no password, so you can enter it directly. MySQL, MySQL prompts are: mysql>

2, Example 2: Connect to MySQL on the remote host. Suppose the IP of the remote host is: 110.110.110.110, the username is root, the password is ABCD123. Type the following command:

mysql -h110.110.110.110 -uroot -Pabcd123

(Note: u and root do not have to bind the body, others are the same)

3, exit mysql command: exit (Enter)

Second, modify the password.

Format: mysqladmin -u username -P old password Password new password

1, Example 1: Add a password to the root AB12. First enter the directory mysqlbin under DOS, then type the following command

MySQLADMIN -UROOT -PASSWORD AB12

Note: Because the root does not have a password, the -p old password can be omitted.

2, Example 2: Change the root password to DJG345.

mysqladmin -uroot -Pab12 Password DJG345

Third, add new users. (Note: Different from the above, because it is the command in the mysql environment, then take a semicolon as the end of the command)

Format: Grant SELECT ON Database. * To Username @ Login Host Identified By / "Password /"

Example 1. Add a user TEST1 password to ABC, allowing him to log in on any host and have the permissions of all databases, insert, modify, delete. First, use the root user into MySQL, then type the following command:

Grant SELECT, INSERT, UPDATE, DELETE ON *. * to Test1 @ / "% /" Identified by / "ABC /"

However, the user of Example 1 is very dangerous. You want someone to know the password of Test1, then he can log in to your MySQL database on any computer on the Internet and to your data for what you want, solution. See Example 2.

Example 2, add a user TEST2 password to ABC, let him log in in localhost, and can query, insert, modify, and delete the database MYDB (localhost refers to the host host, the host where the mysql database is located) In this way, users can use the password that knows Test2, he cannot access the database directly on the Internet, and can only access 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 with a password, you can make a command to remove the password.

Grant SELECT, INSERT, UPDATE, DELETE ON MYDB. * to Test2 @ localhost iDentified by / "/";

In the upper part, we told questions such as login, increase users, password changes. Next Let's take a look at the operations in MySQL. Note: You must first log in to MySQL first, the following operations are performed at the MySQL prompt, and each command ends in a semicolon. First, operation skills

1. If you play a command, I found that I forgot to add the semicolon after I entered the bus. You didn't need to re-play a command, as long as you have a semicolon to enter the car. That is to say, you can divide a complete command into a few lines, and then use the semicolon to end the flag OK.

2, you can use the cursor upside button to call up the previous command. But I used a MySQL old version I have not supported. I am using mysql-3.23.27-beta-win.

Second, display command

1. Display the database list.

Show databases;

Two databases are just started: mysql and test. The mysql library is very important that there is a MySQL system information, we change your password and add users, actually use this library to operate.

2, display the data table in the library:

Use mysql; // Open the library, I will not be unfamiliar with FoxBase.

Show table;

3, display the structure of the data sheet:

DESCRIBE table;

4, build the library:

CREATE DATABASE library name;

5, build the table:

USE library name;

CREATE TABLE Name (Field Settings List);

6, delete libraries and deleted forms:

DROP DATABASE library name;

DROP TABLE table name;

7. Record the table in the table:

DELETE FROM table name;

8, the record in the display:

SELECT * FROM table name;

Third, an example of a construction and construction form and insert data

DROP DATABASE IF EXISTS SCHOOL; / / If there is School, delete

Create Database School; // Establishment Library School

Use school; // Open the library SCHOOL

CREATE TABLE TEACHER / / Establishment TEACHER

(

ID INT (3) Auto_Increment Not Null Primary Key,

Name char (10) Not null,

Address Varchar (50) Default 'Shenzhen',

Year Date

); // End of the table

// The following is inserted in the field

INSERT INTO TEACHER VALUES ('', 'Glcheng', 'Shenzhen No.1 Middle ",' 1976-10-10 ');

INSERT INTO TEACHER VALUES ('', 'Jack', 'Shenzhen No.1 ",' 1975-12-23 ');

Note: In the form of the table (1) set the ID to the number field of length 3: int (3) and let it automatically add one: auto_increment does not empty: NOT NULL and let him become the primary field Primary Key (2) Set the NAME to a character field (3) set the address to the character field of length 50, and the default is Shenzhen. What is the difference between VARCHAR and CHAR? Only the following article will be said. (4) Set the Year of Year to the date field.

If you type the above command on the MySQL prompt, it is not convenient to debug. You can write the above command to a text file to assume School.SQL, then copy it to c: //, and enter the directory // mysql // bin in the DOS state, then type the following command:

MySQL -UROOT -P password

Fourth, transfer the text data into the database

1. The text data should match the format: the field data is separated with the Tab key, and the null value is used to replace it with // n.

example:

3 Rose Shenzhen 2nd 1976-10-10

4 MIKE Shenzhen No.1975-12-23

2. Data Introduction Command Load Data local infile / "file name /" INTO TABLE table name;

Note: You'd better copy files to // mysql // bin directory, and first use the USE command to play the library.

V. Backup database: (command is executed in DOS // mysql // bin directory)

MySQLDUMP - OPT SCHOOL> School.bbb

Note: Back up the database SCHOOL to the school.bb file, and School.bbb is a text file, the file name is all, open to see if you will have new discovery.

Postscript: In fact, Mysql's operation of the database is similar to other SQL class databases. You'd better find this book of SQL. I only introduce some basic in here. In fact, I only know these, huh, huh. The best mysql tutorial or "Mysql Chinese Reference Manual" is not only downloads every relevant website, but also is the most authoritative. Unfortunately, it is not like / "php4 Chinese manual /" is the format of CHM, is not very convenient to find the function command.

转载请注明原文地址:https://www.9cbs.com/read-101530.html

New Post(0)