Available in VPC
MySQL Stored Procedure organizes SQL syntaxes that perform a series of procedures so they can be run in CALL function(); format.
MySQL Stored Procedure provides 4 features: creating user accounts, creating new databases, changing the password, and viewing the list of accounts created.
Access MySQL DB
To run MySQL Stored Procedure, you must access MySQL DB after accessing the cluster server where the database is installed.
To access MySQL DB:
-
Access the cluster server through SSH directly.
- For more information, see Access a cluster node with SSH.
- Run the following commands to access MySQL DB.
- Connect to the master node via SSH and execute the command.
- Enter the cluster administrator account information in
[관리자 계정]and execute the command. WhenEnter password:appears, enter the account password.
$ mysql -h mysql.local -u [admin account] -p Enter password: Password
How to use Stored procedure
Check the procedure creation
To view the created procedure:
- Among the DB lists that are output after you run the
show databases;commands, access Ambari DB with the following commands:- Enter the name of the database you want to access in the ambari_{unique number} location.
use ambari_{unique number}; - Run the
SHOW PROCEDURE STATUS WHERE DB = 'ambari_{unique number}';commands and check the 4 procedures created in Ambari DB.
- Currently available procedures: CHANGE_PW, CHECK_USER, CREATE_DB, and CREATE_USER

Create the database
To create a database:
-
Enter the name of the database you want to create through the
CREATE_DBprocedure.- Example of the database name:
new_database
call CREATE_DB('new_database'); - Example of the database name:
-
Run the
show databases;commands to check the newly created database.

Create the user account and view the list of user accounts
To create a user account and view the list of user accounts:
- Enter the user account to create and the password through the
CREATE_USERprocedure.- Example of the user account:
new_user - Example of the password:
password!
call CREATE_USER('new_user', 'password1!'); - Example of the user account:
- View the list of accounts and check if the user account is created through the
CHECK_USERprocedure.call CHECK_USER();

Change password
To change the password:
- Through the
CHANGE_PWprocedure, enter the name of the account whose password you want to change and the new password.- Example of the target user account:
new_user - Example of the new password:
change_pw2@
call CHANGE_PW('new_user', 'change_pw2@'); - Example of the target user account:
- Check if the
Query OKmessage is output. If the message is output properly, you can access it with the changed password after that.
