Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to install mysql5.7 version and system optimization in binary mode under Linux

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

Editor to share with you how to install the mysql5.7 version and system optimization in binary mode under Linux. I hope you will get something after reading this article. Let's discuss it together.

This article mainly introduces the installation / startup / shutdown process of MySQL binary software package.

Some people may ask, why choose binary installation?

In fact, the answer is very simple. All the functions have been configured in the official version, and we can easily use them.

There are four official MySQL versions: GA version, DMR version, RC version and Beta version. In general, the production environment or the test environment

Select the GA version (the generally available version that has been tested for bug repair).

Download address: https://dev.mysql.com/downloads/mysql/

After the download is completed, you can verify MD5, the version I downloaded earlier, and demonstrate the use of this command here (md5sum file name)

[root@tse2 downloads] # md5sum mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz d903d3dbf235b74059a4b3e216c71161 mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz

1. Pre-installation system environment detection

No matter which version of MySQL is installed, in order to install the MySQL database smoothly and optimize the database in the later stage, it is very necessary to test the Linux system in the early stage.

1.1.The selinux and iptables need to be disabled. Restart the server after changing the SELINUX=disabled to take effect.

I don't have iptables here. I use firewall, so I don't have to turn off iptables.

1.2.The cfq mode is used by default in the Icano scheduling system, and it is strongly recommended to use deadline mode here.

View the Icano scheduling file:

[root@tse2 downloads] # cat / sys/block/sda/queue/scheduler noop [deadline] cfq

1.3.Setting of swap partition

The size of the swpapiness value has a big impact on how swap partitions are used.

It has two limits of 0 and 100. zero means to maximize the use of physical memory before using swap partitions. this behavior is likely to cause a system memory overflow and an OOM error, resulting in an accidental kill drop of MySQL, so you need to set it carefully.

100 is to actively use swap partitions and move data from memory to swap partitions in time (not recommended). It is recommended that you do not allocate swap, or allocate 4GB space is sufficient.

How do I view the swappiness file?

[root@tse2 grub2] # cat / proc/sys/vm/swappiness [root@tse2 grub2] # sysctl-a | grep swapsysctl: reading key "net.ipv6.conf.all.stable_secret" sysctl: reading key "net.ipv6.conf.default.stable_secret" sysctl: reading key "net.ipv6.conf.ens192.stable_secret" sysctl: reading key "net.ipv6.conf.lo.stable_secret" vm.swappiness = 30

To change the value of swappiness, edit / etc/sysctl.conf and add the value of vm.swappiness.

1.4. Selection of file system

It is recommended to use the xfs file system, which is more convenient to manage, support dynamic expansion and delete files than ext4.

1.5. Operating system limitations

Let's take a look at some of the limitations of the current operating system, using ulimit-a to see:

The two most important parameters are marked here, one is called open files and the other is called max user processes.

If the open files setting is unreasonable, and the current server has too many connections or too many tables, it may not be able to open the table or access the table.

By default, the maximum number of Linux handles is 1024, which means that a single process can access up to 1024 file handles. If the default value is exceeded, the file handle exceeds the limit error "too many open files".

The purpose of the max user processes parameter: sometimes we may run a lot of instances, but find that we can't create a new connection and report a "resource temporarily unavailable" error, indicating that we don't have enough resources.

In order to prevent the above two error situations, we can modify the software and hardware limits of the system. Edit / etc/security/limits.conf to add content related to restrictions. Remember that after you change the content, you need to restart the operating system to take effect.

[root@tse2 grub2] # vim / etc/security/limits.conf* soft nproc 65535 * hard nproc 65535 * soft nofile 65535 * hard nofile 65535

1.6. numa needs to be closed.

To put it simply, by turning off the numa function, you can allocate memory better, and you don't need to use swap to get memory.

Because experienced system administrators and DBA both know how disgusting database performance degradation can be when using swap.

The shutdown method is also closed in BIOS, in the operating system, or during database startup.

[root@tse2 bin] # numa-- interleave=all / mysql/app/bin/mysqld_safe-defaults-file=/etc/my.conf &

2. MySQL5.7 version installation process

After checking the operating system environment, enter the MySQL installation phase, summed up as a "trilogy + one step" approach.

2.1. Part I

Create a MySQL user and specify the user group to which MySQL belongs. The command is as follows:

[root@tse2 /] # groupadd mysql [root@tse2 /] # useradd-g mysql mysql-s / sbin/nologin

The home directory of the package (basedir) on my side is used to putting it under / data/downloads:

[root@tse2 downloads] # pwd/data/downloads

You need to extract the MySQL package with the following command:

[root@tse2 downloads] # tar-zxvf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz

Authorization for the MySQL directory is required:

[root@tse2 downloads] # chown-R mysql:mysql / mysql

2.2, part II

Create the data directory (datadir) of the MySQL database, where you can choose to create it under / mysql/:

[root@tse2 downloads] # mkdir-p / mysql/data

Also authorize the data catalog:

[root@tse2 downloads] # chown-R mysql:mysql / mysql/data

2.3. Part III

Because it is a binary installation, the database configuration file here needs to be configured by itself, so the last part is finished.

Download address of my.cnf configuration file: https://files.cnblogs.com/files/Sungeek/Tsemy.7z

Password: tse

2.4. The last step

The mysqld command initializes the database:

[root@tse2 mysql] # / mysql/app/bin/mysqld-defaults-file=/etc/my.cnf-basedir=/mysql/app-datadir=/mysql/data/-user=mysql-initialize

Note: if you add the-- initialize parameter to the initialization process, a temporary database initialization password will be generated

Record it in log-error (error log). If you add the-- initialize-insecure parameter, it means no password to enter. It is recommended to use the method of generating initialization password!

The process of starting the database:

[root@tse2 mysql] # / mysql/app/bin/mysqld_safe-- defaults-file=/etc/my.cnf &

After the database starts successfully, the initialization password for entering the database will be under / mysql/logs/error.log:

[root@tse2 logs] # cat / mysql/logs/error.log | grep password

After entering the database with the initialization password, you need to change the database root password to never expire:

/ mysql/app/bin/mysql-uroot-pmysql > SET PASSWORD = '123456 UNIX POSIX > ALTER USER' root'@'localhost' PASSWORD EXPIRE NEVER;mysql > flush privileges what is the UNIX system Linux is a free-to-use and free-spread UNIX-like operating system, is a POSIX-based multi-user, multi-task, multi-threaded and multi-CPU operating system, using Linux can run major Unix tools, applications and network protocols.

After reading this article, I believe you have a certain understanding of "how to install mysql5.7 version and system optimization in binary mode under Linux". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report