Common commands for compared MYSQL

xiaoxiao2021-03-06  87

First, connect mysql. Format: MySQL -H Host Address -u User Name -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's 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 can not have a splitter, others are also the same) 3, exit the mysql command: EXIT (Enter) Second, modify the password. Format: mysqladmin -u User Name -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 -UROT -PAB12 Password DJG345, add new users. (Note: Different from the above, because it is a command in the MySQL environment, then take a semicolon as a command end value) 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, the root user is connected to MySQL, then type the following command: Grant SELECT, INSERT, UPDATE, DELETE ON *. * To Test1 @ / "% /" Identified by / "abc /"; but Example 1 Increased users are very Dangerous, you want to know the password of Test1 as a person, then you can log in to your MySQL database on any computer on the Internet and you can see you for your data. 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 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 talked on logins, increase users, password changes, etc. 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. I. Operation skills 1, if you are playing a command, then I found that I forgot to add the semicolon, you don't have to play a command, as long as you have a semicolon, you can go. 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 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, the data table in the display library: use mysql; // Open the library, learn FoxBase, will not be unfamiliar with Show Tables; 3, display the structure of the data table: Describe table name; 4, Jian Ling: CREATE DATABASE library name ; 5, Jian Table: Use the library name; CREATE TABLE table name (field setting list); 6, delete libraries and deletions: DROP TABASE 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; three, one to build a library and build table and instance DROP DATABASE IF EXISTS SCHOOL; // If there is School, remove the Create Database School; // Set the library School Use school; // Open the library School Create Table Teacher // Settles TEACHER (ID INT (3) Auto_Increment Not Null Primary Key, Name Char (10) Not Null, Address Varchar (50) Default 'Shenzhen', Year Date ; // The end of the table // below is inserted insert INTO TEACHER VALUES ('', 'Glchengang', 'Shenzhen No.1 ",' 1976-10-10 '); Insert Into Teacher Values ​​(' 'Jack' , 'Shenzhen No.123', '1975-12-23'); Note: In the Table Table (1) Set the ID to the number field of length 3: int (3) and let each record automatically add one: Auto_increment does not empty: NOT NULL and let him become the primary field key (2) Set Name to a character field (3) set 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

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

New Post(0)