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 compile and install MySQL8.0.20 with source code

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains how to use source code to compile and install MySQL8.0.20, the content is clear, interested friends can learn, I believe it will be helpful after reading.

1 Overview

This article mainly describes how to install MySQL Community version 8.0.20 from source code, first introduce some knowledge about compilation and installation, and then start the compilation and installation.

2 knowledge of source code compilation and installation

2.1 make and configure

Make is a compiled command that looks for the Makefile file in the current directory, and the Makefile file records the details of how the source code is compiled. Configure is a testing program written by software developers to detect the user's development environment, and generate Makefile files after testing. Typically, configure detects the following:

Whether there is a suitable compiler, whether it has the required function library, and whether it is compatible with the existence of kernel header files in this system.

2.2 Tarball Fil

Tarball files are actually files that compress the source code after typing with tar. Gzip is usually used for compression, usually with a .tar.gz or .tgz extension, but because technologies such as bzip2 and xz compress better than gzip, the file name becomes a .tar.bz2 or .tar.xz extension. Usually an Tarball file has:

Source code detection file (configure/config) description (README/INSTALL)

2.3 Source Code compilation and installation related components

2.3.1 Compiler

A compiler is required to compile, usually using gcc.

2.3.2 make+autoconfig

For software released in the form of Tarball, in order to simplify the compilation process, make is usually required to compile according to the dependencies of the target file, but because make requires Makefile, autoconfig is required to generate Makefile.

2.3.3 function library

Libraries provided by the kernel and related include files are required.

2.4 static and dynamic libraries

Function libraries are divided into two types: dynamic libraries and static libraries, most of which are placed in / lib and / lib64.

2.4.1 static library

The extension is .a, which is directly integrated into the execution program at compile time, so the file generated by the static library will be larger, and the compiled executable file can be run directly without relying on the external function library. In addition, it is difficult to upgrade, because it is directly integrated into the program, and if you upgrade the static library, you need to recompile.

2.4.2 dynamic library

The extension is .so, unlike static libraries when compiling, dynamic libraries have only one pointer in the program. When the executable program needs the function of the library, it will read the function library to use, and the generated executable file will be smaller, but the compiled program cannot be executed independently. In addition, it is convenient to upgrade and does not need to be recompiled, because the execution file points directly to the new library file.

2.5 General steps for compilation and installation

(1) get the source code: generally use wget or curl or download from the browser. (2) View help files: after decompressing, check the relevant contents of files such as INSTALL or README. (3) install dependencies: install dependencies according to the official website documents or the information obtained in the previous step. (4) generate Makefile: generally use configure/config to configure, detect the operating environment, specify the installation location, enable / close the corresponding functions, specify the location of related libraries, etc., and determine the dependency relationship. Generally, you need to use-help to get the option to help. Configure and generate Makefile (5) compilation after specifying the corresponding options: the actual compilation step, a simple make command, actually includes header file precompilation, preprocessing, compilation and connection steps (6) installation: make install, this step actually carries out two steps of installation and connection to the operating system

Note that the above steps are all in order, and if the previous step fails, the latter step cannot be performed, that is, the previous step is required to be executed successfully before the next step can be performed. Complete the above six steps to compile and install, generally need to carry out some subsequent processing, such as adding executable file path to PATH, adding header files and library files to / usr/include and / etc/ld.so.conf.d, adding online help files to / etc/man_db.conf.

2.6 Psychological preparation before compilation and installation

Here is the last hint, you can close this page by ctrl+w before you install it to avoid a lot of pain.

The most common problem with compilation and installation is the problem of version and dependency, which is easy to deal with and can be upgraded through the package manager or manually. As for the dependency problem, it is easy to install the package manager. Compiling and installing will be a headache because you don't know how many more dependencies need to be installed under a dependency.

Therefore, it takes enough time and patience to solve countless problems in order to successfully compile and install large-scale software like MySQL and Workbench.

Cut the crap and get started.

3 install MySQL

3.1 installation dependency

MySQL requires the following dependencies:

Cmakemake (recommended 3.75 or above) compiler (GCC5.3+ or Clang4.0+ or XCode9+ or Developer Studio12.6+ or Visual Studio2017) SSL library (default uses system OpenSSL) Boost C++ library, need to be used to build but do not need to use, do not need to install, the source code can ncurses library bison2.1+git

3.2 package Manager installation

The author's Debian system, you can use apt:

Sudo apt-get install-y bison git hostname libncurses-dev libssl-dev make openssl pkg-config doxygen cmake make

RedHat8.x:

Sudo yum install-y bison bzip2 git hostname ncurses-devel openssl openssl-devel pkgconfig tar wget zlib-devel doxygen diffutils rpcgen make libtirpc-devel cmake gcc

RedHat7.x:

Sudo yum install-y bison bzip2 git hostname ncurses-devel openssl openssl-devel pkgconfig tar wget zlib-devel doxygen cmake gcc

Others search on their own.

3.2 compile and install

If you do not want to install with the package manager, you can use a compiled installation.

Welcome to toss around.

3.2.1 install cmake

Tar-zxvf cmake-3.17.2.tar.gzcd cmake-3.17.2./bootstrap-- prefix=/usr/local/cmakemake clean make- j 6 # 6 is the number of CPU cores. Custom modification. If it fails, use makemake testsudo make install.

3.2.2 install make

If you cannot compile and install without a compiler, you can install it using a software package. In the author's Debian system, you can directly use apt:

Sudo apt install make

3.2.3 install gcc

Tar-xvf gcc-9.3.0.tar.xzcd gcc-9.3.0./contrib/download_prerequisitesmkdir buildcd build../configure-- prefix=/usr/local/gcc-enable-checking=release-disable-multilib make clean make-j 6make testsudo make installsudo ln-sv / usr/local/gcc/include / usr/include/gcc#/etc/ld.so.conf.d/gcc.conf add the following content / usr/local/gcc/lib/usr/local/gcc/lib64

3.2.4 install openssl

Tar-zxvf openssl-1.1.1g.tar.gzcd openssl-1.1.1g./config-- prefix=/usr/local/openssl-- openssldir=/usr/local/openssl/ssl#prefix is the installation location, and / usr/local#openssldir is the configuration file location by default At the same time, store the certificate and key pair make clean make-j 6make testsudo make installsudo ln-sv / usr/local/openssl/include / usr/include/openssl#/etc/ld.so.conf.d/openssl.conf plus the following content / usr/local/openssl/lib

3.2.5 download boost

Poke here on the official website.

The required version is 1.70.0. At present, the latest version is 1.73.0, in theory, the newer version should work, here is 1.70.0 download. If you do not download the boost library manually, you can set DDOWNLOAD_BOOST to 1 to download when you use cmake to generate Makefile.

You can decompress it after download.

Tar-xvf boost_1_70_0.tar.bz2

3.2.6 install ncurses

Tar-zxvf ncurses-6.2.tar.gzcd ncurses-6.2./configure-- prefix=/usr/local/ncursesmake-j 6sudo make installsudo ln-sv / usr/local/ncurses/include / usr/include/ncurses#/etc/ld.so.conf.d/ncurses.conf join / usr/local/ncurses/lib

3.2.7 install bison

Tar-xvf bison-3.4.tar.xzcd bison-3.4./configure-- prefix=/usr/local/bisonmake-j 6sudo make install#/etc/ld.so.conf.d/bison.conf join / usr/local/bison/lib

3.2.8 install git

Tar-xvf git-2.26.2.tar.xzcd git-2.26.2./configure-- prefix=/usr/local/git\-- with-openssl=/usr/local/openssl\-- with-libpcre2=/usr/local/pcre2\-- with-curl=/usr/local/curl\-- with-expat=/usr/local/expat\-- with-iconv=/usr/local/iconv\-- with-editor=/usr/bin/vim\-- with-zlib=/usr/local/zlib\- With-tcltk=/usr/local/tclmake all doc infosudo make install install-doc install-html install-info

3.2.9 follow-up processing

Modify PATH:

# add export PATH=$PATH in ~ / .bash_profile or ~ / .bashrc:\ / usr/local/cmake/bin:\ / usr/local/gcc/bin:\ / usr/local/openssl/bin:\ / usr/local/bison/bin:\ / usr/local/ncurses/bin:\ / usr/local/git/bin:\

Make the dynamic library effective:

Ldconfig

If the permission is insufficient, please add sudo.

Download MySQL Community Edition

Here on the official website.

I don't know the difference between the first one and the second one, because the author has tried to compile and install both successfully. Although it says the second one with a Boost head, it doesn't seem to be of any use. The first one is used here.

Check (optional):

Md5sum mysql-boost-8.0.20.tar.gz

3.4 generate Makefile

Sudo cmake.. \-DDEFAULT_CHARSET=utf8mb4\-DDEFAULT_COLLATION=utf8mb4_unicode_ci\ #-DENABLED_LOCAL_INFILE=ON\-DWITH_SSL=system\-DCMAKE_INSTALL_PREFIX=/usr/local/mysql/server\-DMYSQL_DATADIR=/usr/local/mysql/data\-DMYSQL_TCP_PORT=3306\-DDOWNLOAD_BOOST=0\-DWITH_BOOST=~/Desktop/boostDDEFAULT_CHARSET: specify the default character set as utf8mb4. Because of historical problems, utf8 in MySQL is not a real utf8, but a castrated version with a maximum length of three bytes. A storage exception occurs when a four-byte utf8 encoding is encountered. From 5.5.3 onwards, use utf8mb4 to implement the full utf8. DDEFAULT_COLLATION: collation, which defaults to utf8mb4_0900_ai_ci, is a type of utf8mb4_unicode_ci. 0900 refers to the version of the Unicode proofreading algorithm, ai refers to accent insensitive (as indicates sensitive), and ci refers to insensitive case (cs means differentiated). Utf8mb4_unicode_ci means to sort and compare based on the standard Unicode, which can sort accurately between various languages, while utf8mb4_general_ci may have inconsistent sorting results and poor accuracy when it encounters some special character sets, but it has better performance and faster comparison and sorting. DENABLED_LOCAL_INFILE indicates whether the load data command can be used. DWITH_SSL means to use the system's SSL library. If you do not use the system's, please customize the path. DCMAKE_INSTALL_PREFIX:MySQL installation directory. DMYSQL_DATADIR:MySQL data directory, initially empty. DMYSQL_TCP_PORT: Port. Default is 3306. DDOWNLOAD_BOOST: value 0 or 1, whether to download the Boost library. DWITH_BOOST: if you do not download the Boost library, it is the location of the local Boost library. If you download Boost, it indicates the download location.

For more parameters, use the

Sudo cmake.. -LH

Check.

3.5 compilation and installation

Sudo make

Or

Sudo make-j n

The author tried make-j 6, failed, but replaced it with make.

The speed of make is still quite different from that of make-j.

Once compiled, it is recommended that you test it:

Make test

Then install:

Sudo make install

3.6 subsequent configuration

3.6.1 user groups and users

Create a new user group and user, and modify the permissions of the user data directory:

Sudo groupadd mysqlsudo useradd-r-g mysql-s / bin/false mysqlsudo chown mysql:mysql / usr/local/mysql/datasudo chmod 750 / usr/local/mysql/data

The data directory is modified as needed. If there is an unwritable error later, please change the permission to 777.

3.6.2 profile

The configuration file is my.cnf, which can be placed in the

/ etc//etc/mysql/ installation directory / etc/~/

Bottom, the reading order is from top to bottom. After installation, the author defaults to / etc/mysql/my.cnf, which is a global configuration, and ~ / .my.cnf is a user-specific configuration. Here, modify / etc/mysql/my.cnf directly:

[client-server] # Import all .cnf files from configuration directory!includedir / etc/mysql/conf.d/!includedir / etc/mysql/mariadb.conf.d/ [mysqld] port=3306basedir=/usr/local/mysql/serverdatadir=/usr/local/mysql/datacharacter-set-server=utf8mb4 [mysql] default-character-set= utf8mb4[client] port=3306default-character-set=utf8mb4

Below [mysqld] are the newly added fields, and the data directory can be modified by itself.

It is recommended that the character set be changed to utf8mb4, because utf8 refers to utf8mb3 in MySQL, the maximum character length of the supported utf8 encoding is 3 bytes, and an exception will be inserted if a 4-byte wide character is encountered. The maximum Unicode character that can be encoded in a three-byte utf8 is 0xffffff, that is, the basic multilingual plane, and Emoji and many uncommonly used Chinese characters cannot be stored. Utf8mb4 is supported after 5.5.3, so utf8mb4 should be used uniformly for the sake of compatibility.

3.7 initialization

Modify the environment variable:

# .bashrc or .bash _ profile plus export PATH=$PATH:/usr/local/mysql/server/bin

Use

Mysqld-initialize-user=mysql

Or

Mysqld-initialize-insecure-user=mysql

Then enable ssl and rsa support (optional):

Mysql_ssl_rsa_setup

Finally, start the service:

Mysqld_safe-- user=mysql &

3.8 change password

Log in using root, if initialized with insecure:

Mysql-u-skip-password

Initialize with initialize:

Mysql-u root-p

Enter the password that appears in the initialization.

Then change the password:

Alter user root@localhost identified by 'xxx'

3.9 Test

Use the built-in mysqlshow and mysqladmin:

Mysqladmin-u root-p versionmysqlshow-u root-p

3.10 wrap-up work

3.10.1 alias

Alias md='mysqld-u mysql &'

Enter md to start the MySQL service.

3.10.2 install Mycli

Mycli is a MySQL command line client tool with automatic completion and syntax highlighting.

You can install it using pip. Please use python2

Pip install mycli

Python3, please use

Pip3 install mycli

Pip cannot be found, please install:

Sudo apt install python-pip#python2sudo apt install python3-pip

Then use mycli to enter the database:

Mycli-u root

Use the complement happily!

After reading the above, do you have a further understanding of how to compile and install MySQL8.0.20 with source code? if you want to learn more, you are welcome to follow the industry information channel.

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