Search code examples
pythonmysqlsqlhostingpythonanywhere

How to import data via MySQL Workbench with SSH?


I'm trying to upload data to my MySQL database on the PythonAnywhere server hosting via SSH (I have a paid account). I have three databases (alter$default, alter$ip_data and alter$visitor_data) from within the PythonAnywhere interface.

Using the online instructions (here) I can successfully connect to the server via SSH using MySQL Workbench, and see the three databases in the schemas window (Click here to view image of schemas list).

I can successfully add tables to the database of my choice, but when I try to add data I get Error Code: 1045. Access denied for user 'alter'@'%' (using password: YES).

I have tried troubleshooting:

For SELECT user(); it returns alter@10.0.0.89

For SELECT current_user(); it returns alter@%

For SHOW GRANTS; it returns:

  GRANT USAGE ON *.* TO 'alter'@'%' IDENTIFIED BY PASSWORD <secret> WITH MAX_USER_CONNECTIONS 6 
  GRANT ALL PRIVILEGES ON 'alter$default' .* TO 'alter'@'%' 
  GRANT ALL PRIVILEGES ON 'alter$visitor_data' .* TO 'alter'@'%' 
  GRANT ALL PRIVILEGES ON 'alter$ip_data' .* TO 'alter'@'%' 

It appears that I have the necessary privileges granted and am correctly connected to the MySQL server - so why will it not let me write to the database? Is the .csv file in the wrong place? I can't use the 'root' user as that is surely the PythonAnywhere administrator account?

Extra details: The SQL query for writing to the database - that returns "access denied" - is:

LOAD DATA INFILE 'VALUES.CSV'
   INTO TABLE ip_data_table
      FIELDS TERMINATED BY ','
      ENCLOSED BY '"'
      LINES TERMINATED BY '\r\n'
IGNORE 0 LINES;

Solution

  • It's the infile that is causing the permission denied. You need to start the mysql client with the --local-infile=1 flag.