Loading
Lesson 23
Courses / Build a Web App like Twitter from Scratch Using HTML, CSS, JavaScript, Express, MySQL
Finishing the Configuration of MySQL after Debugging – Express Tutorial

Video Transcript

We are back. Let's start. Let's continue debugging this thing. So, in my SQL, we have installed my SQL, in my case 5.7 server, community server, and have a problem with my NPM driver. It's not working fine. Client does not support its education protocol, requested by server. Now, I think perhaps if create a new user that might work. I know that this error happened if you have version 8 and the NPM package at some point did not support it. Probably, I don't know if it still has that problem, but I was puzzled that it did a manifest in version 5.7. Anyway, I suspect something to do with the password, the way it's being authenticated, right? Something about the case of protocol. So, let's do the following. Let's go into my SQL. Let's create a new user specifically for our application. Alright, so let's do that. Let's do create user. Give it a name. I can be a write something user. Okay, so it's going to be at Locos, in our case, identified with my SQL native password, in this case. I'm using version 5.7 server, okay? And you give it whatever you want for the password. I'm just going to do it down here. There's some policy requirements. Probably, it's asking for an American, so on. Let's try again. I'm going to do 1, 2, 3, 4, 5. Okay, I think it's asking for an uppercase letter. Now we have numeric, we have lowercase. Let's try ABCD. Okay, still does not satisfy. Okay, let's try again. ABCD. That's good. I don't know. There you go. It needed a punctuation character. Finally got something. That's flush privileges. Let's try it out. My SQL issue. What was the name of the user? Write. Something user. There you go, I got in. Exit. Let's update. Instead of root, we're going to use the write something user. And for the password, we're going to update my environment variable. Give me a moment. I'm just going to my bash rc and changing my export my SQL password to be equal to the new one. Make sure to have a good password. I'm just doing an easy one for educational purposes, but you should always have a good strong password. And don't tell anyone and don't put ever ever put it in the source code. I was using environment variables. Never commit your password or any kind of token to your source control. Okay. Give me a moment. Okay. Back here. Checking. If I think I'm good. I'm going to source my bash rc so I can reload it and load the variable. Let's try this again. Okay, I have the problem access denied now using password. No, why not? Why not? Yet another error. Hold on, might be something to do. Let's let's check the issues again. Oops. Let's copy this. Let's practice again. So if you want to find out, learn more about if somebody had the problem before, right? You want to go to the page for the package. You should get some section of issues or problems or questions, whatever this case issues. I can do a search here. Look at this is one in this case. There's no open but there's close. Read error, something. Uh huh. What is this? But this one is using yes. Why is it not using password for mine? Let's do a search here. Search engine. This is Stack Overflow. We got problem. As like they ran command. Fine. Can reset. You know what? Let me try something here. I think maybe what I did in my bash profile was not proper. Let me reload. Oh, it just hit me. I know what's going on. Okay, so I have loaded my reload in my bash RC here by the actual session. What the server is the other tab, but the other tab has not sourced the bash RC. Therefore it does not know about my SQL password environment variable. Try again. And I'm afraid maybe that problem was there before and I didn't know even before our new user creation. I don't know. Let's see what happened. The access denied database my SQL. Okay, let's let's create a database for our application now. So let's do sudo my SQL. Let's do create database. Let's call it. What do we call it? Right? Something. I think we I'm going to use underscore here. I'm afraid and dash that won't it won't allow us to use dashes. Write something. Let's call it development. Okay, show databases should now have it. And it's here. Now let's try it here. Write something development for our database. Now this query being valid, right? So I'm afraid that that our user does not have access to a database. My SQL. That's why it happened. Anyway, let me just create a table here quickly. Just for testing. Table entries. And we got say ideas. Was it? Is it in? I forgot to use database use, write something development. And then I'm going to create table entries insert into entries. values. ID values. Select star from entries. Now we got something. Okay, great. Now let's do that star. Sorry to have to change this select star from entries. I just created a database for testing. We can change that later and drop it. Now let's try again. Let's go to the other tab. Access denied for that user's database. So I'm guessing my user is not configured to have access to that database. So we have to alter and give grant privileges, right? So let me think about that. So there's a command we can use. Let's go to my SQL again. So do my SQL. We got to find out how to do that. So let's do grant. So you can grant certain kinds of privileges, right? Can a user make it a database? Can you read at least something or whatever? Let's just grab our user everything. Okay, so grant all privileges on. And this is the database we want. We're going to do the write something development database. Okay, it could be any table dot star any table to we got the user. I could be what it was a write something user. Okay, we can say out local host. Try that. Now let's try again. And finally it's working. So wow, we did it. So first problems with the password. I think I had forgot to source my bash RC and therefore this session of the term did not have my password. So that was a problem. So make sure you source your RC after you define the environment variable in the file. And in the same tab, I did a silly mistake. Second step was my newly created user. I usually want to have a user for your application, right? I did not have privileges to modify that is to access my database, right? So we grant, printed all privileges, so we can use the command in my SQL prompt grant all privileges on the name of the database dots star meaning any table it could be specific tables if you want it. The star means every table in this database. And to the user at local. They finally got it working and we got some response here seems like the was it. We do this. So we did a console log for the results right. So results is an array of row data packet. And inside that we got the actual column that with value column ID value one. We can get results. Zero would be the first row right we found. Remember before we had this is the first row here in the client. And this is how it appears here. Of course we had more right if I can do another insert. Oops, and I forgot to select database again. You can do the user we can just type write something development dot here. That means database dot the table name. And we got that. Now if you do a select here of course going to get right to the score something development dot. We got 132. Let's try it here. I just did some zero so maybe I want to remove that we got 132. Nice. Okay, so another thing is the hello thing I put there I wanted to do that to make sure. So is this calling it is it is it a synchronous asynchronous meaning the moment this call that will continue execution beyond that will we will wait. Until the server skill so it's not waiting at all right starting and then even after that it's doing the hello first and then doing the service listening later. So it is asynchronous so we have to find a way where to place this connection and there must be a better place right because you don't want to end the connection as as what is happening here is it's listening on part 3000 but at the same time. It already closed the connection to the database and that's not good because you need to have the connection open right so to be able to make the queries and so on. So we need to find a better place with that. Anyway, I think for this lesson that's very good. Let's take a break and I'll see you in the next one.
No comments yet (loading...)
No comments yet (loading...)
Did you like the lesson? 😆👍
Consider a donation to support our work: