MySQL Server

release type access

  • Operating System:

  • Terminal:

  • Shell:

  • Editor:

  • Package Manager:

  • Programming Language:

  • Database:

release type access

  • Operating System:

  • Terminal:

  • Shell:

  • Editor:

  • Package Manager:

  • Programming Language:

  • Database:

release type access

  • Operating System:

  • Terminal:

  • Shell:

  • Editor:

  • Package Manager:

  • Programming Language:

  • Database:

MySQL is an open-source relational database management system based on SQL - Structured Query Language.

For more information, check the official documentation here.

Initialization

For information on how to use the Initialization parameter, please refer to the Initialization - Bash script section of the documentation.

Create a new server

The app requires to set the Database parameter, which is used to import the MySQL database folder from a UCloud workspace. If the folder is empty, a new database will be initialized. In this case, after the initialization procedure is completed, the following lines will be displayed in the output logs:

[Entrypoint] GENERATED ROOT PASSWORD: <root_temporary_password>

[Entrypoint]: Stopping temporary server
[Entrypoint]: Temporary server stopped

[Entrypoint] MySQL init process done. Ready for start up.

where <root_temporary_password> is a random alphanumeric string which must be used to log in to the database for the first time. In order to change the password, the user should open the app terminal interface and access the database with the command:

$ mysql -u root -p

Tip

Enter password:

The login administrator password <root_temporary_password> must be copied from the output logs and pasted in the terminal. Once inside the MySQL console, a new password should be created with the command:

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword';

Tip

Query OK, 0 rows affected (0.20 sec)

This password will be used to access the database next time the server is deployed.

Note

A custom root password can also be assigned before submitting the job using the parameter Admin password. In this case it is not necessary to reset the password after the first log in.

Connect to the server

As discussed above, the user can access the MySQL console directly from the app terminal interface. However, it is also possible to connect to the server using an external client application. In this case, one has to grant remote access to the database user, e.g., using the following commands from the MySQL console:

mysql> UPDATE mysql.user SET host='%' WHERE user='root';

Tip

Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0

and

mysql> FLUSH PRIVILEGES;

Tip

Query OK, 0 rows affected (0.36 sec)

In this example the database user coincides with the server administrator. Connections from any external host are allowed. In order to restrict access to the server from only one specific host, it is necessary to replace the % in the command above with the corresponding host IP address.

On the one hand, if the client application runs within another interactive app available on UCloud, one can connect directly to the MySQL server, as outlined here. In this case the server hostname is configured as an external parameter via the option Connect to other jobs.

On the other hand, if the MySQL client is a third-party application, which is not deployed on UCloud, it is necessary to assign a static IP address to the server, using the corresponding option Public IP.

Note

By default remote access to the MySQL server is established over the TCP port 3306. The same port should be open on the network firewall of the public IP address.

Use option files

A customized server configuration can be specified using the parameter Option file. An example is shown below:

[client]
port=3306

[mysqld]
port=3306
key_buffer_size=16M
max_allowed_packet=128M
bind-address=0.0.0.0

[mysqld-8.0]
sql_mode=TRADITIONAL

To check the global configuration variables from the MySQL console, use the commands:

mysql> SELECT @@GLOBAL.innodb_data_file_path;

Tip

+--------------------------------+
| @@GLOBAL.innodb_data_file_path |
+--------------------------------+
| ibdata1:12M:autoextend         |
+--------------------------------+
1 row in set (0.00 sec)

and

mysql> SHOW VARIABLES;

For more information about option files, check the official documentation.