MySQL Database with Python Tutorial Part 1 – Intro

MySQL Database with Python Tutorial Part 1 – Intro

What’s going on? Everybody [welcome] to another python series this series is going to be concerning my sequel with python so if you’re only after simple storage and retrieval And you want just the most basic solution for that yet. You still want to use an sql database then you might be interested more so in my sqlite series so sqlite as its name suggests is a Lightweight Sql solution that is really easily used with python and so I will put the links of those three videos in the [description] Basically the first one setting up the database second one is storing Data and the third one is retrieving Data now Historically I’ve avoided doing a full my sequel tutorial [mostly] because like windows users are going to tend to have issues installing and setting up an sql server to run on their computer and It just it just would have been a mess right so you got a like set it up and open up the right ports It’s in the correct information to the ninth ward of the interplanetary Xenon space [cake] Victor Charlie Alpha And you know what at that point? You know people just kind of throw in the towel, so we wouldn’t really get very far Probably have really bad retention because it’s just kind of tough So I did just recently show you guys that python anywhere website which is here and I Thought you know what this would be a good place to do sql plus python. So anybody that doesn’t want to have to deal with installing my sequel or My sequel post python rather so anybody there was one I deal with you know installing and setting up a my sequel server Maybe run their computer if they don’t already have like a shared hosting Plan somewhere or even VPS and whatnot That [they] could still follow along so even noobs because most of my tutorials I try to make them to the point where if you’re brand new you can still follow along so really this just makes the perfect solution because everyone in it will be able to follow along identically with me if they want to and Everyone is on the same platform. So that makes it just super easy So setting up an account on here is real quick and easy if you don’t have an account already You probably [rive] at a page like this. It’s completely free to make an account. You. Just don’t get a lot of processing [but] [we’ll] structure the tutorial so you won’t exceed that processing anyways [so] you can make an account just click here, and it’s very sincere, [and] it’s a little statement here You can create a beginner account and literally you fill this out hit this register You’re ready to go, so I’m going to go ahead and log in now to my account [which] just so happens to be beginner account? So [I’ll] log [into] that apparently that was Dashboard I don’t know why it sent me back to that page anyway So when you log in you should see something like this, and it just so happens that they’ve actually already got my sequel installed and ready to go if you decided to not follow my My advice and just follow us here you can run a sudo apt-get install my sequel – server sudo apt-get install Python – my sequel DB then do a my seat or go into your you know my sequel? Like with bash my sequel – you root – p get it. Just whatever it takes for you to get into that basically my sequel Line here, well, we can’t I can’t show you just yet, but I’ll show you guys in [a] second And then you just you know write create Database test DB Or whatever you want to make and you’re the name of your database, and then you’ll be able to follow along with us [and] that should be really it if you want to cheat so anyways with that I’m gonna let that you guys that want to blaze your own path will continue blazing your own path [so] anyway if now that you’ve got an account whenever you come here what we want to do is yeah, we want to make a database here, so and then also keep this in mind whenever you’re Connecting to a database like say you did have a local database a lot of times you can just say [Localhost] is where you want to connect As long as the files are [on] the same server, but you can’t do that here [so] this will take the place of Localhost And then your username is the same username you’re using and then database password suggested that you don’t use the same password account name Because of right here, it’s going to any any like text or any python applications You write that database password is going to be visible invisible? So with that I’m going to go ahead and make [my] password um cookies Since y’all are going to see it anyways, so set database password awesome So now we’ve got The first database here, and you can see the name of the database as always you get set [up] with a default database Or a database called default but every database you ever make like if you make another database like I’ll make a database called tutorial And you create that database You’ll see that it always starts with beginner account [dollar] son, and then the name [of] that database So that’s that now you’ve got the database setup announced Learn to kind of communicate with it. So eventually yeah, you want to communicate with it via a python script But also you want to know how to communicate with it by hand basically so you can later communicate, Via Ssh, and then later communicate via. Ssh by your program So it does become useful to be able to do this in plus if you want to run especially when it comes to creating tables That sometimes, it’s just quicker by hand to make [it] by hand then to code a program that makes the table if It’s a new thing anyways if you’re going to be making a lot of new tables And you might as well make a program to do it, but anyway and then also when it comes to like deleting or getting rid of maybe corrupt data you usually do that by hand, so Anyway, um it’s good to know how to do it. So what we’re going to do is pop over to consoles now They’re nice, and they give us a my sequel console, so you can just click on this and you start already in the my sequel console as soon as it loads and So yeah, so you’re ready to give my sequel queries But not everybody is going to have it that way and if you ever move on past [maybe] hosting here you have another hosting Provider you pry are going to get that you’re just gonna have a bash line when you connect by ssh It’s going to look more like this so how you get to that my sequel first of all you better have my sequel installed and a database and everything but here what you’re going to do is call my [C] cool and then [we’re] going to – you and then you put in your [username] in my case. It’s beginner I Was a beginner user being in our account already forgot. Let me go, okay. Look I just made it. It’s beginner at count So it gets right good job. We get our account and then – h and So user is just your [username] right and then – h will [be] Where you’re connecting so a lot of times it would be localhost, but in our case. We can’t do that so it’s my sequel dot server and @p and now you’re going to need to put in the password. This is the password Your database password right so in my case. It was cookies. Whatever yours is can be whatever. I highly suggest cookies. It’s a great password I’m just kidding. I don’t anyway [so] now we’re in the database so the first thing that you’ll be able to do and the only thing that we can do so Far since pretty much all we have is a database is run a command called show databases Don’t forget your semicolons otherwise. It’s going to do this to you, and you’re going to like I forgot my semicolon Anyway, so now what it’s going to do is is print out. It’s a best attempt at a gui and it prints out You know we’ve got information Information schema, then we’ve got the default table or I mean a default database not a table And then we’ve got the one that we made Now it’s not really necessary. You don’t have to do your commands [in] all caps, but all generally especially in code It makes it really helpful to anybody reading it to know What’s like a table name, and what’s an actual sequel command? So you’ve got all kinds of stuff like oops [I] thought I hit the caps select and insert and delete and all this kind of stuff [an] update not that update so you put in all caps But you don’t have to but [just] helps for your purposes and debugging and also reading your own old scripts maybe and then also if you’re collaborating with people It’s just nice another useful query to have it. You can run it pretty much whenever is show Process list and what this is going to do is show you all the processes that are occurring right now [and] so if you ever have like a process that you find yourself with my sequel is use Up a hundred percent of your cPU and you want to know what the heck is going on? You can do this and see what kind of processes are still running and then you can shut them down [by] their little Id right here, so you can kill the process I’ll probably show you guys that later But anyway, just that’s where you can start whenever if you if you do find yourself at [100%] you don’t know why? so Anyway, those are the basic topics now in the next video. I’m going to be talking about setting up a new table, [Via] you know the same rule command line here [and] Then a little bit of inserting data into those tables, and then probably in the next video after that Manipulating that data a little bit just and then also just some pro tips right. I’m not a pro But these are other people’s pro tips so anyway Stay tuned for those videos as always. Thanks for watching thanks [for] the support in the subscriptions and until next time

Danny Hutson

29 thoughts on “MySQL Database with Python Tutorial Part 1 – Intro

  1. These series didn't teach me how to install any of the modules needed to connect to mysql from python which is the most important part. At best i call this series add hoc and amateurish. No comprehensive tutorial. Don't waste your time on these tutorials.

  2. hi derek, im having trouble running an application. i have to connect the log in to mysql data base and from the data base the application gets username, password, ect. i was wondring if you can help me out set up my data base. im , im currently using xammp my sql and im only confused on where i have to set the users. on rows and rows. is there any way i can contact you so i can send you the script?

  3. Thank you for these tutorial. I wanna know if I can run the python code from outside pythonanywhere and access the database.

  4. It is showing an error while running the mysql command in the bash console
    ERROR 2005 (HY000): Unknown MySQL server host 'mysql.server' (0

  5. Hi bro am a beginner i just know basics of python can i learn this straight away or do you have any prerequisite course(playlist because you have plenty of playlist) ping me asap bro Thanks

  6. Man, Sentdex is so awesome… Every time I take up a big project hes already gone about building a tutorial for half the tasks involved haha

  7. Hi dude i just would ask you , what about mariadb they say that its better than mysql so do i learn mariadb or sql . Even this ,what is the diffrence between mysql and sql and nosql … all those kind of same names

  8. when i running the mysql command in the bash consloe than show error "command not find".Can u help me to resolve this error

  9. Hi Sentdex, I work in a lab that generates a lot of spectral data (each file can consist of 15 different columns about 4000 lines long of numerical values). There can be many parameters for each file (metal, number of laser pulses, energy used, date, user, etc.) I am thinking of building a database and using python to filter the data and display the results in various plots. I have python experience but only a tiny amount with SQL. I'm just curious if you have experience doing this with a database that would grow over time and if there is a preference between SQL, MySQL, and SQLite.

  10. Was searchin' for this and came across a playlist and thought, "oh nice a compiled finished list perhaps?" Turns out, it's by the lord and saviour himself. Thanks Sentdex Sensei! <3

  11. For those having the "(HY000) error " go to your database tab and where it says Database Host Name you have to enter that entire name into the console and then proceed with the rest it should work.

  12. WHO GOT (HY000) ERROR :
    2. COPY Database host address (
    4.PUT : mysql -uYOUR_USERNAME – -p

    that works 100%

Leave a Reply

Your email address will not be published. Required fields are marked *