Loading
Lesson 21
Courses / Build a Web App like Twitter from Scratch Using HTML, CSS, JavaScript, Express, MySQL
Installing MySQL – Nodejs Express Tutorial

Video Transcript

In this lesson, we are going to learn how to install my SQL. So so far, we have the client working with the server. Now the server is storing its data in memory if we go to server.js, lines, and through 23 define an array of objects. Now this data stays in memory as long as the server is run. When the server is shut down and restarted, all that data is gone because every time the server starts, it starts with entries anew because of this hard coded value here. That is not a good way to start data at all because everything we type, everything you put in there is not persisted. It gets lost. So enter the database. We are going to use an SQL database called mySQL or mySQL. So we are going to start in that database. That we're going to have a database that database has many tables. For our case, we're going to have one table to store the entries. That would be the interest table. The interest table will have some columns. Since we already defined the representation of the data in this manner here in this object, it's easy to translate that into a database column. Simply take the keys from the object and make that the column. So we'll have the ID as one column. This column will be the primary key. The second one will be the text. Okay. Now let's go to the mySQL website. This is the website for mySQL. There are many ways to install mySQL depending on your system, depending on whether you want to use a package manager. Okay. So here are some ways you can do to install mySQL. If you are a Windows user, you can simply download the installer from mySQL.dev.mySQL.com website. For example, if you go to the website, you can click developer zone. It goes to my... dev.mySQL.com. You can go to mySQL downloads and here have the option mySQL installer for Windows. This is the community edition. You can see this is version 8.0.21. And you can get the MSI here. If you're using Mac OS, there's also an installer. Here's a link I put for version 5.17. It's still a stable version, even though not the latest. And that's the PKG. If you want, you can also go to the same website. Let's go back one. And that might be somewhere here for Mac. We just got to look. I think it's community server and I claim select the operating system Mac OS. And there's a DMG archive, for example. Now the way is using brew. If you have brew package manager for iOS, for Mac OS, you can do brew install mySQL. For my case, I'm using Linux. The distribution is Ubuntu. I can use my own package manager instead of downloading from the website, although you can also do that. You can go back and there's an APT here. Now for other distributions like Fadar, there's YUM, and there's SUSE and so on. Anyway, I'm going to do my case using APT. APT has been on top of APTGAD. You can also do APTGAD, it doesn't matter. Very simple, just update the repository next and install the mySQL server package. If you want to do the secure installation to disable certain features that are by default to make it more secure, we can do this one. And finally, we can use the client, right? Because we have the database server, the mySQL server, and we need a way to access the database. And that's through the mySQL client that we get. That's the command mySQL. Of course, you can use utilities like the mySQL workbench, that's a GUI you can use. I recommend that too. Up to you. Anyway, let's get started here. I'm going to use the command line. I'm going to do sudo to get privilege. APT update to APT. Packet manager for Ubuntu. Let's update the repository index list. Might take some time. And we can do sudo APT install mySQL Dev server. Now it's usually asked if you want to go on. I said yes before because I already installed. And I'm doing it again. So this is installing version 5.7 for me. I'm using Ubuntu 18.04 long term support. So the package manager recommends I use that version. Of course, you can always find out if there are packages for the newer versions depending on what version of your distribution you use. So with that, let's try mySQL-desk version. This should give us the version of the client. You can do sudo service. Maybe mySQL status. We can see it's running mySQL community server. Exact as year and so on. Control C. I think some of the configuration is under ETC slash mySQL. And there are some files there. MySQL comfd, mySQL cnnf, the one. Just so you know. Before do a secure installation, I just want to check if it's working. So sudo mySQL, it's going to connect us to the database server. We got it here, show databases. And we got everything fine. Let me exit. We can do the optional mySQL secure installation to make things more secure. There are certain questions that will be asked. And it's up to you to choose to adopt them or not. Let me try mySQL secure installation. So the first one, let's see. Connected to mySQL using a plan of password. I think I already installed this so I didn't ask. So there's something about the validate password plugin. Can you choose to have it or not? Connected to mySQL is a blank password. The validate is installed because I already did. But if you didn't have it, I'd probably ask you for that. Subsequent steps to run existing configuration. Set the password for root here. You can set a password for root if you want. Of course, that's a recommended study for production. Length of the password and so on. It's probably going to ask about the password strength also. I already did that before. And of course, you want to choose the strongest for your production one since we're doing education here. I'm trying to be a little less. But always go for the strongest one. Better strength, so on. Do you wish to continue? Yeah. Okay, so by default, the mySQL installation has an anonymous user. I want to log into mySQL without having to have a user account creator for them. This is intended only for testing. To make the slash go a bit smoother. You should remove them before moving into production environments. So make sure to do that as you go into production. I'm going to remove it. I don't care. Normally, root should only be allowed to connect from local host. This ensures someone cannot guess at root password for the network. Just allow root logging remotely. If you want that, I'm going to say yes. There's also the test database. I want to remove it and access. Remove the access. Reload privilege table now. Yes. Okay, all done. So I can do so do my sequence should be working fine. Mind you that when I do so do running the command as root, so it's working. Okay, so that's it. I installed my SQL and I can connect using the client. Now we can start poking our back end to connect to my SQL database server. And then we can start doing some queries to insert data. And we're going to create the table and then we're going to do some queries to insert data and so on. 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: