Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Automation via bash script (mysql creation)

Discussion in 'Database Discussion' started by fergusweb, Sep 24, 2010.

  1. fergusweb

    fergusweb Registered

    Sep 24, 2010
    Likes Received:
    Trophy Points:

    I've been trying to write a bash script to automate our site deployments. I've got it fetching our compressed file, extracting it to the right location, and setting file permissions/ownership. I also need to set up a MySQL database & user via the script, which is where I'm having some trouble.

    I've got it creating a databse & user, which then appear in the cpanel account for that user. So that part is great. But I can't seem to grant permissions.

    sudo mysql --user=${MYSQL_USER} --password=${MYSQL_PASS} --execute="create database $DB_NAME"
    sudo mysql --user=${MYSQL_USER} --password=${MYSQL_PASS} --execute="CREATE USER '$DB_USER' IDENTIFIED BY '$DB_PASS'"
    sudo mysql --user=${MYSQL_USER} --password=${MYSQL_PASS} --execute="GRANT ALL ON ${DB_NAME}.* TO '$DB_USER'@'localhost' IDENTIFIED BY '$DB_PASS'"
    sudo mysql --user=${MYSQL_USER} --password=${MYSQL_PASS} --execute="FLUSH PRIVILEGES"
    Can anyone tell me how I would grant my new user full privs on my new DB, and have that be reflected in cpanel? My level of experience here is pretty low.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice