Using MySQL: Difference between revisions
(fix wording and punctuation a little bit) |
(Accessing MySQL aangepast zoals uitgelegd in wikipagina documentatie herschrijven, nog wat meer nodig bij ssh) |
||
Line 17: | Line 17: | ||
===Using MySQL for your website or application=== | ===Using MySQL for your website or application=== | ||
you can connect to the database with the following details: | |||
Host: mysql.ulyssis.org | Host: mysql.ulyssis.org | ||
Username: your account's username | Username: your account's username | ||
Line 33: | Line 34: | ||
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. | 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. | ||
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) | |||
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 | ssh username@ssh2.ulyssis.org -L 3300:mysql.ulyssis.org:3306 -N | ||
Line 45: | Line 41: | ||
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. | 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. | ||
==== MySQL Workbench ==== | |||
While [https://www.mysql.com/products/workbench/ 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): | |||
[[File:MySQL_Workbench_SSH.png]] | |||
[[Category:Databases]] | [[Category:Databases]] |
Revision as of 15:31, 29 September 2022
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
you can connect to the database with the following details:
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.
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.
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):