Nodejs is connected to mysql. The table does not exist. A lot of information has been found on the Internet. The books around him have been turned over and are still unresolved.

  mysql, question

It’s been going on for almost a night, but I don’t know how to solve it.图片描述

图片描述

The topic owner probably doesn’t know much about js asynchrony, does he? People who come from languages such as php may have little contact with asynchronous operations. You just need toinsertData();This line goes toconnection.query();Inside’s second parameter method is ok. Specific as follows

var sql = 'create table if not exists users(id INT(50) not null auto_increment primary key);'  ;  //Because you created a table but did not have any fields, you will also report an error, so you changed your sql.
 
 connention.query(sql,function(err){
 if (err) throw err;
 insertData();  //Put the method of inserting data here and execute it.  Otherwise, according to your original writing, insertData () will be executed before the table is created, so you will be prompted that the table does not exist.
 });

If you copy the above code directly, you should also report an error, because I only wrote one field for you to create the table, and add the remaining fields yourself.

In addition, find out what asynchrony is by yourself. I found a good article.Http://www.ruanyifeng.com/blog/2012/12/asynchronous% EF% BC% BFjavascript …