pb_SKAT
pb_SKAT

Reputation: 163

How to create a MySQL installation setup script?

I have an application that stores its data in an MySQL database. The application is using a specific DB account with full access, the indivdual user rights are maintained on application level. Apart from root there is no other user with access to that database.

In order to install the application on a computer I need an sql script that creates the database, the application user, all tables without data, views, triggers, stored procedures, etc.

mysqldump --no-data --routines --add-drop-database --databases dbname > sqlfile will do almost all these things but I could not find any option to include the creation of the user having access to that database. Any hints?

Upvotes: 1

Views: 2575

Answers (2)

Neha Chopra
Neha Chopra

Reputation: 1791

Before introducing the application dump to your database.

  1. First list down the users which all are available with you:

SELECT User, Host, Password FROM mysql.user;

  1. Check if that user has permissions using "show grants" command to perform the operation, else provide the permissions to do so.

GRANT ALL PRIVILEGES ON . TO 'root'@'localhost' WITH GRANT OPTION

  1. Create the database name where you want to introduce the dump.

Upvotes: 0

e4c5
e4c5

Reputation: 53734

The reason that mysqldump doesn't dump user information is because that is stored in a different database name mysql rather than in the database for your applicaation.

You cannot add this information manually to the generated sql dump either. You have two options. Create a shell script or create a separate sql file that contains user creation information. In either case your file will include statements like

GRANT ALL ON appdb.* TO 'pb_skat'@'localhost';

http://dev.mysql.com/doc/refman/5.7/en/grant.html

Upvotes: 1

Related Questions