Mysql red hat linux

Install MySQL on Red Hat 7 Operating System

MySQL, the most popular and reliable open-source relational database management system, is no longer available with RHEL’s repositories. After releasing Red Hat 7, the default repositories of RHEL is supporting MariaDB as a default Relational database system. MariaDB is backwards compatible with MySQL, and it is the perfect replacement of MySQL.

In this article, we will learn how to install MySQL into Red Hat Enterprise Linux (RHEL) 7 Operating System.

Prerequisites

To start MySQL installation on RHEL 7, we need a system running with RHEL 7 operating system and a user to login into the system with sudo privileges as we need to run installation and configuration commands with sudo permission.

As I have already mentioned, MySQL is not coming with default centos default repositories, so we need to install the package using MySQL Yum Repository.

You should install any one version in your Red Hat machine, and If you have any doubt to choose a version of MySQL, I suggest you go through with your required application’s documentation and choose a compatible version of MySQL.

Install MySQL 8.0 on RHEL 7

You can follow the below process to install MySQL 8.0 into your RHEL 7 System:

Step 1 – Enable MySQL 8.0 repository

You can enable the MySQL 8.0 repository into your Red Hat system by using the following command:

$ sudo rpm -Uvh https://repo.mysql.com/mysql80-community-release-el7-3.noarch.rpm

Linux Concept - mysql 8 repository install

Step 2 – Install MySQL 8.0

After enabling the repository, you can install MySQL using the following command:

$ sudo yum install mysql-community-server

Linux Concept - mysql 8 install

While installing MySQL yum may ask to import the MySQL GPG key, you should allow y type “y” and hit Enter.

Install MySQL 5.7 on RHEL 7

you need to follow below steps to install the previous stable version of MySQL is 5.7:

Step 1 – Enable MySQL 5.7 repository

To enable MySQL 5.7 repository on RHEL 7 need to execute below command on terminal:

$ sudo yum localinstall https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm

Step 2 – Install MySQL 5.7 package

You can install mysql 5.7 community server package by using the following command:

$ sudo yum install mysql-community-server

MySQL Service Management

After the installation of MySQL, you should start and enable the MySQL service.

To start the MySQL service use following command:

$ sudo systemctl start mysqld

To enable the MySQL service so it can automatically start on system startup, use the following command:

$ sudo systemctl enable mysqld

You can check the MySQL service status by using the following command:

$ sudo systemctl status mysqld

Linux Concept - mysql status

MySQL Securing

When MySQL successfully get installed and started, a temporary root password generated to login into MySQL.

You can find the temporary root password by using the following command:

$ sudo grep ‘temporary password’ /var/log/mysqld.log

Linux Concept - mysql temporary password

To make your MySQL secure need to run the “mysql_secure_installation” command as shown below:

Читайте также:  Посмотреть версию кали линукс

Linux Concept - mysql secure installation

After entering the temporary password, you get a prompt to enter a new password for the root user. You can set the new password with your choice which is at least 8-character long and contain one uppercase letter, one lowercase letter, one number and one special character.

Linux Concept - mysql root password change

The script will ask more thing like remove anonymous user, restrict root access from localhost and remove test database. You should type “Y” to answer in “Yes” for those questions.

Linux Concept - mysql secure install

MySQL connection from Command Line

We are using MySQL client to connect with MySQL server which installed with MySQL server. To login into MySQL server using root user, as shown below:

After entering the command, you will have prompted to enter the root password and when successfully login into the MySQL server as shown below:

Linux Concept - mysql login

Conclusion

Now you have learned the process to install MySQL on RHEL 7 Operating System. You also know how to connect with MySQL Server.

Источник

How to get started with MySQL and MariaDB

Person with a laptop and phone

If you plan to set up a web application like Drupal, WordPress, Bugzilla, or something similar, you’re probably going to also need a database so that the app can save the data your users generate. One of the most popular databases is MySQL, which is prominently implemented as an open source project called MariaDB.

Cloud services

It’s common to interact with a database through a programming language. For this reason, there’s usually a MySQL application programming interface (API) (sometimes called a «binding») for Java, Python, Lua, PHP, Ruby, C++, and many, many other programming languages. However, before using an API, it helps to understand what’s actually happening with the database engine.

Client and server

For web applications, databases often (although not always) run on a dedicated database server. Your web app can access your database similarly to how you access remote computers over Secure Shell (SSH). Even when you run your database on the same server as your application, you access it through the server and client model using the loopback IP address 127.0.0.1, also known as localhost .

In this article, I’ll demonstrate a local MySQL install. The process for a remote one is essentially the same, except a few privileges are required to access a database outside localhost . I note these differences when necessary.

Install MySQL

The open source implementation of MySQL is MariaDB. To install MariaDB on a Red Hat Enterprise Linux (RHEL), CentOS, or Fedora server:

[server]$ sudo dnf install mariadb mariadb-server

If you’re also setting up a client machine, install the client software on that machine too:

[client]$ sudo dnf install mariadb 

You can confirm the installation using the —version option. MariaDB responds to either the mariadb or mysql command:

$ mariadb --version mariadb Ver 15.1 Distrib 10.5.13-MariaDB, for Linux (x86_64) $ mysql --version mysql Ver 15.1 Distrib 10.5.13-MariaDB, for Linux (x86_64) 

Start the database service

You’ve installed a database engine, but you haven’t started it. To start it and to set it to autostart after a reboot:

[server]$ sudo systemctl enable --now mariadb

Alternately, you can set MariaDB to start and run until you either reboot or stop it manually:

[server]$ sudo systemctl start mariadb

Connect to your database

After installation, you can open an interactive MariaDB session as root with the —user option:

[server]$ sudo mariadb --user root password for tux: Welcome to the MariaDB monitor. MariaDB> 

IT Automation ebook

You communicate with MariaDB through Structured Query Language (SQL) commands. SQL isn’t a vast language, but it can be nuanced and, as its name suggests, highly structured. Unless you’re designing a database from scratch or developing software that uses a database, you don’t need to know much SQL. If you’re setting up a database for another application to use, that application handles most of the SQL for you, because that’s what it’s programmed to do. You do need administrative functions, however, so here are the basics.

Читайте также:  Enable firewall on linux

Show data with SHOW

The SHOW statement displays information about your database. To get a list of databases in your MariaDB installation:

MariaDB> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | +--------------------+ 3 rows in set (0.000 sec)

As you can see, there are a few default databases present. You can make one active with the USE command:

MariaDB> USE mysql; Database changed

Once you’ve switched to a database, you can run queries on it. For instance, you can show what tables exist in the database using SHOW again:

MariaDB> SHOW TABLES; +---------------------------+ | Tables_in_mysql | +---------------------------+ | column_stats | | columns_priv | | db | | event | [. ] | transaction_registry | | user | +---------------------------+ 31 rows in set (0.000 sec)

Tables are two-dimensional arrays, sometimes visualized as a spreadsheet with columns and rows. You can see the columns with the SHOW command, but because there are many tables to choose from, you must specify which table you want to see:

MariaDB> SHOW COLUMNS FROM user; +-------------+------------+-----+----+--------+------+ | Field | Type | Null| Key| Default| Extra| +-------------+------------+-----+----+--------+------+ | Host | char(60) | NO | | | | | User | char(80) | NO | | | | | Password | longtext | YES | | NULL | | | Select_priv | varchar(1) | YES | | NULL | | | Insert_priv | varchar(1) | YES | | NULL | | | Update_priv | varchar(1) | YES | | NULL | | [. ] 47 rows in set (0.001 sec)

There are a lot of columns in the user table (47, to be precise), which is a lot of data to handle. Luckily, SQL provides the SELECT command.

[ Use the Linux system administration skills assessment to learn which training opportunities are right for you. ]

Query tables with SELECT

Once you’ve identified what tables are in a database, you’ve started to wander into the domain of actual data. Rather than getting all data from a table at once, SQL enables you to select just the parts of a table you care about.

To view the contents of a table, use the SELECT command—but you have to know what you want to select. You know the columns from the results of your SHOW COLUMNS FROM user; command. A reasonable column to be curious about is the one called User , which, as it turns out, contains the usernames of all database users:

MariaDB> SELECT User FROM user; +-------------+ | User | +-------------+ | mariadb.sys | | mysql | | root | +-------------+ 3 rows in set (0.001 sec)

You can also perform a combined query:

MariaDB> SELECT User,Host FROM user; +-------------+------------+ | User | Host | +-------------+------------+ | mariadb.sys | localhost | | mysql | localhost | | root | localhost | +-------------+------------+ 3 rows in set (0.001 sec)

Try similar queries for other columns.

Create a new user with CREATE

As with most login shells, you generally don’t want to interact with MariaDB as an unconstrained, privileged root user. Instead, create a user with limited privileges for you or the application that will interact with the database. In this example, you’re the one using the database, so create a user and an example password:

MariaDB> CREATE USER 'tux'@'localhost' IDENTIFIED BY 'Example123'; Query OK, 0 rows affected (0.012 sec)

If you’re still logged in as root, type exit to leave the MariaDB prompt. Now that you have a user identity with the database, you can access it as a regular user, but only locally. The syntax to open a new local connection is mostly the same as what you used to connect as root, except that you no longer need sudo and you use the -p option to have MariaDB prompt you for a password:

$ mariadb --user tux -p [sudo] password for tux: Welcome to the MariaDB monitor. Commands end with ; or \g. MariaDB> 

Grant remote privileges with GRANT

Remote logins are disabled by default, but you can add a user from a specific known host:

MariaDB> GRANT ALL PRIVILEGES ON *.* TO 'tux'@'192.168.122.31' IDENTIFIED BY 'Example123'

Granting ALL PRIVILEGES to users isn’t always necessary, so consider what permissions a user or an application requires to perform an SQL function. If you’re configuring a database specifically for another application’s use, as you do for WordPress, Drupal, and so on, then that project’s documentation provides a list of privileges required. By limiting privileges granted and tethering an expected user to a specific IP address, you can restrict what damage mistakes or malice can do.

Читайте также:  Nfs sharing on linux

When logging in remotely, you must provide the IP address to your MySQL server using the —host option and (optionally) the port you connect through with the -P option:

$ mariadb --user tux -p --host 192.168.122.10 -P 3306 [sudo] password for tux: Welcome to the MariaDB monitor. Commands end with ; or \g. MariaDB> 

Automation advice

If you’re using a virtual machine as your MySQL database, and you’re accessing that database from the host, your origin IP address may not be what you think it is. For instance, GNOME Boxes tunnels all traffic through a tap0 gateway, meaning that your virtualized MySQL server receives traffic from tun0 , not your wired or wireless IP network interface.

Tend to your firewall

To access MySQL from outside, you also must configure the server’s firewall to permit mysql traffic.

Database interactions

It’s easy to get lost in the vastness of an SQL database. It’s a big, empty space filled with potential and a collection of new commands to explore. Don’t let it overwhelm you. When setting up a database for an application to use, you can find the vital information you need in the project’s documentation. WordPress, for instance, gives you the exact SQL command you need to run on your database to grant WordPress the privileges it needs to create and alter databases and tables. Unless you’re building an application from scratch, the most you probably need to know is how to install MariaDB, how to start it, and how to get to an interactive prompt. And now you do.

Источник

Оцените статью
Adblock
detector