linux:mariadb:mariadb-setup
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| linux:mariadb:mariadb-setup [2019/09/13 09:54] – external edit 127.0.0.1 | linux:mariadb:mariadb-setup [Unknown date] (current) – removed - external edit (Unknown date) 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ===== Install MariaDB ===== | ||
| - | To install MariaDB, run the command below; | ||
| - | # apt-get install mariadb-server mariadb-client | ||
| - | When installed, MariaDB is started and enabled to run on system boot. | ||
| - | # systemctl is-enabled mariadb | ||
| - | | ||
| - | # systemctl status mariadb | ||
| - | |||
| - | ● mariadb.service - MariaDB 10.3.15 database server | ||
| - | Loaded: loaded (/ | ||
| - | Active: active (running) since Thu 2019-07-18 15:31:35 EDT; 9min ago | ||
| - | Docs: man: | ||
| - | https:// | ||
| - | Main PID: 2356 (mysqld) | ||
| - | Status: " | ||
| - | | ||
| - | Memory: 76.4M | ||
| - | CGroup: / | ||
| - | └─2356 / | ||
| - | After installing MariaDB database server, the commands below can be used to stop, start and enable MariaDB service to always start up when the server boots. | ||
| - | # systemctl stop mariadb.service | ||
| - | # systemctl start mariadb.service | ||
| - | # systemctl enable mariadb.service | ||
| - | ==== Database location ==== | ||
| - | Database is located at: | ||
| - | # cd / | ||
| - | |||
| - | ==== Check location used config file ==== | ||
| - | The location of the used config file can be found by: | ||
| - | / | ||
| - | |||
| - | ==== MariaDB initial Security ==== | ||
| - | By default, MariaDB uses unix_socket plugin for authentication and thus, it doesn’t require password to login. You can simply run mysql or mysql -u root to login to MariaDB server. | ||
| - | # mysql | ||
| - | |||
| - | | ||
| - | Your MariaDB connection id is 48 | ||
| - | | ||
| - | | ||
| - | Type ' | ||
| - | | ||
| - | |||
| - | You can now run the mysql_secure_installation script to remove MariaDB test databases, anonymous users and disallow remote root login. To run the script, just run the command below | ||
| - | # mysql_secure_installation | ||
| - | |||
| - | When prompted, answer the questions below by following the guide. | ||
| - | |||
| - | Enter current password for root (enter for none): Just press the Enter | ||
| - | * Set root password? [Y/n]: Y | ||
| - | * New password: Enter password | ||
| - | * Re-enter new password: Repeat password | ||
| - | * Remove anonymous users? [Y/n]: Y | ||
| - | * Disallow root login remotely? [Y/n]: Y | ||
| - | * Remove test database and access to it? [Y/ | ||
| - | * Reload privilege tables now? [Y/ | ||
| - | * Restart MariaDB server | ||
| - | |||
| - | To test if MariaDB is installed, type the commands below to logon to MariaDB server | ||
| - | |||
| - | # sudo mysql -u root -p | ||
| - | |||
| - | Then type the password you created above to sign on… if successful, you should see MariaDB welcome message | ||
| - | |||
| - | ==== Remote Access ==== | ||
| - | By default the remote access is disabled. In order to enable remote access make the following changes to the configuration file: | ||
| - | < | ||
| - | # nano / | ||
| - | |||
| - | Disabled the line: bind-address = 127.0.0.1. | ||
| - | # | ||
| - | |||
| - | #And add 2 new lines: | ||
| - | skip-networking=0 | ||
| - | skip-bind-address | ||
| - | </ | ||
| - | ===== Query Databases ===== | ||
| - | < | ||
| - | MariaDB [(none)]> | ||
| - | +--------------------+ | ||
| - | | Database | ||
| - | +--------------------+ | ||
| - | | information_schema | | ||
| - | | mysql | | ||
| - | | nextcloud | ||
| - | | performance_schema | | ||
| - | | sitedatabase | ||
| - | +--------------------+ | ||
| - | </ | ||
| - | ===== Query Users ===== | ||
| - | < | ||
| - | MariaDB [(none)]> | ||
| - | +-----------+----------+-------------------------------------------+ | ||
| - | | host | user | password | ||
| - | +-----------+----------+-------------------------------------------+ | ||
| - | | localhost | root | *AF926838A9A0501BA7017D135C123C007497F85B | | ||
| - | | localhost | www-data | *AF926838A9A0501BA7017D135C123C007497F85B | | ||
| - | | localhost | nc-user | ||
| - | +-----------+----------+-------------------------------------------+ | ||
| - | |||
| - | MariaDB [(none)]> | ||
| - | +----------+--------------+-----------+ | ||
| - | | User | Db | Host | | ||
| - | +----------+--------------+-----------+ | ||
| - | | nc-user | ||
| - | | www-data | sitedatabase | localhost | | ||
| - | +----------+--------------+-----------+ | ||
| - | </ | ||
| - | ===== Create Users ===== | ||
| - | < | ||
| - | CREATE USER ' | ||
| - | CREATE USER ' | ||
| - | </ | ||
| - | ===== Query Users Rights ===== | ||
| - | < | ||
| - | MariaDB [(none)]> | ||
| - | +------------------------------------------------------------------------------------------------+ | ||
| - | | Grants for root@localhost | ||
| - | +------------------------------------------------------------------------------------------------+ | ||
| - | | GRANT ALL PRIVILEGES ON *.* TO ' | ||
| - | | GRANT PROXY ON '' | ||
| - | +------------------------------------------------------------------------------------------------+ | ||
| - | |||
| - | MariaDB [(none)]> | ||
| - | +-----------------------------------------------------------------------------------------------------------------+ | ||
| - | | Grants for www-data@localhost | ||
| - | +-----------------------------------------------------------------------------------------------------------------+ | ||
| - | | GRANT USAGE ON *.* TO ' | ||
| - | | GRANT ALL PRIVILEGES ON `sitedatabase`.* TO ' | ||
| - | +-----------------------------------------------------------------------------------------------------------------+ | ||
| - | |||
| - | MariaDB [(none)]> | ||
| - | +----------------------------------------------------------------------------------------------------------------+ | ||
| - | | Grants for nc-user@localhost | ||
| - | +----------------------------------------------------------------------------------------------------------------+ | ||
| - | | GRANT USAGE ON *.* TO ' | ||
| - | | GRANT ALL PRIVILEGES ON `nextcloud`.* TO ' | ||
| - | +----------------------------------------------------------------------------------------------------------------+ | ||
| - | </ | ||
| - | ===== Grand Users Rights ===== | ||
| - | < | ||
| - | GRANT ALL PRIVILEGES ON `sitedatabase`.* TO ' | ||
| - | GRANT ALL PRIVILEGES ON `nextcloud`.* TO ' | ||
| - | </ | ||
| - | ===== Migrate Databases ===== | ||
| - | Dump the databases on the original server. Better extract them one-by-one so we don't migrate anything unnecessary. To dump as single databases, use the following commands: | ||
| - | # mysqldump -u root -p --all-databases > all_databases.sql | ||
| - | # mysqldump -u [user] -p --opt [database name] > database_name.sql | ||
| - | | ||
| - | # mysqldump -u root -p --opt sitedatabase > sitedatabase_dump.sql | ||
| - | # mysqldump -u root -p --opt nextcloud > nextcloud_dump.sql | ||
| - | |||
| - | Once the dump is completed, you are ready to transfer the databases. But databases need to be created first on target server. | ||
| - | # mysql -u root -p | ||
| - | CREATE DATABASE sitedatabase; | ||
| - | CREATE DATABASE nextcloud; | ||
| - | quit; | ||
| - | Retore the data to the newly creates databases: | ||
| - | # mysql -u [user] -p --all-databases < all_databases.sql | ||
| - | # mysql -u [user] -p newdatabase < DUMP-SITE-DATABASE.sql | ||
| - | | ||
| - | # mysql -u root -p sitedatabase < sitedatabase_dump.sql | ||
| - | # mysql -u root -p nextcloud < nextcloud_dump.sql | ||
linux/mariadb/mariadb-setup.1568368468.txt.gz · Last modified: (external edit)
