Connect: mysql -h host address -u user name-p user password (Note: u and root need not add spaces, the other is the same)
disconnect: exit (Enter)
Create authorization: grant select on database.* to username@Login host identified by \”password\”
Modify password: mysqladmin -u username -p old password password new password
delete authorization: revoke select,insert,update,delete om *.* [email protected];
Display database: show databases;
Display data table: show tables;
Display table structure: describe table name ;
Create table: create table table name (field setting list); Back up the database: mysql\bin\mysqldump -h(ip) -uroot -p(password ) databasename> database.sql Import text data: load data local infile \”file name\” into table table name; Start and stop mysql service Login to mysql Add a new user Example 2: Connect to MYSQL on the remote host mysql-h110.110.110.110 -uroot -pabcd123 (Note: u and root can be used without spaces, the other is the same) < p> 3. Exit MYSQL command: exit (一) Connect MYSQL: 1, example 1 : Connect to MYSQL on this machine (2) Modify password: But examples 1 The added user is very dangerous. If 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 do whatever you want with your data. See examples for solutions 2. MySQL import and export commands 3. Export a database structure 4. Import the database Create database: Database query: Select the database to be operated; use test1 View all the data tables created in the test1 database: Create a table: create table emp(ename varchar(10),hiredate date,sal decimal(10,2) ,deptno int(2)); View table: Delete table: Modify table type: alter table emp modify ename varchar(20); Add table fields alter table emp add column age int(3); Delete table fields < p> alter table emp drop column age; Rename the field alter table emp change age agel int(4); Note: Modify the field arrangement order table rename alter table emp rename emp1; Insert record insert into emp(ename,hiredate,sal,deptno) values('zzx1','2000-01-01','2000',1) ; Modify the order of the fields Insert multiple records at once Update record: update emp set sal=4000 where ename='lisa'; Delete records: delete from emp where ename='dony'; Query records: select * from emp; where "*" means to select all records, or all fields separated by commas can be used instead, for example Query unique records : Select distinct deptno from emp; Conditional query: select * from emp where deptno=1; Sorting and restriction: select * from emp order by sal; < p>Aggregation Table join < /li> Sub query alter table emp add birth date after ename; alter table emp modify age int(3) first; p> alter table emp add birth date after ename; alter table emp modify age int(3) first; INSERT INTO tablename (field1, field2,……fieldn) VALUES(record1_value1, record1_value2,……record1_valuesn), < p>(record2_value1, record2_value2,……record2_valuesn), delete a,b from emp a,dept b where a .deptno=b.deptno and a.deptno=3; fun_name represents the aggregation operation to be done, that is, the aggregation function. Commonly used are sum (sum), count(*) (number of records), max (maximum), min ( Minimum). The GROUP BY keyword indicates the field to be classified and aggregated. For example, if you want to classify and count the number of employees by department, the department should be written after group by. WITH ROLLUP is an optional syntax, indicating whether to re-aggregate the results after classification and aggregation. The HAVING keyword means to filter the results after classification. #To count the total number of companies in the emp table select count(1) from emp; #On this basis, count the number of people in each department select deptno,count(1) from emp group by deptno; # It is necessary to count the number of people in each department as well as the total number of people select deptno,count(1) from emp group by deptno with rollup; #Departments with more than 1 person /p> select deptno,count(1) from emp group by deptno having count(1)>1; #Statistics of the total salary, maximum and minimum salary of all employees in the company select sum(sal),max(sal),min(sal) from emp; select ename,deptname from emp,dept where emp.deptno=dept.deptno; < p># Can list names that do not exist in another column select ename, deptname from emp left join dept on emp.deptno=dept.deptno; select * from emp where deptno in(select deptno from dept); #If the number of subquery records is unique, you can also use = instead of in select * from emp where deptno = (select deptno from dept limit 1); WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
Delete table: drop table table name;
Modify table: alter table t1 rename t2
Query table: select * from table name;
Empty table: delete from table name;
Backup table: mysqlbinmysqldump -h(ip) -uroot -p(password) databasenametablename> tablename.sql
Restore table: mysqlbinmysql -h (ip) -uroot -p(password) databasenametablename
Restore the database: mysql\bin\mysql -h(ip) -uroot -p(password) databasename< database.sql
Copy the database: mysql\bin\mysqldump –all-databases >all-databases.sql
Repair the database: mysqlcheck -A -o -uroot -p54safer
Data import guide Out: mysql\bin\mysqlimport database tables.txt
net stop mysql
net start mysql
The syntax is as follows: mysql -u username -p user password
Type the command mysql -uroot -p, press Enter and prompt you to enter the password, enter 12345, and then press Enter to enter mysql. The mysql prompt is:
mysql>
Note, if you are connecting to another machine, you need to add a parameter -h machine IP
Format: grant permission on database.* to username @Login host identified by “password”
For example, add a user user1 password to password1, so that it can log in on this machine, and have query, insert, modify, and delete permissions for all databases. First connect to mysql as the root user, and then type the following command:
grant select,insert,update,delete on *.* [emailprotected] Identified by “password1”;
If you want the user to be able to be on any machine Log on to mysql, then change localhost to “%”.
If you don’t want user1 to have a password, you can type another command to remove the password.
grant select,insert,update,delete on mydb.* [email protected] identified by””;
Assuming 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:
Format: mysql -h host address-u user name-p user password
First, open the DOS window, and then enter the bin directory under the mysql installation directory, for example: D:\mysql\bin, and then type the command mysql -uroot-p, and then press Enter to prompt You enter the password. If you just installed MYSQL, the super user root does not have a password, so you can enter MYSQL directly by pressing Enter. The prompt of MYSQL is: mysql>
2, Example 2: Connect to the remote host MYSQL on the
Assume that the IP of the remote host is 10.0.0.1, the user name is root, and the password is 123. Then type the following command:
mysql -h10.0.0.1 -uroot-p123
(Note: u and root can be without spaces, the other is the same)
3. Exit MYSQL command
exit ( Enter)
Format: mysqladmin -u username -p old password password new password
1, Example 1: Add a password 123 to root. First enter the directory C:\mysql\bin under DOS, and then type the following command:
mysqladmin -uroot -password123
Note: Because root does not have a password at the beginning, the -p old password can be omitted.
2, Example 2: Then change the root password to 456
mysqladmin -uroot -pab12password 456
(3) Add a new user: (Note: Unlike the above, the following is because it is in the MYSQL environment Command, so there is 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, Let him log in on any host, and have query, insert, modify, and delete permissions for all databases. First connect to MYSQL as the root user, and then type the following command:
grantselect,insert,update,delete on *.* to [emailprotected]”%” Identified by”abc”;
Example 2. Add a user test2 password to 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, where the MYSQL database is located Host), 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.
grantselect, insert, update, delete on mydb.* to [email protected] identifiedby “abc”;
If you don’t want test2 to have a password, you can type another command to delete the password.
grantselect,insert,update,delete on mydb.* to [email protected] identifiedby “”;
1. Export the entire database
mysqldump -u username -p database name> exported file name
mysqldump -u wcnc -p smgp_apps_wcnc >wcnc.sql
2. Export a table
mysqldump -u username-p database name table name> exported file name
br> mysqldump -u wcnc -p smgp_apps_wcnc users>wcnc_users.sql
mysqldump -u wcnc -p -d –add-drop-table smgp_apps_wcnc>d:wcnc_db .sql
-d has no data–add-drop-table adds a drop table before each create statement
commonly used source commands
enter the mysql database control Station,
such as mysql -u root -p
mysql>use database
Then use the source command, the following parameters are script files (such as the .sql used here)
mysql>source d:wcnc_db .sqlcreate database test1;
show databases;
show tables;
desc emp;
drop table emp
change< Both /code> and
modify
can modify the definition of the table. The difference is that the column name needs to be written twice after change
, which is inconvenient. But the advantage of change
is that you can modify the column name, but modify
cannot.
< li>
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 2999 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC