Create MySQL Database and User
This section explains how to create CNCC user and CNCC database.
- Login to the server or machine which has permission to access the SQL nodes of NDB cluster.
- Connect to the SQL nodes of NDB cluster one by one.
- 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. - Check whether CNCC user already exists. If user does not exist,
create a CNCC user by executing following commands:
- Execute
$ SELECT User FROM mysql.user;
to list the users. - If user does not exist, create the new user by executing
$ CREATE USER '<CNCC User Name>'@'%' IDENTIFIED BY '<CNCC Password>';
- Execute
- 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:
- Execute
$ show databases;
to check if database exists. - 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
- Execute
$ CREATE DATABASE IF NOT EXISTS <CNCC Database> CHARACTER SET utf8;
for Database creation. - 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>'@'%';
- Execute
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'@'%';