How to create a MySQL database and user (WHS panel and cPanel)

Sajt na WordPressu, prodavnica ili bilo koja aplikacija čuva svoje podatke u bazi. Da bi aplikacija mogla da koristi bazu, trebaju ti tri stvari: baza, korisnik baze sa lozinkom i veza između njih (dozvole). Postupak je drugačiji u WHS panelu i u cPanelu, zato ispod izaberi svoj panel.

Šta treba da znaš pre nego što počneš

  • Korisnik baze nije tvoj hosting nalog. To je poseban nalog sa svojom lozinkom, samo za aplikaciju. Najbolje je jedan korisnik po sajtu.
  • Ime dobija prefiks naloga. Ako ti je nalog mojnalog i upišeš bazu wpsajt, puno ime je mojnalog_wpsajt. Isto važi za korisnika. U podešavanja sajta uvek upisuješ puno ime.
  • Host je localhost. Sajt na istom hostingu se na bazu povezuje preko adrese localhost.

First log in to your panel

Log in client panel, for hosting click Edit, so AutoLogin Panel. In detail: Reset Password Panel or AutoLogin Panel.

What panel are you using? Click and go directly to your instruction.

Don't know which one you have? The WHS panel has a menu on the left (Control Panel, Domains, Email...). cPanel on the home page has icons arranged by groups (Email, Files, Databases, Domains) and the inscription cPanel at the bottom of the page.

WHS panel

MySQL baza u WHS panelu

WHS panel koristi MariaDB, potpunu zamenu za MySQL. WordPress i ostale aplikacije rade sa njom bez ikakvih izmena.

MySQL databases store the structured data of your applications (WordPress, Magento, stores, custom applications). In this part of the panel, you create databases, database users and manage their permissions. Database and user names are automatically prefixed with your account name (for example whsuser_) so that there are no collisions with other users on the server.

1. Overview

Open in the menu Databases well MySQL databases. There are three tabs at the top: Databases (how many do you have), Total size and Database users. Below are two tables: a list of databases (each with its own actions) and a list of users.

2. The easiest way: Base wizard

Click Database Wizard to create a database, a user and assign privileges at once in four steps (Database, User, Privileges, Done).

3. Handcrafted

  • Create database: enter the name (only letters, numbers and underscores are allowed). The database appears in the table.
  • Create user: create a separate database user account with a password.

4. Actions on the database

At each base in the table there are buttons:

ActionWhat does it do?
ExportDownloads the entire database as .sql file, for backup or migration to another server.
Remote accessControls which external IP addresses are allowed to connect to the base from outside the server (for connecting from another server or from a desktop tool).
PrivilegesIt determines which users have access to the database and which operations they are allowed (explained below).
phpMyAdminOpens phpMyAdmin, a web tool for viewing and editing tables and running SQL queries directly in the browser.
DeletePermanently deletes the base. Before deleting it, you must export it.

5. Granting privileges

By clicking on Privileges a list of users who have access to that database opens. With a button Grant privileges you connect the user to the database and choose which operations he is allowed to perform (SELECT, INSERT, UPDATE, DELETE and others). For a typical application, grant its user all privileges over its base.

6. Database users

Database users are separate login accounts that your applications use to connect to MySQL. They are not the same as your hosting account. Each user has buttons:

  • Password: changes the user's password (if leaked or needs to be rotated).
  • Delete: removes the user.

It is recommended that you create one user per application and grant him access only to the databases he needs.

7. How to connect WordPress or another application

  • Database name: full name with a prefix (eg whsuser_mysite).
  • Database user: the user you created (same with the prefix), to whom you assigned privileges over that database.
  • Password: that user's password.
  • Host: localhost (the database is on the same server as the site).

Note: always use full database and user name with account prefix; without a prefix the connection does not work. Do not forget to the user grant privileges over the database, otherwise the application cannot access it.

Security: create a separate user per application with only necessary privileges and regularly export the database as a backup.

cPanel

MySQL baza u cPanelu

On the home page of cPanel, in the group Bases, su dve opcije za ovo. Database Wizard te vodi korak po korak. Manage My Databases ima sve na jednoj strani i njega opisujemo ovde.

1. Kreiraj bazu

In the work Kreiraj novu bazu, in the field Nova baza upiši naziv, na primer wpsajt. Prefiks naloga je već ispred polja. Klikni Kreiraj bazu.

2. Kreiraj korisnika

Spusti se do dela Dodaj novog korisnika. Upiši Username, pa lozinku u Password and Ponovi lozinku. cPanel traži jaku lozinku (jačina najmanje 65 od 100), a najlakše je da klikneš Password generator. Zapiši lozinku, trebaće ti za sajt. Klikni Kreiraj korisnika.

3. Poveži korisnika sa bazom

In the work Dodaj korisnika bazi izaberi svog korisnika u polju Korisnik i bazu u polju Bases, then click Dodaj.

Otvara se strana Uredi dozvole korisnika. Štikliraj SVE DOZVOLE (sve kvačice ispod se same uključe) i na dnu klikni Napravi Izmene.

Gotovo. U tabeli Trenutne baze, u koloni Ovlašćeni korisnici, sada vidiš korisnika uz bazu. Klik na njegovo ime ponovo otvara dozvole.

Za uvoz i izvoz baze koristi phpMyAdmin iz iste grupe: uvoz baze and izvoz baze.

Podaci koje upisuješ u sajt

Za WordPress ovo ide u wp-config.php, a druge aplikacije imaju slična polja pri instalaciji:

PoljeŠta upisuješ
DB_NAMEpuno ime baze, sa prefiksom (mojnalog_wpsajt)
DB_USERpuno ime korisnika, sa prefiksom
DB_PASSWORDlozinka korisnika baze
DB_HOSTlocalhost

Ako sajt javi „Error establishing a database connection“, skoro uvek je jedno od ova četiri polja pogrešno, najčešće ime bez prefiksa ili korisnik koji nije povezan sa bazom.