- #CREATING MYSQL DATABASE WORKBENCH AND USING WITH FLASK HOW TO#
- #CREATING MYSQL DATABASE WORKBENCH AND USING WITH FLASK UPDATE#
- #CREATING MYSQL DATABASE WORKBENCH AND USING WITH FLASK CODE#
To do so, from the top menu select ‘Server’ and ‘Data Export’ Option as shown in the below image.
#CREATING MYSQL DATABASE WORKBENCH AND USING WITH FLASK HOW TO#
Now let us see how to export the School database. INSERT INTO `school`.`studentaddress` (AddressId, StudentId, City, State) VALUES (2, 'Priyanka', 'Dewangan', 'Second', 17) INSERT INTO `school`.`students` (StudentId, FirstName, LastName, Class, Age) Please use the below SQL Script to create the database, table, and data. So, let us first create a Database called School and tables Students and StudentAddress with some data. In order to export a database using MySQL Workbench, we should have a database on our MySQL Server. Export MySQL database using MySQL Workbench:
#CREATING MYSQL DATABASE WORKBENCH AND USING WITH FLASK UPDATE#
Please read our previous article, where we discussed how to Insert, Update and Delete Data Rows using MySQL Workbench. In this article, I am going to discuss how to Export and Import MySQL Database using MySQL Workbench.
#CREATING MYSQL DATABASE WORKBENCH AND USING WITH FLASK CODE#
This may seem like an odd assignment, but getting errors is one of the best ways to start uncovering how things work, and what different parts of our code do.
Note: We will need to call on the connectToMySQL function every time we want to execute a query because our connection closes as soon as the query finishes executing. # Iterate over the db results and create instances of friends with cls. # Create an empty list to append our instances of friends Results = connectToMySQL('first_flask').query_db(query) # make sure to call the connectToMySQL function with the schema you are targeting. # Now we use class methods to query our get_all(cls): # model the class after the friend table from our database # import the function that will return an instance of a connectionįrom mysqlconnection import connectToMySQL Now we are gonna use OOP, and create a class that is modeled after our table in a file called friend.py. If the query goes wrong, it will return False.UPDATE and DELETE queries will return nothing.INSERT queries will return the auto-generated id of the inserted row.SELECT queries will return a list of dictionaries.
While you don't have to understand everything 100%, you should know how to use the file and recognize the principles of OOP at work. Read all of the comments in the mysqlconnection.py file to understand how it works. By the end of the bootcamp, you will be experienced enough to create your own connection files! # connectToMySQL receives the database we're using and uses it to create an instance of MySQLConnectionĪt this time, you do not need to know how to create one of these files. # if the query fails the method will return FALSE # UPDATE and DELETE queries will return nothing # SELECT queries will return the data from the database as a LIST OF DICTIONARIES
# INSERT queries will return the ID NUMBER of the row inserted # establish the connection to the database # this class will give us an instance of a connection to our databaseĬonnection = nnect(host = 'localhost',Ĭursorclass = , # a cursor is the object we use to interact with the database