Forums

Importing data into MySQL Database

I have exported MySQL data on my desktop into a export.sql file and have uploaded to /home/mydentalplan folder on PythonAnywhere server.

How do I import this schema+data into MySQL Database on PythonAnywhere?

just type in the MySQL command line

USE username$databasename;    
SOURCE backup.sql;

I have the same question. I have an version compatibility error. What can I do to run different versions?

You can't on PythonAnywhere. Everyone has the same version. You might be able to get your local version to output for the version on PythonAnywhere or work out a way to not use whatever feature is causing the version issue, though. That would depend on what you're doing and what version you're exporting from.

Another alternative is to use Django dumpdata and loaddata. Actually, I never succeeded importing database through raw sql dump.

Check out our help pages for more detailed instructions. And if you are trying to connect from outside of pythonanywhere, you will need to setup ssh tunnelling.

I use the commands from this thread to try to import MySQL db and I get this error:

ERROR 1146 (42s02): Table 'CostaRica$cagecds.cagecdstype1_2' doesn't exist

cagecdstype1_2 is the name of the table I uploaded and cagecds is the name of the database I made in pythonanywhere MySql.

I tried creating a table with the exact name and schema. That seemed to work but then i try to do USE CostaRica$cagecds; SOURCE part1.sql; and still get same error.

I feel like i might be making a few errors. Any help please?

can you show us the steps you took to create the cagecds.cagecdstype1_2 table?

From my ‘Databases’ tab I selected start console on: CostaRica$cagecds

In the console I entered:

CREATE TABLE cagecdsType1_2 (id INT PRIMARY KEY AUTO_INCREMENT, cageCode VARCHAR(5), addNum VARCHAR(2), adrsNmCTxt VARCHAR(36),adrsNmLo_2 VARCHAR(2), adrsNmCtxt_2 VARCHAR(36),
          stAddress1 VARCHAR(36), stAddress2 VARCHAR(36), PoBox VARCHAR(36), city VARCHAR(36), state VARCHAR(2), zipCode VARCHAR(10), country VARCHAR(36), phone VARCHAR(20))

I copied this right out of a jupyter notebook and formatting seemed a little off but just beneath that line I got the response “Query OK, 0 rows affected (0.03 sec)”

I see the table name I entered was different than in my upload. My uploaded file contains a table called "cagecdstype1_2". The table I made in the code above used a capital "T". I corrected that issue but I think my problem is the table isn't sticking or maybe I need to commit. I tried adding "COMMIT;" but that doesn't seem to help either.

I think the T vs t issue is that MySQL can be case insensitive for table names, and everything is probably set to lower case. Not 100% sure- how did you correct the issue? And what do you mean "the table isn't sticking"? The table should definitely have been created and continue to exist.

My specific issue is I have a database I’ve backed up from my local computer to /home/CostaRica/part1.sql. I want to use this in my PA website. How do I go from where the file is now to the MySQL framework in PA?

I’ll try to summarize my steps here

  1. Enter the in PA console for MySQL: CostaRica$cagecds
  2. Make the cagecdstype1_2 table using syntax above. At this point I check that the table is made by entering ‘SHOW TABLES in CostaRica$cagecds;’ I see cagecds in the list.
  3. ‘USE CostaRica$cagecds; SOURCE part1.sql;’ At this point I get the error repeated many times: ERROR 1146 (42S02): Table 'CostaRica$cagecds.cagecdstype1_2' doesn't exist
  4. Enter ‘SHOW TABLES in CostaRica$cagecds;’ but now the console returns: Empty set (0.00 sec)

I've done step 3 without using 2, as another form post suggested, and I get the same error. This suggests to me that the console can read the table name inside part1.sql but I must still be doing something wrong to access the table in part1.sql.

Is there guidance that you can provide to help with my struggle? Thanks!

Is there a reason not to follow our help page about (dump on your local machine, restore on PA)?

No, my apologies and thank you. I guess I stumbled onto other posts that I thought would get me to where I want.

These instructions make more sense to me, but I’m still getting something wrong. From the bash console I entered

mysql -u CostaRica -h CostaRica.mysql.pythonanywhere-services.com 'CostaRica$cagecds'  < part1.sql

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual… near ‘mysql -u CostaRica -h CostaRica.mysql.pythonanywhere-services.com 'CostaRica$cag' at line 1

I tried this from the MySQL: CostaRica$cagecds console

I also tried creating a table and backing up using instructions from the top of the page and I also get same syntax error.

You;re trying to run that command in a MySQL console. Use a Bash console instead.

Thanks for bearing with me.

I'm now getting this error: ERROR 1273 (HY000) at line 25: Unknown collation: 'utf8mb4_0900_ai_ci'

I opened the Bash console instead of MySQL. I tried the commands in the directory that the console opens into. I also did ‘ls’ and I can see the file part1.sql in this directory.

I used MySQL workbench to backup my file instead of phpMyAdmin as another thread suggested. Does that have anything to do with this latest error?

Take a look at https://help.pythonanywhere.com/pages/DatabaseCharacterSets/

WHEN I TYPE SOURCE mydata.sql; I get the following error

Failed to open file 'mydata.sql', error: 2

That is not how you import data into mysql. See https://help.pythonanywhere.com/pages/MySQLBackupRestore/

Hi

I have my SQL file in this address: /home/mcaycedo/py_palabras/mysql/f_jugada_post.sql

How must be the command?

SOURCE "/home/mcaycedo/py_palabras/mysql/f_jugada_post.sql"; SOURCE /home/mcaycedo/py_palabras/mysql/f_jugada_post.sql;

These two didn't work

What is the command for? What do you want to achieve?

It's an stored procedure. Maybe 10 sentences. When I created in my local environment, worked perfect. When I copy/paste un the mysql console didn't work

Your MySQL has no access to the filesystem of your PythonAnywhere account.