Using MySQL

From ULYSSIS documentation
Revision as of 19:04, 16 December 2020 by Pcy (talk | contribs) (fix wording and punctuation a little bit)

MySQL is one of the most popular databases for websites. It's used by most CMSes and other common web software, and many programming languages have support for it. ULYSSIS specifically uses MariaDB, which is a fork of MySQL with similar features and (almost) identical SQL syntax, but offers better performance and has less corporate interference in the development process.

Managing MySQL

All common management tasks can be performed through our control panel UCC, under the MySQL section.

Creating a MySQL user

To use MySQL on your ULYSSIS account, you first need to create a MySQL user on UCC. In the MySQL section of the panel, you will be suggested to click a link to create a user. Then fill in a password for the database user. It is highly recommended that this password differs from the password you use for your account. Finally, click Create user and you are ready to go.

Creating a MySQL database

After having created a MySQL user, you can click Add database in UCC and enter the name for your new database. It will automatically be prefixed by your username.

Deleting a MySQL database

If you no longer need a database, you can easily remove it by clicking on MySQL in UCC and then pressing on Remove database next to the database you would like to delete. After confirming, the database and all its tables and other contents will be gone. For security reasons, you can't remove databases using an SQL query like DROP DATABASE, but have to go through UCC.

Accessing MySQL

Our MySQL and PostgreSQL databases run on a separate database server, this means you may need to enter a specific host, together with the correct credentials, to access your database within a website or application. You may also wish to use a common tool such as PHPMyAdmin or access a database remotely. Details on how to do that are available in the sections below.

Using MySQL for your website or application

Host: mysql.ulyssis.org
Username: your account's username
Password: the password you chose when you made the MySQL user
Database: the database name you chose, prefixed by your username

For example, if my username is foobar, I made a database called website and I were to create a PHP website I would use something like:

$db = new mysqli('mysql.ulyssis.org', 'foobar', 'correct horse battery staple', 'foobar_website');

or

$db = new PDO('mysql:host=mysql.ulyssis.org;dbname=foobar_website', 'foobar', 'correct horse battery staple');

Accessing MySQL with PHPMyAdmin or Adminer

Using your username and password you can easily manage your MySQL databases, tables and records on https://phpmyadmin.ulyssis.org and https://adminer.ulyssis.org. Documentation is also available to aid in using PHPMyAdmin and using Adminer.

Accessing MySQL from outside of our network

To prevent unnecessary load on our database server by hackers and bots it is only available inside of our network. If you wish to access it externally the easiest way is to use an SSH tunnel. In many MySQL management tools this is already supported.

MySQL Workbench

While MySQL Workbench might not fully support our MySQL database, all commonly used operations work perfectly. You can connect to our database using MySQL Workbench by creating a connection as follows ([username] should be replaced by your username, of course): MySQL Workbench SSH.png

Linux, Mac OSX

On Linux, Mac OSX and other Unix-like Operating Systems it is also easily possible to use the following command to create a tunnel to a local port (in this case 3300)

ssh username@ssh2.ulyssis.org -L 3300:mysql.ulyssis.org:3306 -N

While this command is running, you can connect to the MySQL server with host 'localhost' and port '3300'. To terminate the port forwarding, press ctrl-C in the terminal.

You can use "ssh -f username@ssh2.ulyssis.org -L 3300:mysql.ulyssis.org:3306 -N": the f-argument will put the command in the background.