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!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Create MySQL Database & User via Shell

Discussion in 'Database Discussions' started by Arhineus, Oct 11, 2007.

  1. Arhineus

    Arhineus Well-Known Member

    Nov 1, 2005
    Likes Received:
    Trophy Points:
    I'm trying to assign a MySQL database & MySQL user to a cPanel account via SSH.

    I believe the correct syntax to be the following.

    > create database account_dbname;
    > GRANT ALL PRIVILEGES ON account_dbname.* TO 'account_dbuser'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;

    When I go into the cPanel account to make sure I've done it correctly, the user doesn't seam to be assigned to the database. Have I got something wrong here?
  2. madaboutlinux

    madaboutlinux Well-Known Member

    Jan 24, 2005
    Likes Received:
    Trophy Points:
    When you create a database and assign a user from shell a back slash (\) get missed in the database name in the 'db' table. Connect to Mysql and execute the command:

    mysql> use mysql;

    mysql> select * from db;

    Check the 'Db' field and you will see a slash missing. The database name should be changed to 'account\_dbname' and at the moment it should be 'account_dbname'. Execute the below query and you will see the user assigned to database in cPanel.

    update db set Db='account\_dbname' where User='account_dbuser';

    This should fix the issue.

Share This Page