Skip to content

Instantly share code, notes, and snippets.

@arliber
Created April 2, 2020 08:49
Show Gist options
  • Save arliber/cc97129267f88e882d86de35aed215bb to your computer and use it in GitHub Desktop.
Save arliber/cc97129267f88e882d86de35aed215bb to your computer and use it in GitHub Desktop.
MySQL #snipepts

Locate MySQL

Add path to .bash_profile

export PATH="/usr/local/mysql/bin:$PATH"

You need to Change password before it starts

$ login - mysql -u root -p

mynsql > SET PASSWORD = PASSWORD('your_new_password');

Restore/Import error

UPDATE: To avoid all this, create a dump of your database and remove the first line in the backup file containing "DEFINER". Here is command to get it done quickly:

sed -i "" -e "s/.*50013 DEFINER=.*//g" <PATH TO FILE>

To develop locally one would want to bring in the the data from production over to staging or localhost. One limitation is that the views in the database are inked to creator - which differs from environment to environment. As an example, in production the user name might be prod_au_xyz and on localhost he might be called root. The error you might encounter is this:

DatabaseError: The user specified as a definer ('<user>'@'%') does not exist

To fix that execute the following query and then execute the resulting queries it produces:

SELECT CONCAT("ALTER DEFINER=root@localhost VIEW ", table_name, " AS ", view_definition, ";") FROM information_schema.views WHERE table_schema='<DB NAME>';

Note how the new definer is named root. This is usually the case for localhost. If the same fix is needed for staging - make sure to replace root with whatever username there is for staging.

More details: permissions - MySQL error 1449: The user specified as a...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment