Get the App
SLTechnology News&Howtos  ›  Database  › 

What are the installation methods of MySQL database

Shulou Source: shulou.com Published: 2022-05-31 14:32:49 10月26日 Update

Editor to share with you what MySQL database installation methods, I believe that most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to know it!

Install Mysql in RPM/YUM mode

1. First, go to the official website https://dev.mysql.com/downloads/repo/yum/ to download the yum source of mysql and upload it to the server. Or use the following command to download:

Wget http://repo.mysql.com/mysql80-community-release-el7-3.noarch.rpm

two。 Install the yum source for mysql.

Rpm-ivh mysql80-community-release-el7-3.noarch.rpm

3.yum installs mysql.

Yum install mysql-server-y

4. Start mysql when the installation is complete.

Systemctl start mysqld

In addition, you can also use MariaDB instead, the MariaDB database management system is a branch of MySQL, mainly maintained by the open source community and licensed by GPL. One of the reasons for developing this branch is that after Oracle acquired MySQL, there is a potential risk of shutting down MySQL, so the community uses a branching approach to avoid this risk. The goal of MariaDB is to be fully compatible with MySQL, including API and the command line, making it an easy replacement for MySQL.

Yum install mariadb-server-y

Install Mysql in binary mode

1. First, go to the official website https://dev.mysql.com/downloads/mysql/ to download the Linux Generic version of mysql and upload it to the server.

two。 Add mysql users and user groups under which the database is installed.

# groupadd mysql # useradd-g mysql mysql

3. Extract the binary installation package, assuming that the installation package is placed under / home/mysql, and add a matching link "mysql" to the extracted mysql directory, which will be more convenient for the operation of the mysql directory.

# cd / home/mysql/ # tar-xvJf mysql-8.0.19-linux-glibc2.12-x86_64.tar.xz # ln-s mysql-8.0.19-linux-glibc2.12-x86_64 mysql

4. Create the mysql data directory and modify the directory permissions.

# mkdir / home/mysql/data # chown-R mysql.mysql / home/mysql/data/

5. Initialize the database. A default random password is generated.

# / home/mysql/mysql/bin/mysqld-initialize-user=mysql-basedir=/home/mysql/mysql-datadir=/home/mysql/data

6. Configure the mysql parameter file / etc/my.cnf and grant mysql permissions.

# vi / etc/my.cnf [mysqld] basedir=/home/mysql/mysql datadir=/home/mysql/data # chown mysql.mysql / etc/my.cnf

7. Set up the mysql startup file and start mysql.

# cp / home/mysql/mysql/support-files/mysql.server / etc/init.d/mysqld # service mysqld start Starting MySQL.Logging to'/ home/mysql/data/linux-52-122.erratically. .. SUCCESS!

8. Add the mysql environment variable and take effect.

# echo "export PATH=$PATH:/home/mysql/mysql/bin" > > / etc/profile # source / etc/profile

9. Connect to mysql, enter the random password generated before, log in and change the password and take effect.

# mysql-u root-p Enter password: Welcome to the MySQL monitor. Commands end with; or\ g. Your MySQL connection id is 10 Server version: 8.0.19 Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or'\ h' for help. Type'\ c'to clear the current input statement. Mysql > alter user 'root'@'localhost' identified by' 123456; Query OK, 0 rows affected (0.00 sec) mysql > flush privileges; Query OK, 0 rows affected (0.00 sec) mysql > exit Bye

Source code compilation and installation of Mysql

1. Installing a source package is similar to installing a binary package. First, go to the official website https://dev.mysql.com/downloads/mysql/ to download mysql's source code and upload it to the server. Or use the following command to download:

# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.29.tar.gz

two。 Create a mysql group and user name. At the same time, it is forbidden to log in to the system directly as a mysql user for the sake of security.

# groupadd mysql # useradd-r-g mysql-s / bin/false mysql

3. Create the mysql installation directory and data directory, and modify the directory permissions.

# mkdir-p / usr/local/mysql # mkdir-p / data/mysql # chown-R mysql.mysql / usr/local/mysql/ # chown-R mysql.mysql / data/mysql/

4. Extract the mysql source code package.

# tar-xzvf mysql-boost-5.7.29.tar.gz

5. Compile and install mysql. Install it first if you don't have the cmake tool.

# yum install cmake-y # cd mysql-5.7.29 cmake. \-DWITH_BOOST=/root/mysql-5.7.29/boost\-DCMAKE_INSTALL_PREFIX=/usr/local/mysql\-DMYSQL_DATADIR=/data/mysql\-DWITH_INNOBASE_STORAGE_ENGINE=1\-DWITHOUT_FEDERATED_STORAGE_ENGINE=1\-DWITHOUT_ARCHIVE_STORAGE_ENGINE=1\-DWITH_PARTITION_STORAGE_ENGINE=1\-DWITH_DEBUG=1\-DDEFAULT_CHARSET=utf8\-DDEFAULT_COLLATION=utf8_general_ci\-DFORCE_INSOURCE_BUILD=1\-DDOWNLOAD_BOOST=1\-DWITH_SSL=system # make & & make install

For the meaning of compilation parameters, please refer to the official documentation:

Https://dev.mysql.com/doc/refman/8.0/en/source-configuration-options.html

6. Initialize the database. And a default random password is generated.

7. Set up the startup script and start mysql.

# cp / usr/local/mysql/support-files/mysql.server / etc/init.d/mysqld # systemctl start mysqld

8. Add the mysql environment variable and take effect.

# echo "export PATH=$PATH:/usr/local/mysql/bin" > > / etc/profile # source / etc/profile

9. Log in to the database and change the password after logging in with the default password you just generated.

10. Login succeeded after changing password.

The above is all the contents of the article "what are the ways to install MySQL database?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Data database password directory method user login generation binary branch command server permission source code article service compilation content parameter variable Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Shulou Tech Info Shulou Technology vpn OPPO Reno