Linux

DatabaseLinux

Back Up & Restore A MySQL Database

Back Up & Restore A MySQL Database

Back Up & Restore A MySQL Database | It is very essential to make regular backups of all data to prevent data loss. Has your MySQL database has been lost, and you’re scrambling to restore a copy from your last backup? Read these step below carefully to Back Up & Restore A MySQL Database using mysqldump & phpMyAdmin.

Back Up MySQL Database Using mysqldump

The mysqldump client utility can dump a database including the SQL statements required to rebuild the database.

By default, the dump file includes the SQL commands to restore the tables and data.

Here is the syntax of mysqldump to backup MySQL Database

sudo mysqldump -u [user] -p [database_name] > [filename].sql

Note:

  • Replace [user] with your username and password (if needed).
  • The [database_name] is the path and filename of the database.
  • The command specifies the output.
  • [filename] is the path and filename you want to save the dump file as.

Example

Backup of an entire Database Management System:

mysqldump --all-databases --single-transaction --quick --lock-tables=false > full-backup-$(date +%F).sql -u root -p

You include more than one database in the backup dump file:

sudo mysqldump -u [user] -p [database_1] [database_2] [database_etc] > [filename].sql

Restore MySQL Using mysqldump

Step 1: Create New Database

On the system that hosts the database, use MySQL to create a new database.

Make sure you’ve named it the same as the database you lost. This creates the foundation file that mysqldump will import the data into. Since the dump file has the commands to rebuild the database, you only need to create the empty database.

Step 2: Restore MySQL Dump

To restore a MySQL backup:

mysql -u [user] -p [database_name] < [filename].sql

Note:

Make sure to include [database_name] and [filename] in the path.

It’s likely that on the host machine, [database_name] can be in a root directory, so you may not need to add the path. Make sure that you specify the exact path for the dump file you’re restoring, including server name (if needed).

How to Install Percona 8 in CentOS 7

Back Up & Restore A MySQL Database Using phpMyAdmin

Step 1: Create a MySQL Database Backup

1. Open phpMyAdmin. On the directory tree on the left, click the database you want to back up.

This should open the directory structure in the right-hand window. You’ll also notice that, in the directory tree on the left, all the assets under the main database are highlighted.

2. Click Export on the menu across the top of the display.

You’ll see a section called “Export Method.” Use Quick to save a copy of the whole database. Choose Custom to select individual tables or other special options.

Leave the Format field set to SQL, unless you have a good reason to change it.

3. Click Go. If you select Quick, your web browser will download a copy of the database into your specified downloads folder. You can copy that to a safe location.

Step 2: Clear the Old Database Information

It’s important to clear out old data before restoring a backup. If there’s any old data, it isn’t overwritten when you restore. This can create duplicate tables, causing errors and conflicts.

1. Open phpMyAdmin, on the navigation pane on the left, choose the database you want to restore.

2. Click the check all box near the bottom. Then, use the drop-down menu labeled With selected to select Drop.

3. The tool should prompt you to confirm that you want to go forward. Click yes.

This will get rid of all the existing data, clearing the way for your restoration.

Install MariaDB 10.4 on CentOS 7 : Easy Steps

Step 3: Restore Your Backed up MySQL Database

In phpMyAdmin, the Import tool is used to restore a database.

1. On the menu across the top, click Import.

2. The first section is labeled File to import. A couple of lines down, there’s a line that starts with “Browse your computer,” with a button labeled Choose File. Click that button.

3. Use the dialog box to navigate to the location where you’ve saved the export file that you want to restore. Leave all the options set to default. (If you created your backup with different options, you can select those here.)

4. Click Go.

read more
CentosLinux

Configure FirewallD for Mail Server in Centos 7

Configure FirewallD for Mail Server

Configure FirewallD for Mail Server in Centos 7A mail server (or email server) is a computer system that sends and receives email. In many cases, web servers and mail servers are combined in a single machine. However, large ISPs and public email services (such as Gmail and Hotmail) may use dedicated hardware for sending and receiving email. In order for a computer system to function as a mail server, it must include mail server software. This software allows the system administrator to create and manage email accounts for any domains hosted on the server

Configure FirewallD for Mail Server

Check if firewalld is installed:

# which firewalld
/usr/bin/which: no firewalld in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

If not installed, install firewalld:

# yum install firewalld

Ensure that firewalld is running:

# systemctl start firewalld

List allowed services:

# firewall-cmd --list-service
dhcpv6-client ssh

How to Install Percona 8 in CentOS 7

Add required services: HTTPS, SMTP, IMAP, POP3, DAV, DHCP(May be required in a testing environment).

# firewall-cmd --zone=public --add-service=smtp --add-service=smtps --add-service=imap --add-service=imaps --add-service=pop3 --add-service=pop3s --add-service=https --add-service=dhcp --permanent
# firewall-cmd --zone=public --add-port=587/tcp --add-port=8443/tcp --permanent

Reload firewalld

# firewall-cmd --reload

List allowed services and ports. Check for previously added additions firewalld list rules

# firewall-cmd --list-all | grep 'services\|ports' | head -n 2
services: dhcpv6-client https imap imaps pop3 pop3s smtp smtps ssh
ports: 8443/tcp 587/tcp

Enable DNS over HTTPS (DoH) on Mikrotik

read more
Linux

Vim Keyboard Shortcut (or Vi) You Should Memorize

vim

Vim Keyboard Shortcut – The Vim editor is a command-line based tool that’s an enhanced version of the venerable vi editor. Despite the abundance of graphical rich text editors, familiarity with Vim will help every Linux user – from an experienced system administrator to a newbie Raspberry Pi user.

One important thing to note when using Vim, is that the function of a key depends on the “mode” the editor is in. For example, pressing the alphabet “j” will move the cursor down one line in the “command mode”. You’ll have to switch to the “insert mode” to make the keys input the character they represent.

Shortcut KeysFunction
Main
Escape keyGets out of the current mode into the “command mode”. All keys are bound of commands.
i“Insert mode” for inserting text. Keys behave as expected.
:“Last-line mode” where Vim expects you to enter a command such as to save the document.
Navigation keys
hmoves the cursor one character to the left.
j or Ctrl + Jmoves the cursor down one line.
k or Ctrl + Pmoves the cursor up one line.
lmoves the cursor one character to the right.
0moves the cursor to the beginning of the line.
$moves the cursor to the end of the line.
^moves the cursor to the first non-empty character of the line
wmove forward one word (next alphanumeric word)
Wmove forward one word (delimited by a white space)
5wmove forward five words
bmove backward one word (previous alphanumeric word)
Bmove backward one word (delimited by a white space)
5bmove backward five words
Gmove to the end of the file
ggmove to the beginning of the file.
Navigate around the document
(jumps to the previous sentence
)jumps to the next sentence
{jumps to the previous paragraph
}jumps to the next paragraph
[[jumps to the previous section
]]jumps to the next section
[]jump to the end of the previous section
][jump to the end of the next section
Insert text
aInsert text after the cursor
AInsert text at the end of the line
iInsert text before the cursor
oBegin a new line below the cursor
OBegin a new line above the cursor
Special inserts
:r [filename]Insert the file [filename] below the cursor
:r ![command]Execute [command] and insert its output below the cursor
Delete text
xdelete character at cursor
dwdelete a word.
d0delete to the beginning of a line.
d$delete to the end of a line.
d)delete to the end of sentence.
dggdelete to the beginning of the file.
dGdelete to the end of the file.
dddelete line
3dddelete three lines
Simple replace text
r{text}Replace the character under the cursor with {text}
RReplace characters instead of inserting them
Copy/Paste text
yycopy current line into storage buffer
[“x]yyCopy the current lines into register x
ppaste storage buffer after current line
Ppaste storage buffer before current line
[“x]ppaste from register x after current line
[“x]Ppaste from register x before current line
Undo/Redo operation
uundo the last operation.
Ctrl+rredo the last undo.
Search and Replace keys
/search_textsearch document for search_text going forward
?search_textsearch document for search_text going backward
nmove to the next instance of the result from the search
Nmove to the previous instance of the result
:%s/original/replacementSearch for the first occurrence of the string “original” and replace it with “replacement”
:%s/original/replacement/gSearch and replace all occurrences of the string “original” with “replacement”
:%s/original/replacement/gcSearch for all occurrences of the string “original” but ask for confirmation before replacing them with “replacement”
Bookmarks
m {a-z A-Z}Set bookmark {a-z A-Z} at the current cursor position
:marksList all bookmarks
`{a-z A-Z}Jumps to the bookmark {a-z A-Z}
Select text
vEnter visual mode per character
VEnter visual mode per line
EscExit visual mode
Modify selected text
~Switch case
ddelete a word.
cchange
yyank
>shift right
<shift left
!filter through an external command
Save and quit
:qQuits Vim but fails when file has been changed
:wSave the file
:w new_nameSave the file with the new_name filename
:wqSave the file and quit Vim.
:q!Quit Vim without saving the changes to the file.
ZZWrite file, if modified, and quit Vim
ZQSame as :q! Quits Vim without writing changes

That’s the shortcut you can learn on Vim. So Let’s memorize all the Vim Keyboard Shortcut !!

read more
CentosLinux

Semanage : Command Not Found in CentOS 7

semanage

Semanage is an SELinux (Security-Enhanced Linux) management tool that is used to configure specific elements without making any adjustments to or reassembling from policy sources. If you found semanage error (command not found), here’s how to overcome it.

Enter the following package that will provide this command

 yum provides /usr/sbin/semanage

or

yum whatprovides /usr/sbin/semanage

Install the policycoreutils-phyton by typing the following command

yum install policycoreutils-python

That’s it, how to fix semanage command not found in CentOS 7

read more
CentosLinux

Install Nextcloud on CentOS 7 + Setting Let’s Encrypt SSL

nextcloud

Install Nextcloud on CentOS 7 – This guide will walk you through the installation of Nextcloud on CentOS 7 with PHP 7.3, Apache and MariaDB 10.4. You can optionally configure SSL encryption with Let’s Encrypt to ensure that access and data is being transferred through a secure tunnel. Nextcloud is an open-source seft-hosted syncing and file sharing server forked from ownCloud. It is written in PHP and JavaScript and has support for MySQL, PostgreSQL, SQLite and Oracle Database.

Install Nextcloud on CentOS 7 + Setting Let’s Encrypt SSL

Disable SELinux or Put in in Permissive mode

Disabling SELinux for smooth operations:

sudo setenforce 0
sudo sed -i 's/^SELINUX=.*/SELINUX=permissive/g' /etc/selinux/config

Install PHP and httpd

sudo yum -y install epel-release yum-utils
sudo yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

Disable default PHP 5.x enabled repository and enable one for PHP 7.3:

sudo yum-config-manager --disable remi-php54
sudo yum-config-manager --enable remi-php73

Install and Configure MariaDB / MySQL

Install MariaDB / MySQL database server on CentOS 7 using our previous guides. Choose one, recommended is MariaDB.

Read this : Install MariaDB 10.4 on CentOS 7 : Easy Steps

After the installation, login as a root user to MySQL console and create a new database for Nextcloud.

$ mysql -u root -p
CREATE USER 'nextcloud'@'localhost' IDENTIFIED BY "StrongPassword";
CREATE DATABASE nextcloud;
GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextcloud'@'localhost';
FLUSH PRIVILEGES;
QUIT

Download and Install Nextcloud on CentOS 7

sudo yum -y install wget unzip
wget https://download.nextcloud.com/server/releases/latest.zip

Unzip the downloaded file & remove source file:

unzip latest.zip
rm -f latest.zip

Move the resulting nextcloud folder to /var/www/html directory

sudo mv nextcloud/ /var/www/html/

Create data directory to store Nextcloud uploaded files. This can be any path e.g NFS mount point, SAN mount point e.t.c.

sudo mkdir /var/www/html/nextcloud/data
sudo chown apache:apache -R /var/www/html/nextcloud/data

Give apache user and group the ownership of nextcloud folder.

sudo chown apache:apache -R /var/www/html/nextcloud

Configure Apache VirtualHost – Without SSL

Create an Apache configuration file for Nextcloud

sudo vim /etc/httpd/conf.d/nextcloud.conf

Paste code below to file

<VirtualHost *:80>
  ServerName files.example.com
  ServerAdmin admin@example.com
  DocumentRoot /var/www/html/nextcloud
  <directory /var/www/html/nextcloud>
    Require all granted
    AllowOverride All
    Options FollowSymLinks MultiViews
    SetEnv HOME /var/www/html/nextcloud
    SetEnv HTTP_HOME /var/www/html/nextcloud
  </directory>
</VirtualHost>

Set correct ServerName and change other settings to suit your use.

When done, save the file and start httpd service.

sudo systemctl enable --now httpd
sudo semanage fcontext -a -t httpd_sys_content_t "/var/www/html(/.*)?"
sudo sudo restorecon -Rv /var/www/html

If you have an active firewalld service, allow http and https ports.

sudo firewall-cmd --add-service={http,https} --permanent
sudo firewall-cmd --reload

Configure Apache With Let’s Encrypt SSL

To use Let’s Encrypt SSL certificate, first install certbot

wget https://dl.eff.org/certbot-auto
chmod a+x certbot-auto
sudo mv certbot-auto /usr/local/bin

Then request for SSL certificate.

export DOMAIN="files.example.com"
export EMAIL="admin@example.com"
certbot-auto certonly --standalone -d $DOMAIN --preferred-challenges http --agree-tos -n -m $EMAIL --keep-until-expiring

Don’t forget to change domain name & email above with yours

Modify your VirtualHost configuration file to look like below.

<VirtualHost *:80>
   ServerName files.example.com
   ServerAdmin admin@example.com
   RewriteEngine On
   RewriteCond %{HTTPS} off
   RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]
</VirtualHost>

<IfModule mod_ssl.c>
   <VirtualHost *:443>
     ServerName files.example.com
     ServerAdmin admin@example.com
     DocumentRoot /var/www/html/nextcloud
     <directory /var/www/html/nextcloud>
        Require all granted
        AllowOverride All
        Options FollowSymLinks MultiViews
        SetEnv HOME /var/www/html/nextcloud
        SetEnv HTTP_HOME /var/www/html/nextcloud
    </directory>
     SSLEngine on
     SSLCertificateFile /etc/letsencrypt/live/files.example.com/fullchain.pem
     SSLCertificateKeyFile /etc/letsencrypt/live/files.example.com/privkey.pem
   </VirtualHost>
</IfModule>

Access Nextcloud UI and finish installation

Open your nextcloud server URL as configured on Apache: http://files.example.com

Setup admin password

Setup Database, don’t forget to using MariaDB and set credentials

When done click the “Finish Setup” button. You should get the Files dashboard of Nextcloud. Now install Nextcloud Agent on your end device to start syncing files.

Thanks for using our guide to install Nextcloud on CentOS 7.

read more
CentosLinux

Install MariaDB 10.4 on CentOS 7 : Easy Steps

mariadb

Install MariaDB 10.4 on CentOS 7 – In this page, we will guide you how to setup MariaDB 10.4 on CentOS 7. As of this writing, the latest stable release of MariaDB is 10.4.  The default version of MariaDB installed on CentOS 7 is 5.5. This versions are available on OS upstream repositories.

Note that before you can setup MariaDB 10.4, you may need to uninstall the current version of MariaDB server. You can ignore this if upgrading.  On Ubuntu, run:

sudo yum remove mariadb-server

Add MariaDB YUM repository to CentOS 7 server:

cat <<EOF | sudo tee /etc/yum.repos.d/MariaDB.repo
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.4/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
EOF

Clean yum cache index:

sudo yum makecache fast

Install MariaDB 10.4 on CentOS 7:

sudo yum -y install MariaDB-server MariaDB-client

Start and enable MariaDB service:

sudo systemctl enable --now mariadb

Secure MariaDB by running mysql_secure_installation

sudo mysql_secure_installation 

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

Log in and check MariaDB version:

# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 16
Server version: 10.4.6-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> select version();
+----------------+
| version()      |
+----------------+
| 10.4.6-MariaDB |
+----------------+
1 row in set (0.000 sec)

Or, You can also check version using:

# mysql -V

 

Those are steps how to Install MariaDB 10.4 on CentOS 7

IF you have any question, please write down below in comments

read more
CentosLinux

How to Install Percona 8 in CentOS 7

How to Install Percona 8 in Centos 7 – Percona Server for MySQL® is a free, fully compatible, enhanced and open source drop-in replacement for any MySQL database. It provides superior performance, scalability and instrumentation.

Percona Server for MySQL is trusted by thousands of enterprises to provide better performance and concurrency for their most demanding workloads, and delivers greater value to MySQL server users with optimized performance, greater performance scalability and availability, enhanced backups and increased visibility.

So essentially, yes. It is MySQL with some (very interesting) tweaks. You should use it when it solves a particular problem that you’re having. The list of differences are available at the product documentation page (linked above), but here’s a short list of what I believe are among the most compelling features:

– Improved Buffer Pool Scalability
– HandlerSocket included by default
– InnoDB Data Dictionary Size Limit
– Dynamic Row Format Memory Tables
– Extra slow query log statistics and configuration options

Follow these steps to Install Percona 8 in CentOS 7

 

yum install https://repo.percona.com/yum/percona-release-latest.noarch.rpm

Enable percona server 8.0 repo

percona-release setup ps80

Install percona server

sudo yum install percona-server-server

Start mysql Server

service mysql start

Find the temporary password and login to mysql

sudo grep "temporary password" /var/log/mysqld.log

Run mysql_secure_installation

/usr/bin/mysql_secure_installation

Change the password, answer “yes” every question

Those are the article How to Install Percona 8 in CentOS 7, Keep going..

read more
CentosLinux

How to Set Nano as Default Editor on CentOS 7

How to Set Default Editor to Nano on CentOS 7 – Not everyone is familiar with the “vim” text editor. Its many shortcuts are also not easy to memorize. One of the most commonly used text editors is nano, but in the CentOS 7 standard installation, nano is not yet a standard text editor. Therefore, follow the steps below to make nano as a standard text editor, so that it will be easier for us to do editing, for example, to edit crontab

Install nano

Execute command below to install nano

yum -y install nano

Disable Word Wrap

Nano by default enables word wrap. While nice in a normal document, this is generally undesirable in a configuration file

echo "set nowrap" >>/etc/nanorc

Set System Default Editor

During login, a number of scripts are run to setup the environment. In CentOS, a file for each subject is used. These are stored in a system profile directory, /etc/profile.d/. There are two environment variables that control which editor to use.

cat <>/etc/profile.d/nano.sh
export VISUAL="nano"
export EDITOR="nano"
EOF

Set Per User Default

If a user wishes to set the default editor for themselves, it can be, instead, be done in the user’s bash profile.

cat <>~/.bash_profile
export VISUAL="nano"
export EDITOR="nano"
EOF

Try

Try by opening crontab. execute commnad below

crontab -e

If it opened in nano, so, those steps is right..Try to logout and then login again if still fail

Thats is steps to Set Nano as Default Editor on CentOS 7, if you want to install Percona on Centos 7, please follow this link

read more
Continue in browser
To install tap Add to Home Screen
Add to Home Screen
To install tap
and choose
Add to Home Screen
Continue in browser
To install tap
and choose
Add to Home Screen
Continue in browser
Continue in browser
To install tap
and choose
Add to Home Screen
We would like to show you notifications for the latest news and updates.
Dismiss
Allow Notifications