Using MySQL: Difference between revisions
No edit summary |
(remove SQL workbench) |
||
(6 intermediate revisions by 3 users not shown) | |||
Line 2: | Line 2: | ||
== Managing MySQL == | == Managing MySQL == | ||
All common management tasks can be performed through our control panel [https://ucc.ulyssis.org UCC], under the MySQL section. | |||
===Creating a MySQL user=== | ===Creating a MySQL user=== | ||
To use MySQL on your ULYSSIS account you first need to create a MySQL user on [https://ucc.ulyssis.org 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. | To use MySQL on your ULYSSIS account, you first need to create a MySQL user on [https://ucc.ulyssis.org 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=== | ===Creating a MySQL database=== | ||
After | After having created a MySQL user, you can click ''Add database'' in [https://ucc.ulyssis.org UCC] and enter the name for your new database. It will automatically be prefixed by your username. | ||
===Deleting a MySQL database=== | ===Deleting a MySQL database=== | ||
Line 12: | Line 14: | ||
== Accessing MySQL == | == 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=== | ===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 25: | Line 29: | ||
===Accessing MySQL with PHPMyAdmin or Adminer=== | ===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]] | 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=== | ===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 | 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 41: | Line 40: | ||
To terminate the port forwarding, press ctrl-C in the terminal. | To terminate the port forwarding, press ctrl-C in the terminal. | ||
If you prefer the command to be run in the background, you can add <code>-f</code> to your command. To close this background process, you can use pgrep to acquire the pid of the process: | |||
pgrep --list-full ssh | grep mysql.ulyssis.org | |||
12657 ssh -f username@ssh2.ulyssis.org -L 5400:mysql.ulyssis.org:5432 -N | |||
We can then kill the process using kill with the pid we acquired: | |||
kill 12657 | |||
[[Category:Databases]] | [[Category:Databases]] |
Latest revision as of 14:28, 1 October 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.
If you prefer the command to be run in the background, you can add -f
to your command. To close this background process, you can use pgrep to acquire the pid of the process:
pgrep --list-full ssh | grep mysql.ulyssis.org 12657 ssh -f username@ssh2.ulyssis.org -L 5400:mysql.ulyssis.org:5432 -N
We can then kill the process using kill with the pid we acquired:
kill 12657