Import directly in MySQLQureyBrower *. SQL scripts cannot execute multiple SQL commands at a time. The following describes how to import and export MySQL. SQL files and common commands are directly imported into MySQL Qurey Brower *. SQL scripts cannot execute multiple SQL commands at a time. execute the SQL file command in mysql:
Mysql> source c: \ test. SQL;
The following is a common mysql command:
(1) connecting to MYSQL:
Format: mysql-h host address-u user name-p user password
1. Example 1: Connect to MYSQL on the local machine
First, open the DOS window, enter the bin directory under the mysql installation directory, for example, D:/mysql/bin, and then type the command mysql-uroot-p, after you press enter, you are prompted to enter the password. if you have just installed MYSQL, the super user root does not have a password, so you can directly press enter to enter MYSQL. the MYSQL prompt is: mysql>
2. Example 2: Connect to MYSQL on the remote host (remote: IP address)
Assume that the IP address of the remote host is 10.0.0.1, the user name is root, and the password is 123. Enter the following command:
Mysql-h10.0.0.1-uroot-p123
(Note: You do not need to add spaces for u and root. The same applies to others)
3. exit MYSQL command
Exit (press enter)
(2) change the password:
Format: mysqladmin-u username-p old password new password
1. Example 1: Add a 123 password to the root user. First enter the directory C:/mysql/bin in DOS, and then type the following command:
Mysqladmin-uroot-password 123
Note: Because the root account does not have a password at the beginning, the old-p password can be omitted.
2. Example 2: change the password of root to 456.
Mysqladmin-uroot-pab12 password 456
(3) add new users:(Note: Unlike the above, the following commands in the MYSQL environment 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 named "test1" with the password "abc" so that the user can log on to any host and have the permission to query, insert, modify, and delete all databases. First, use the root user to connect to MYSQL, and then type the following command: grant select, insert, update, delete on *. * to test2 @ localhost identified by "abc ";
If you do not want test2 to have a password, you can run another command to remove the password. Grant select, insert, update, delete on mydb. * to test2 @ localhost identified "";
(4) display commands
1. display the database list:
Show databases; at the beginning, there were only two databases: mysql and test. The mysql database contains the MYSQL system information. we change the password and add new users to use this database for operations.
2. display the data tables in the database:
Use mysql; // open the show tables Library;
3. display the data table structure:
Describe table name;
4. database creation:
Create database name;
5. create a table:
Use database name; create table name (field setting list );
6. delete databases and tables:
Drop database name; drop table name;
7. clear records in the table:
Delete from table name;
8. display records in the table:
Select * from table name;
Export SQL scripts
Mysqldump-u username-p database name> storage location
Mysqldump-u root-p test> c:/a. SQL
Import SQL scripts
Mysql-u username-p database name <storage location
Mysqljump-u root-p test <c:/a. SQL
Note: The test database must already exist.
Use cases for MySQL export import commands
1. export the entire database
Mysqldump-u username-p database name> exported file name
Mysqldump-u wcnc-p smgp_rj_wcnc> wcnc. SQL
2. export a table
Mysqldump-u user name-p database name> exported file name
Mysqldump-u wcnc-p smgp_rj_wcnc users> wcnc_users. SQL
3. export a database structure
Mysqldump-u wcnc-p-d -- add-drop-table smgp_apps_wcnc> d: wcnc_db. SQL
-D no data -- add-drop-table adds a drop table before each create statement.
4. import the database
Common source commands
Go to the mysql database console,
For example, mysql-u root-p
Mysql> use database
Then run the source Command. the following parameter is the script File (for example,. SQL used here)
Mysql> source d: wcnc_db. SQL