How to import mysql.txt.The following are the general steps to import the txt-file into the mysmysoul database:
1. Create the test table and prepare the data:
- First, create a table for receiving data. For example, create a table called person, which contains id (self-increment and not empty), name (not empty), age, city, salary, and other fields. The example creation statement is: createtableperson(idintnotnullauto_increment,namevarchar(40)notnull,age int,cityvarchar(20),salaryint,primarykey(id))engine = innodb charset = gb2312;
- Prepare a txt-file, such as c:/data.txt. The data format is separated by the Tab key between each item. If the field is blank, it is represented by/N. For example, Zhang San 31 Beijing 3000, Li Si 25 Hangzhou 4000, etc.
2. Data import:
- Use the load data local infile 'c:/data.txt' into table person(name,age,city,salary); command to import the data from the txt-file into the table, where local means local. After executing this command, the data of the Null-class will also be imported correctly.
- Note that the default separation between fields and records (rows) is/t (that is, Tab) and/n, but it can be changed, such as using Fields Terminated By ','(fields are separated by,), Lines Terminated By ';'(records are separated by,) and other settings. At the same time, it is also important to note that the line break of other operating systems may be different from that of windows.
<a href="/?from=ask_words" style="color:red" target="_blank">Read more exciting novels for free</a>
Creating a complete table in mysqlThe complete process of creating a table in Mystical is as follows:
1. He opened the Mystical command line.
2. Connecting to the database.
3. Create a table by using the CREATE TABLE grammar to specify the column name and data type. The format is as follows:
```sql
Create TableName (
`Field name 1` VarCHAR(Field size) NOT nil,
`Field name 2` INT nil,
Primary Key(`Primary Key Field 1`)
);
```
For example, create a table named `employees`(save employee information):
```sql
CREATE TABLE employees (
id INT NOT NULL,
name VARCHAR(64) NOT NULL,
department VARCHAR(16) NOT NULL,
role VARCHAR(16) NOT NULL DEFAULT 'staff',
salary FLOAT(8,2) NULL
);
```
What needed to be noted here was:
- You can choose the data type according to your needs, such as INT, VarCHAR, DatateTime, and so on.
- NOT Nulls will force the non-acceptance of Nulls, while Nulls will allow Nulls.
- The alternative `DEBUCT` keyword can be used when declaring a field using the VARCHAR or TINYINT data type.
4. Executing a query statement to create a table.
5. Use `Show Tables;` to check whether the verification table was successfully created.
"Choose" was equally exciting. Everyone was welcome to read it!
import data from txtls into mysqlThere are the following ways to import the data in TMT into MysQL:
1. Create a new table, add a line of template data in the first line of the text file (if you don't add it, the import may be wrong), then right click import ward to import txy, then set the partition field (with space or/according to the situation), then set the corresponding attribute corresponding value, and finally check whether the data is correct and whether the amount of data is missing.
2. You can also use the command to import it. For example, if the table tt format is Create Table `tt` ( `ind` int NOT Empty auto_increment, `name` char100) default Empty, Primary Key (`ind`) ), the contents of the file d.txt. For example, 1, a2, b3,c, and the import command is: mysql> load data infile 'd.txt' into table tt -> fields terminated by',' -> lines terminated by'\r\n'. Points to note:
- You can use an absolute path for the file, such as 'c:/d.txt'. Otherwise, please place the file in the root of the database.
- Because the fields are separated by commas, the fields must be terminated by',' or the import will fail.
- Because the lines are separated by "\r\n" in Winwindows, it must be lines terminated by "\r\n". If you don't set this argument, the import can also be successful, but there will be an additional "\r" control character. The field may not be seen in the visual mysticism tool, but it will be obviously confused in the mysmysticism command line.
- If the table tt is not empty and the ind value in the file is repeated in the table, an error will be prompted and the import will fail. If only the name field is imported, the content of the file d.txt. is abc, and the import command is: mysqlgtload data infile 'd.txt' into table tt -> lines terminated by'\r'-> (name). The load data command also supports more complex text format, file code, etc. You can refer to the official document.
<a href="/?from=ask_words" style="color:red" target="_blank">Read more exciting novels for free</a>
How to create a database and table in mysql1. ** Creating a database **
- You can create a database using the Create Databank statement. For example, if you want to create a database named "my_first_db', you can execute the statement" create database my_first_db'. You can also specify the default character set when creating the database, such as "create database day16 - > default character set utf8;". You can also specify the default character set and the default verification rule for the character set.
2. ** Create Table **
- After creating the database, you can use the Create Table statement to create a table in the database. Its grammar is "Create Table Name (column name 1 data type, column name 2 data type, column name 3 data type,... )”。For example, if you want to create an employee information table (including employee number, name, and date of birth) in the database named "my_first_db', you first execute" use my_first_db'; to select the database, and then execute "Create Table employee( id INT, nam VARCHAR(255), birthday date );" statement to create the table.
"Choose" was equally exciting. Everyone was welcome to read it!
The problem of storing large chunks of text into the mysQL databaseYou can store large chunks of text in the Mystical database using an SQL statement.
Suppose there is a text file called text, which contains a large chunk of text that needs to be stored. You can store the contents of the text file in the mysmysticism database using the following SQL statement:
```
INSERT INTO text_table (column1 column2 column3 )
VALUES (value1 value2 value3 );
```
Where text_table is a table name used to store text data, column1, column2, column3, etc. are column names used to store corresponding text data, value1, value2, value3, etc. are actual values used to store corresponding text data.
When executing the above SQL statement, the contents of the text file need to be passed to the SQL statement as variables of actual values such as value1, value2, and value3.
If the text file contains multiple sections, you can store each section on a separate line and use a terminator to group these lines in the SQL statement. For example:
```
INSERT INTO text_table (column1 column2 column3 )
VALUES (value1 value2 value3 ' ' ' ');
```
This will create a table called text_table with the following columns:
- column1
- column2
- column3
- value1
- value2
- value3
- separator
In the example above, the separating character is a commas separating each paragraph.
It is important to note that when storing large chunks of text in the Mystical database, you need to consider the character set and the code. It was necessary to ensure that the database character set was consistent with the text file character set and that the text data was stored using the correct encryption method.
How many words can text store in mysql?In Mystical, the text type can store text data of any length without a maximum storage capacity limit. However, in order to ensure the accuracy and legibility of the data, it is usually recommended to compress the text data into a smaller file format to reduce the storage space requirements. The space that can be used in Mystical to store a character set. The character set includes all possible characters. A character set can contain one or more characters. Each character takes up one syllable. Therefore, a 100-character text data may actually take up more storage space than it actually needs because each character takes up a bit of space.
How to save a document with a lot of text into the mysql databaseTo save a document with a lot of text into the mysmysticism database, you can follow these steps:
Create a database and create a table to store the content and titles of the document. For example, you can create a table called content that contains the following fields:
- content_id (The primary key will automatically increment the id)
- title
- author_id (Foreign key points to the author ID of the document)
- language
- timestamp
2 Create a new document and add it to the content table. You can add the contents of the document to the table using an SQL statement. For example, you can create a new document using the following SQL statement:
```
INSERT INTO content (content_id title author_id language timestamp)
Values (1'document title'1 'Chinese' now())
```
This will create an auto-increment row named 1 in the content table and add the document title, author ID, language, and creation time to the table.
Write a program or script to extract the content of the document from the browser and write it to a text file. The text file was then written to the local disk and compared to the contents of the document in the database to ensure that the contents of the document matched the contents in the database.
4. If necessary, you can paginate the content of the document to better organize and manage the document.
5. Periodically back up and restore the database to ensure the safety and reliability of the data.
These are the basic steps to store a document with a lot of text in the Mystical database. The specific implementation method may vary according to the specific situation and needs to be adjusted according to actual needs.
Is it better to save the collected articles in mysql database or generate files?The answer to this question depends on many factors, including how you plan to deal with this data and how you use a database or file to store it.
If you plan to save the collected articles in a database for later analysis and processing, then a database may be a better choice. The database can provide high expansibility, high reliability, and efficient query capabilities to support large-scale data storage and processing. In addition, the database also supports a variety of data management tools and applications that can help you manage and query your data.
However, if you plan to generate a file of collected articles for direct storage on a local computer or mobile device, generating a file may be a better choice. Creating files allows faster access and editing of data and makes it easier to share files with others. In addition, generating files can reduce the need for a database because you don't need to use a database to store and process data.
In summary, the choice to save the collected articles in the database or generate a file depends on your specific needs and usage.
How to use sql statements to clean the web page data collected by the web crawling program in mysqlThe web data collected by the web crawling program can be cleaned in Mystical by the following steps:
1. Data import: Use Python's web crawling framework (such as requests) to send an IP request to retrieve web page data and import the data into Python's dictionary or list.
```python
import requests
response = requestsget('https://examplecom')
data = responsejson()
```
2. Parse the data: Use Python's JSon analyzer to analyze the webpage data and extract the required data.
```python
import json
data = jsonloads(responsetext)
```
3. Clean data: According to the type and format of the webpage data, use the SQL statement to clean and convert the data.
For example, if you were to obtain an browser document, you could use Python's Beautiful Soup library to analyze the browser document and then use an SQL statement to convert the browser document into table data.
```python
from bs4 import BeautifulSoup
soup = BeautifulSoup(data 'htmlparser')
table = soupfind('table')
#Converting a Python dictionary from an existing table
data = {}
for row in tablefind_all('tr'):
data[rowfind('td')] = rowfind('td')text
```
4. Store data: Store the cleaned data in the Mystical database.
```python
#Connecting to the Mystical database
db = MySQLdbconnect(user='username' password='password' host='localhost' database='database_name')
#Store data in the mysmysticism database
cursor = dbcursor()
#Execute a SQL statement to insert data into the mysmysticism database
cursorexecute('INSERT INTO table_name (column1 column2 column3) VALUES (? ? ?) ' (data[0] data[1] data[2]))
dbcommit()
```
The above is a simple web crawling program to collect web page data, clean and store the data in Mystical. It should be noted that when cleaning and converting data, appropriate tools and methods should be selected according to the type and format of the data to ensure the accuracy and integrity of the data.
I want to create a mysql-based database, and then save the registered account password and text of the webpage into the database.To set up a mysoul database, you need to use the following command:
```
CREATE DATABASE database_name;
```
`database_name` is the name of the database you want to create.
Next, you need to select the database and specify the table name to save the data. Suppose you want to create a table named `users` that contains the user's registered account password and text information, you can use the following command:
```
USE database_name;
CREATE TABLE users (
id INT(11) NOT NULL AUTO_INCREMENT
username VARCHAR(50) NOT NULL
password VARCHAR(50) NOT NULL
text VARCHAR(200) NOT NULL
PRIMARY KEY (id)
UNIQUE KEY username (username)
);
```
This command creates a table named `users` which contains three columns,`id`,`username` and `text`. Each column has the appropriate type and length requirements, and each column needs to be set to a default value and a Unique Key.
Next, you need to create a unique ID value for each user so that you can correctly identify the user during the query. You can use the following commands:
```
INSERT INTO users (username password text) VALUES ('user1' 'password1' 'text1');
INSERT INTO users (username password text) VALUES ('user2' 'password2' 'text2');
```
These commands will create two new rows for you to store the information of the two users,`user1` and `user2`.
Finally, you need to save the data into the mysmysticism database. You can use the following commands:
```
USE database_name;
backup the database;
```
This command will back up your database so that you can quickly restore the data if you need to restore it.
Now you have set up a Mystical database and created a table containing user information. Next, you can use Mystical queries to retrieve and manipulate the data.