Recently started to learn MySQL, because the school is a bit miscellaneous, to my head, to clarify the idea for a long time ....
Now just a little thought, first write down for everyone to refer to, in fact, only me haha haha ~ ~ ~
I use the Express module in Nodejs, install MySQL recommended to download the official website;
Create a folder First Test
Then create a JS file in the folder, name Express.js
1) Install: Open Command Window in current folder, enter: NPM install Express installation Express module
2) Use: Open Express.js, enter:
varExpress = require (' Express ');varApp =Express ();//To process Get/post/put/delete requests:App.get/post/put/delete ('/', Function (req,res) {//processing Get/post/put/delete request}); App.get ('/login.html ', function (req,res) {//Handling GET Requests
Fs.readfile (' login.html ', function (err,data) {
if (err) {
Res.end ("404 page ...");
}else{
res.setheader (' Content-type ', ' text/html ');
res.end (data);
}
});
}); App.post ('/user ',function(req,res) { // processing POST request });
Jump to the ' login.html ' page, if there are references to server resources (images, CSS, etc.), you will find that these resources are not loaded ... This is necessary ↓
Server file Loading:
App.use (express.static (' public '));
Create a new folder in the Test folder public, the need to load the server images, CSS,JS, etc. into the public folder, so that the server resources can be loaded out.
Note: Although placed in the public folder, but the path is still the same old
HTML file:
//html file://assets/css/style.css < href= "Css/style.css">//public/images/1.jpg< src= "images/1.jpg">
Start the MySQL operation below:
1) Installation: mysql.com official website download
2) Use: ① Open the Workbench graphical interface to view the running status of MySQL:
You can see that the database is working and you can do the next step.
② Creating a Database
Click on the slice as
Enter the database name (not Chinese) → Click apply→ below and click apply→ Database creation succeeded
Create a table
Right-tables:create table→ input table name → input column name → Click apply→ click Finish
Table Creation Succeeded
③ to database additions and deletions
Right-click on select rows to open the sign table
After opening the image below, you can add/delete data directly in the table (remember to click on the Apply save operation after manipulating the data), or you can enter the command to operate the sign.
If you forget the command, there is a small way: for the following table operation (for example, I added a row of data: id=1,name=javencs,password=123), click Apply, a selection box appears:
Inside the statement is just I add data operation, = Copy this statement to the Code box, apply save, you can achieve the same effect;
Add Data:
Into ' hshs ': ' Sign ' (' id ', ' name ', ' Password ') VALUES (' 1 ', ' javencs ', ' 123 ');
Delete data:
DELETE from ' hshs '. ' Sign ' WHERE ' id ' = ' 1 ';
Find data:
SELECT * from Hshs.sign; // Find all data SELECT * from Hshs.sign WHERE id=1; // Condition Lookup
To modify the data:
UPDATE ' hshs '. ' Sign ' SET ' password ' = ' 456 ' WHERE ' id ' = ' 1 '; // Modify part of the data UPDATE ' hshs '. ' Sign ' SET ' id ' = ' 3 ', ' name ' = ' Jack ', ' password ' = ' 456 ' WHERE ' id ' = ' 1 '; // Modify a piece of data
Simple MySQL operation (i)