How to import. SQL data in the mysql tutorial
The method is as follows:
1. First connect with the jive User:
E: mysqlbin> mysql-u jive-p jive
2. Run the following command:
Mysql>. f: workingfolderjivejdondatabasejive_mysql. SQL
My personal practice is: php tutorial myadmin exports abc. SQL in UTF-8 insert mode
Ftp abc. SQL to server
Ssh to server
Mysql-u abc-p
Use kkk (database tutorial name, if not, create database kkk)
Set names 'utf8'
Source abc. SQL
Note: I have seen the set character set utf8; statement. It is not feasible. Chinese characters are garbled.
1. First open mysql in the command line Console
Perhaps the command is as follows:
Mysql-u root-p database_name
Then you may be prompted to enter the corresponding Password
2. The following command may be useful to you. When you want to change a database
Mysql> use database_name
Run the following command:
Mysql> source d: datafilename. SQL
Of course, you need to clarify the path of the file and use it correctly.
Enter bin in the directory where mysql is installed. Enter the command to import SQL.
For example, your mysql is installed in d: mysql
The procedure is as follows:
Start> RUN> Enter cmd
D:
Cd mysqlbin
Mysql-u root-p123456 test <d: a. SQL
Here, root is your mysql administrator username, and 123456 is the password test is the database name d: a. SQL is the location of the backup data file.
For windows, go to the bin folder in the mysql file directory from the command prompt and execute the command
Mysql-u root-p databasename <db. SQL
Here, root is your mysql user name, databasename is your database name, and db. SQL: You are a file. note that you must set db. the SQL statement can be placed in the bin folder. of course, the file location can be changed.
For linux, enter
Mysql databasename <db. SQL
The default mysql command is the system command.
I. Operation Skills
1. If you forget the extra points after you press Enter when making the command, you do not need to re-run the command. You only need to press a semicolon to press Enter.
. That is to say, you can divide a complete command into several lines, and then use a semicolon as the end sign to complete the operation.
2. You can use the cursor to bring up or down the previous commands. However, an old mysql version I used earlier does not support this feature. Me now
In use is the mysql-3.23.27-beta-win.
Ii. Display commands
1. display the Database List.
Show databases;
At the beginning, there were only two databases: mysql and test. The mysql database contains mysql system information.
Code and new users are actually operated using this library.
2. display the data tables in the database:
Use mysql; // open the database. If you have learned foxbase, you will not be unfamiliar with it.
Show tables;
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;
3. An instance for creating a database, creating a table, and inserting data
Drop database if exists school; // Delete if school exists
Create database school; // create a database school
Use school; // open the school library
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
); // Table creation ends
// Insert fields as follows
Insert into teacher values ('', 'glengang ', 'shenzhen Zhongyi', '2017-10-10 ');
Insert into teacher values ('', 'jack', 'shenzhen Zhongyi ', '2017-12-23 ');
Note: In table creation (1), set the id to a numeric field with a length of 3: int (3) and add auto_inc to each record automatically.
Rement cannot be blank: not
Null and set it as the primary field primary
Key (2) Set name to 10 character field (3) set address to 50 character field, and the default
The value is Shenzhen. What is the difference between varchar and char? It will only be discussed later. (4) set year to date
.
If you type the preceding command at the mysql prompt, debugging is not convenient. You can write the preceding command as is
Assume that these text files are school. SQL, then copy them to c:, and enter the directory mysqlbin in dos status,
Run the following command:
Mysql-uroot-p password <c: school. SQL
If it succeeds, no display is displayed for a blank row. If there is an error, a prompt is displayed. (The above command has been debugged. You only need //
).
4. Transfer text data to the database
1. Text data should conform to the format: field data is separated by the tab key, and the null value is replaced by n.
Example:
3 rose:
4 mike: Shenzhen No. 1,-12-23
2. data Import command load data local infile "file name" into table name;
Note: You 'd better copy the file to the mysqlbin directory and use the use command to create the database where the table is located.
V. Back up the database: (execute the command in the dos mysqlbin directory)
Mysqldump -- opt school> school. bbb
Note: Back up the database school to the school. bbb file. school. bbb is a text file.
See if you have any new discoveries.