![]() Follow the steps below to import a CSV file into a MySQL database via the Graphical User Interface. # in the below line please pass the create table statement which you want #to createĬursor. We’ll use MySQL Workbench, one of the most popular GUIs for MySQL. Print("You're connected to database: ", record)Ĭursor.execute('DROP TABLE IF EXISTS employee_data ') We will create an employee_data table under the employee database and insert the records in MySQL with below python code.īuild Professional SQL Projects for Data Analysis with ProjectProĬonn = nnect(host='localhost', database='employee', user='root', conn.is_connected(): Step 4: Create a table and Import the CSV data into the MySQL table ![]() Output of the above code: After running the above the code will create an employee database in mysql as shown in below. Note :if you don't connect then, please install the mysql-connector-python package, type the following command: pip install mysql-connector-python Print("Error while connecting to MySQL", e) Step 3 : Connect to the MySQL using Python and create a DatabaseĬreate a connection object to connect to MySQL, The connect() constructor creates a connection to the MySQL and returns a MySQLConnection object.Ĭonn = nnect(host='localhost', ur username, passwordĬursor.execute("CREATE DATABASE employee") However it stops importing the first 5 records. You'll need to change the path name to reflect the location where the CSV file is stored on your computerĮmpdata = pd.read_csv('C:\\Users\\XXXXX\\empdata.csv', index_col=False, delimiter = ',') 4 Hi I am trying to use to MySql Workbench Data Import facility to import a. Here is the code that I used to import the CSV file, and then create the DataFrame. Next, import the CSV file into Python using the pandas library. Note: the above employee csv data is taken from the below link employee_data Step 2: Import the CSV File into the DataFrame. For example, I prepared a simple CSV file with the following data: To begin, prepare the CSV file that you'd like to import to MySQL. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |