Installation and basic setup of MySQL on Centos 8 TAR
Last updated: Jun 02, 2022
Colleagues hello to all.
Mysql DBMS is a free relational database management system, and in today's article we will talk about how to install Mysql DBMS on Centos 8 from a tar archive. We will install the version 8.0.29.
- Create a mysql account.
- Download the Mysql TAR archive.
- Create the necessary directories for the Mysql DBMS.
- Let's archive our downloaded TAR archive.
- Create a configuration file.
- Database initialization.
- Launching the database.
- Stop the database.
1. Creating a mysql account.
First thing we need to create a Linux account called mysql because the database only runs under the mysql account. In order to create an account in Linux, use the command:
$. useradd mysql
2. Download the Mysql TAR archive.
Next step we need to download the Mysql TAR archive. And to download the Mysql TAR archive we need to go to https://dev.mysql.com/downloads/mysql/.
Next, select your operating system and its bit depth, and only after that you will have a complete list of available files for download.
We need TAR!! Click Download.
After clicking the Download button, you will be redirected to the TAR archive download page. We need to copy the download link. COPY!!
After copying the link, go to the server and download the TAR archive using the wget utility.
$. wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.29-el7-x86_64.tar
Great! We have successfully downloaded the TAR archive. Let's move on.
3. Create the necessary directories for the Mysql DBMS.
The next step is to create directories for the database.
3.1. Directory for data:
$. mkdir -p /app/mysql/data
3.2. Directory for error logs, query logs and slow query logs.
$. mkdir -p /app/mysql/log
3.3. Directory for configuration files.
$. mkdir -p /app/mysql/config
3.4. Directory for binary logs (binary log).
$. mkdir -p /app/mysql/binlog
3.4. Directory for relay logs.
$. mkdir -p /app/mysql/relaylog
3.5. Assign the owner of the directory and the group to the mysql account.
$. chown -R mysql:mysql /app/mysql
You should be like me.
4. Roz archive our downloaded TAR archive.
4.1. We transfer our downloaded TAR archive to the directory /app/mysql
$. cp mysql-8.0.29-el7-x86_64.tar /app/mysql
4.2. Roz archive the TAR archive using the tar utility.
$. tar -xvf mysql-8.0.29-el7-x86_64.tar.gz
You should be able to do the same as mine. mysql-8.0.29-el7-x86_64.tar.gz can be deleted.
4.3. Rename the directory to server.
$. mv mysql-8.0.29-el7-x86_64 server
Your directory names should be the same as mine.
The main thing is that the owner of all directories should be mysql.
5. Creating a configuration file.
If anyone does not know, the Mysql database likes when its configuration file is created in the /etc/my.cnf directory, but we will cheat a little and specify the path of the configuration file where we want.
5.1. Create the first configuration file my.cnf in /etc.
$. vim /etc/my.cnf
And we will indicate in it where we will actually have the database configuration.
The !include command seems to tell mysql that my configuration will continue in the my.cnf file, but already in the directory we created /app/mysql/config.
5.2. Let's create our config file in the /app/mysql/config directory.
$. vim /app/mysql/config/my.cnf
And add the most important parameters to it:
- basedir = /app/mysql/server
- datadir = /app/mysql/data
- log_bin = /app/mysql/binlog/mysqlbin
- log_bin_index = /app/mysql/binlog/mysql-bin.index
- log_error = /app/mysql/log/mysql.local.err
- default_authentication_plugin = mysql_native_password
6. Initializing the database.
After creating all the directories and the configuration file, we need to initialize the database so that all the necessary directories of the database itself are created.
6.1. If you were doing everything as root, then you need to switch to mysql.
$. su - mysql
6.2. We initialize the database.
$. export BASEDIR=/app/mysql/server
$. export PATH=$BASEDIR/bin:$PATH
$. mysqld --initialize --user=mysql --basedir=/app/mysql/server --datadir=/app/mysql/data --console
After initialization, you should have database files in the /app/mysql/data directory.
And the generated password for the root account will appear in the /app/mysql/log directory in the mysql.local.err file.
7. Starting the database.
After initializing the database, we can now start it, for this we will use the mysqld_safe utility.
$. mysqld_safe --basedir=/app/mysql/server --datadir=/app/mysql/data --console --user=mysql &
After starting, you should have database processes, to check we will use the command:
$. ps aux | grep mysql
As you can see in the screenshot, the database processes are present, which means you can already connect to it via mysql -u root -p
8. Stop the database.
To stop the database, you need to use the mysqladmin utility.
$. mysqladmin -u root -p shutdown
As a result, colleagues, today we successfully installed the Mysql database from the TAR archive. I agree with you that this is not the easiest way to install, but it is the best in terms of database maintenance. So it's up to you to decide whether you need this installation method or not.
Thank you all, I hope that my article helped you in some way.