#๐Ÿ”’ MySQL Database Error

39 messages ยท Page 1 of 1 (latest)

shy beacon
#

I created a MySQL database and a table within the database, I try to run the SQL in my app only to be met with an error which I have yet to see a fix for. It tells me that "Database survey.survey does not exist", yet when I open MySQL Workbench and check, both Database survey and Table people exist and I can edit it through Workbench but not Python. Is there a work around for this? I cannot seem to make it work no matter what I change or how I change it. Refer to my screenshots which show the errors and my Workbench setup which displays both the Database and the Table for it.

frail canopyBOT
#

@shy beacon

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

sharp sierra
#

Are you sure you have a survey table? The screenshot doesn't show that.

shy beacon
#

Yes, let me show you

shy beacon
#

Look

#

Database: survey
Table: people

#

Columns: name, age, gender, city

sharp sierra
#

So, did you mean survey.people?

#

I don't regularly use SQL (we use Mongo), so I can't remember the exact notation, but the error indicates that you attempted to access a survey table, when you don't have such a table.

shy beacon
#

This is what I want to do:

I want to load the tables on screen from the database and display the user information. But when I load the data, I get a ton of errors.

#

Let me show you

shy beacon
#

It should read everything from the database and display it on the screen. Though it just crashes my app. I tried changing it from 'survey' to 'people' and the same crash happens. Its something with MySQL not liking python

gentle yacht
# shy beacon

you are doing FROM survay, that means that you are trying to access a table named survay, that is not the database name there

#

you want to use FROM people if your table is named people

shy beacon
#

I tried that but it didnt work either

gentle yacht
#

as have already been noted by Carcigenicate the error message says survey.survey meaning database survey (which is correct) but table survey which is wrong

#

you even show us your people table

shy beacon
#

I think I fixed it though, for some reason the data wasnt loading for MySQL in PyCharm and it was causing a conflict. I deleted the table and remade it and it works now.

#

Idk what the error was LOL, I couldnt get it to load anything but I guess a good DROP command fixed it

#

Lets see it in action if itll work

gentle yacht
#

you will probably get problems down the road if you use SELECT * in your code of your app, instead specify the tables names in the correct order that you want to fetch them in

#

otherwise if you alter or recreate the able later and it's not exactly as the table you got now you will get errors

shy beacon
gentle yacht
shy beacon
shy beacon
gentle yacht
#

@shy beacon another thing to remember is to not interpolate or concatenate or similar strings that can be affected by a user in any way into an SQL statement, always use bind variables/placeholders for things that can be affected by a user
if that isn't possible (for example for column names or table names, use for example a lookup table to make exact comparisons to the input so be sure that it matches exactly what you expect and doesn't contain anything malicious/unexpected (SQL-injection attacks) that could be used to breach the security of your database

shy beacon
royal dove
#

Regardless of how big you think the app will be, security issues are still security issues.
It's good practice to always use the proper technique and avoid this kind of exposure early.

gentle yacht
# shy beacon I understand the message: Dont expose yur data, but I am lacking in the terms yo...

concatenation is just when you add two or more strings together to form a single longer string
like the below uses + and += for concatenation

name = "Alice"
print("Hello " + name + "!")

interpolation is when you expand a variable or something that produces text within a string
for example using "f-strings" (format strings that begin with a f just before the opening quotes

name = "Bob"
print(f"Hello {name}!")

and as GraiceTurrble notes, it's good to get into good habits and practises regardless

shy beacon
#

Im going to close this since my problem is fixed, but I will message all of you privately if thats okay so I can talk more in depth in DM ๐Ÿ™‚ Thanks to you all โค๏ธ

#

!close

frail canopyBOT
#
Python help channel closed with !close

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.