# Set Up a MySQL Database

This section describes how to set up a training database using MySQL. The database can be on a Windows or Linux machine and can be on a different machine to your Media Server.

To set up a MySQL database

1. Download and install a MySQL server. Ensure that the package includes the `mysql` command-line tool. During installation, set up a user account with superuser privileges. The MySQL server is typically installed to run as a service. For detailed instructions, refer to the MySQL documentation.

2. Configure the database server for use with Media Server:

   1. Open the configuration file for the MySQL server in a text editor. This file is usually `my.ini` on Windows, or `/etc/my.cnf` on Linux.
   2. So that Media Server can send large amounts of binary data (such as images) to the database, set the configuration parameter `max_allowed_packet=1073741824`.
   3. Save and close the configuration file.

3. (Windows only) Add the MySQL `bin` directory to your `PATH` environment variable. This step enables you to use the command `mysql` to start the `mysql` command-line tool from the Windows Command Prompt. If you do not add the directory to the `PATH` environment variable, you must specify the full path of the tool. This step is usually not required on Linux because the tool is installed to a directory such as `/usr/bin`, which is already in the `PATH`.

4. Create a new database to store Media Server training data.

   1. Open a command-prompt or terminal and start the `mysql` command line tool:

          mysql -u user -p

      where `user` is your MySQL user name.

   2. Enter your password when prompted.

   3. Run a `CREATE DATABASE` command to create a new database. Specify the following database settings.

      Database name | Any name.
      Character set | Must be Unicode–either UTF8 or UCS2.
      Collation | Any that is compatible with the encoding.

      For example:

          CREATE DATABASE MediaTraining CHARACTER SET utf8 COLLATE utf8_unicode_ci;

   4. Close the `mysql` command-line tool:

          quit

5. Set up the database schema that Media Server requires. To do this, run the `my.sql` script provided in the `sql` folder of the Media Server installation directory.

   1. Change directory to the `sql` folder of the Media Server installation directory (for example, `C:\MediaServer\sql` on Windows or `/opt/MediaServer/sql` on Linux). This is important because the `my.sql` script refers to other files in the same directory.

   2. Run the `my.sql` script. Running the script non-interactively from the terminal ensures that the script terminates if an error occurs. For example:

          mysql -u user -p -v -D MediaTraining < my.sql

      where `user` is your MySQL user name, and `MediaTraining` is the name of the database you created.

6. Create a user for Media Server to use and grant the following privileges to that user:

   Grant... | On...
   --- | ---
   Create Temporary Tables | Database
   Select, Insert, Update, Delete | All tables
   Execute | All functions and stored procedures

   1. Start the `mysql` command-line tool:

          mysql -u user -p

   2. Create a new user:

          CREATE USER 'MediaServer' IDENTIFIED BY 'password';

      where `MediaServer` is the name of the new user, and `password` is the password for the new user.

   3. Grant the necessary privileges to the new user:

          GRANT CREATE TEMPORARY TABLES ON MediaTraining.* TO 'MediaServer';
          GRANT SELECT, INSERT, UPDATE, DELETE ON MediaTraining.* TO 'MediaServer';
          GRANT EXECUTE ON MediaTraining.* TO 'MediaServer';

      where `MediaTraining` is the name of the database you created and `MediaServer` is the name of the user you created for Media Server.

   4. Close the `mysql` command-line tool:

          quit

7. You can now set up a data source name (DSN) so that Media Server can connect to the database. If you are running Media Server on Windows, see Create a MySQL DSN on Windows. If you are running Media Server on Linux, see Create a MySQL DSN on Linux.

_FT_HTML5_bannerTitle.htm