[wpseo_breadcrumb]

Installing MySQL using YUM or APT Package Manager

Update on:
Jan 24, 2023

MySQL is one of the most popular open-source relational databases. It is used for storing and managing data for various types of applications, including web applications, content management systems, and more. In this article, we will cover how to install MySQL on a Linux server using YUM (Yellowdog Updater Modified) and APT (Advanced Package Tool) package managers.

Before we begin, it’s important to note that the commands and examples in this article are specific to the Red Hat and Debian/Ubuntu distributions of Linux. If you’re using a different distribution, the commands and package names may be slightly different.

Installing MySQL using YUM

YUM is the default package manager for Red Hat-based distributions of Linux, such as Red Hat Enterprise Linux (RHEL), CentOS, and Fedora. To install MySQL using YUM, you will need to have root or superuser access to the server.

First, you will need to add the MySQL YUM repository to your server. This is a collection of software packages that are available for installation using YUM. To add the MySQL YUM repository, you will need to create a new file in the /etc/yum.repos.d/ directory. For example, you can create a file called mysql-community.repo with the following contents:

[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

Once the repository is added, you can then use the YUM command to install the MySQL server package. For example, to install the latest version of MySQL, you can use the following command:

yum install mysql-server

During the installation process, you will be prompted to enter a password for the root user. This is the user that has full access to the MySQL database server. Make sure to choose a strong and secure password.

After the installation is complete, you can start the MySQL server using the following command:

systemctl start mysqld

You can also check the status of the MySQL server using the following command:

systemctl status mysqld

If everything is set up correctly, you should see a message indicating that the MySQL server is running.

Installing MySQL using APT

APT is the default package manager for Debian and Ubuntu-based distributions of Linux. To install MySQL using APT, you will need to have root or superuser access to the server.

First, you will need to add the MySQL APT repository to your server. This is a collection of software packages that are available for installation using APT. To add the MySQL APT repository, you will need to create a new file in the /etc/apt/sources.list.d/ directory. For example, you can create a file called mysql.list with the following contents:

deb http://repo.mysql.com/apt/ubuntu/ trusty mysql-5.7
deb-src http://repo.mysql.com/apt/ubuntu/ trusty mysql-5.7

Once the repository is added, you can then use the APT command to install the MySQL server package. For example, to install the latest version of MySQL, you can use the following command:

apt-get update
apt-get install mysql-server

During the installation process, you will be prompted to enter a password for the root user. This is the user that has full access to the MySQL database server. Make sure to choose a strong and secure password.

After the installation is complete, you can start the MySQL server using the following command:

systemctl start mysql

You can also check the status of the MySQL server using the following command:

systemctl status mysql

If everything is set up correctly, you should see a message indicating that the MySQL server is running.

Configuring MySQL

Now that MySQL is installed on your server, you’ll need to configure it to make sure it’s running securely and efficiently. Here are a few important configurations you should consider:

  • Secure the MySQL installation: One of the first things you should do after installing MySQL is to secure the installation. This will remove some default user accounts, change the root password, and disable remote root login. You can do this by running the mysql_secure_installation script.
  • Set the character set and collation: By default, MySQL uses the latin1 character set and the latin1_swedish_ci collation. If you’re going to be storing non-English data in your MySQL databases, you’ll want to change this to UTF-8.
  • Optimize the MySQL configuration: MySQL has many performance-related settings that you can adjust to optimize its performance on your server. Some popular settings include the query cache size, table cache size, and innodb buffer pool size. You can configure these settings in the my.cnf file.
  • Backup MySQL: It is important to have a proper backup plan in place to protect your data in case of any disaster. There are several ways to backup MySQL, such as using mysqldump command, replication, or third-party tools.

Conclusion

Installing MySQL on a Linux server is a relatively simple process. By using YUM or APT package manager, you can easily install and configure MySQL. It is important to remember to secure the installation and optimize the configuration for best performance. Also, proper backup plan is crucial to protect your data. With MySQL installed, you can now start creating and managing databases for your application or service.

Related Posts

MySQL: Creating tables

Creating tables in MySQL is a fundamental task for any database administrator or developer. A table is a collection of related data that is organized in a specific structure, with rows and columns. In this article, we will go over the basics of creating tables in...

MySQL: Creating databases

MySQL is a popular open-source relational database management system that is widely used for web development, data warehousing, and other applications. One of the first things you'll need to do when working with MySQL is to create a new database. In this article,...

Connecting to MySQL using the command-line client

Connecting to MySQL using the command-line client can seem like a daunting task for those new to the world of databases. But don't worry, it's not as difficult as it may seem. In this article, we'll go over the basics of connecting to a MySQL server using the...

Installing MySQL utilities

Installing MySQL utilities can be a bit tricky, but with the right tools and a little bit of knowledge, it's a breeze. In this article, we'll go over the different ways you can install MySQL utilities, including using the command line, using a package manager, and...

Follow Us

Our Communities

More on MySQL

The Ultimate Managed Hosting Platform
Load WordPress Sites in as fast as 37ms!

0 Comments

0 Comments

Submit a Comment

Your email address will not be published.

1 × four =