Create MySQL Database and User

This section explains how to create CNCC user and CNCC database.

  1. Login to the server or machine which has permission to access the SQL nodes of NDB cluster.
  2. Connect to the SQL nodes of NDB cluster one by one.
  3. Execute the following command to login to the MySQL prompt using root permission or user, which has permission to create users with permissions:

    mysql -h -uroot -p

    Note:

    After writing the command mentioned above, user must enter MySql password.
  4. Check whether CNCC user already exists. If user does not exist, create a CNCC user by executing following commands:
    1. Execute $ SELECT User FROM mysql.user; to list the users.
    2. If user does not exist, create the new user by executing $ CREATE USER '<CNCC User Name>'@'%' IDENTIFIED BY '<CNCC Password>';
  5. Check if CNCC database already exists. If the database does not exist, create a CNCC database and provide permissions to CNCC user created in the previous step:
    1. Execute $ show databases; to check if database exists.
    2. If MySql has CNCC database created as per release 1.0.0, drop it before creating cnccdb by executing the following command:

      DROP DATABASE cnccdb
    3. Execute $ CREATE DATABASE IF NOT EXISTS <CNCC Database> CHARACTER SET utf8; for Database creation.
    4. Grant permission to user by executing the following command:

      $ GRANT SELECT,INSERT,CREATE,ALTER,DROP,LOCK TABLES,CREATE TEMPORARY TABLES, DELETE,UPDATE,EXECUTE ON <CNCC Database>.* TO '<CNCC User Name>'@'%';
Example to demonstrate cncc user creation, cnccdb creation and granting permissions to cncc user:
# Login to MySql prompt:-
$ mysql -u root -p
Check user already exists or not
$ SELECT User FROM mysql.user;
# In case, user already exists, move to next step. Command to create new user is as mentioned below:-
$ CREATE USER 'cnccusr'@'%' IDENTIFIED BY 'cnccpasswd'
# Command to check if database exists:-
$ show databases;
# Check if required database is already in list. If MySql has cnccdb already created as per 1.0.0 release creation, drop it.  
$ DROP DATABASE cnccdb;
# Database creation for CNCC
$ CREATE DATABASE IF NOT EXISTS cnccdb CHARACTERSET utf8;
#Granting permission to user:-
$ GRANT SELECT, INSERT, CREATE, ALTER, DROP, LOCK TABLES, CREATE TEMPORARY TABLES, DELETE, UPDATE, EXECUTE ON cnccdb .* TO'cnccusr'@'%';