In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Will choose to use the source code to install MySQL, presumably have a certain understanding of MySQL and other installation methods, here do not elaborate too much on the surrounding information, just start.
Compiling MySQL consumes more memory, and if the machine memory is small, an out-of-memory exception may occur during compilation. If the swap partition is not set, you can set the swap partition to solve the problem, otherwise you can only expand the memory:
[root@txy-server ~] # dd if=/dev/zero of=/swapfile bs=1k count=2048000 [root@txy-server ~] # mkswap / swapfile [root@txy-server ~] # swapon / swapfile1, install dependency packages required for compilation
1.1.Using the yum command to install the packages and tools that the compilation depends on:
[root@txy-server ~] # yum install-y cmake3 git gcc-c++ ncurses-devel perl-Data-Dumper boost boost-doc boost-devel bzip2 openssl-devel libtirpc-devel.x86_64
Since we need to upgrade the version of gcc when compiling MySQL, we need to upgrade the version of gcc first, because the latest version of yum installation is only 4.8.5.
There are two main ways to upgrade the gcc version, one is to download the source code package for compilation and installation, and the other is to install the devtoolset package using yum. Currently, the gcc version in the devtoolset package is 5.3.1.
The source code installation is more flexible and you can choose any version, but it is very time-consuming. Both methods will be introduced here, and you can choose according to the situation.
1.1.1. Install the devtoolset package using yum with the following commands:
[root@txy-server ~] # yum install-y centos-release-scl scl-utils-build [root@txy-server ~] # yum install-y devtoolset-4-gcc.x86_64 devtoolset-4-gcc-c++.x86_64 devtoolset-4-gcc-gdb-plugin.x86_64
1.1.2. Create a software link to overwrite the gcc-related commands under / usr/bin, because when compiling MySQL, you will go to the / usr/bin directory by default to find gcc-related commands:
[root@txy-server ~] # ln-sf / opt/rh/devtoolset-4/root/usr/bin/* / usr/bin/
1.1.3. Finally, verify that the version of gcc, cc, C++ and other commands is 5.3.1:
[root@txy-server ~] # gcc-v...gcc version 5.3.1 20160406 (Red Hat 5.3.1-6) (GCC) [root@txy-server ~] # cc-v...gcc version 5.3.1 20160406 (Red Hat 5.3.1-6) (GCC) [root@txy-server ~] # C++-v...gcc version 5.3.1 20160406 (Red Hat 5.3.1-6) (GCC) Tips: it is recommended to install in this way It's relatively simple and not easy to step on.
1.2.1. The following is how to install the source code. First, download the GCC source code installation package and decompress it:
[root@txy-server ~] # cd / usr/local/src [root@txy-server / usr/local/src] # wget http://ftp.gnu.org/gnu/gcc/gcc-9.1.0/gcc-9.1.0.tar.gz[root@txy-server / usr/local/src] # tar-xzvf gcc-9.1.0.tar.gz
1.2.2. Enter the extracted directory and run the download_prerequisites script, which automatically downloads the dependent files and libraries needed for compilation:
[root@txy-server / usr/local/src] # cd gcc-9.1.0 [root@txy-server / usr/local/src/gcc-9.1.0] #. / contrib/download_prerequisites
1.2.3. Set up an output directory and put all the intermediate files in this directory:
[root@txy-server / usr/local/src/gcc-9.1.0] # mkdir gcc-build-9.1.0
1.2.4. Enter the newly created directory and complete the compilation configuration:
[root@txy-server / usr/local/src/gcc-9.1.0] # cd gcc-build-9.1.0 [root@txy-server / usr/local/src/gcc-9.1.0/gcc-build-9.1.0] #.. / configure-enable-checking=release-enable-languages=c,c++-disable-multilib
Parameter description:
-enable-languages: which languages are supported by gcc-disable-multilib: do not generate cross-compilers that are compiled into executable code for other platforms-disable-checking: the generated compiler does not make additional checks during compilation, or you can use-enable-checking=xxx to add some checks
1.2.5, and then you can compile and install:
[root@txy-server / usr/local/src/gcc-9.1.0/gcc-build-9.1.0] # make & & make installTips: this step will take a long time, about 1-2 hours
1.2.6. Create a software link to override the gcc-related commands under / usr/bin, because when compiling MySQL, you will go to the / usr/bin directory by default to find gcc-related commands:
[root@txy-server ~] # ln-sf / usr/local/bin/* / usr/bin/
1.2.7. Finally, verify whether the gcc version is 9.1.0. The following indicates that the installation is successful:
[root@txy-server ~] # gcc-vUsing built-in specs.COLLECT_GCC=gccCOLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-pc-linux-gnu/9.1.0/lto-wrapperTarget: x86_64-pc-linux-gnuConfigured with:.. / configure-enable-checking=release-enable-languages=c,c++-disable-multilibThread model: posixgcc version 9.1.0 (GCC) [root@txy-server ~] # 2, download MySQL source code package, decompress, compile and install
2.1. go to the official website of MySQL to download the address:
Https://dev.mysql.com/downloads/mysql/
2.2. Download link for copying source code package:
Download and decompress the source code package on Linux:
[root@txy-server ~] # cd / usr/local/src [root@txy-server / usr/local/src] # wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-boost-8.0.18.tar.gz[root@txy-server / usr/local/src] # tar-zxvf mysql-boost-8.0.18.tar.gz
2.4. Enter the decompressed directory and follow the command steps below to complete the compilation and installation:
# create a directory for data files [root@txy-server / usr/local/src] # mkdir-p / data/mysql [root@txy-server / usr/local/src] # cd mysql-8.0.18/# create a new directory and store the intermediate files generated by compilation. Because compiling [root@txy-server / usr/local/src/mysql-8.0.18] # mkdir builder [root@txy-server / usr/local/src/mysql-8.0.18] # cd builder/ [root@txy-server / usr/local/src/mysql-8.0.18/builder] # cmake3.. /-DCMAKE_INSTALL_PREFIX=/usr/local/mysql-DMYSQL_DATADIR=/data/mysql-DSYSCONFDIR=/etc-DMYSQL_ is not allowed in the source directory. USER=mysql-DWITH_MYISAM_STORAGE_ENGINE=1-DWITH_INNOBASE_STORAGE_ENGINE=1-DMYSQL_UNIX_ADDR=/tmp/mysql.sock-DMYSQL_TCP_PORT=3306-DEXTRA_CHARSETS=all-DDEFAULT_CHARSET=utf8mb4-DDEFAULT_COLLATION=utf8mb4_general_ci-DWITH_DEBUG=0-DMYSQL_MAINTAINER_MODE=0-DWITH_SYSTEMD=1-DDOWNLOAD_BOOST=1-DWITH_BOOST=../ boost [root @ txy-server / usr/local/src/mysql-8.0.18/builder] # make & & make installTips: it takes time to compile and install About 1-2 hours.
The parameters used by the cmake3 command describe:
-root directory of DCMAKE_INSTALL_PREFIX=/usr/local/mysql:MySQL installation-DMYSQL_DATADIR=/data/mysql: directory where data files are stored-DSYSCONFDIR=/etc: directory where MySQL configuration files are located-user name of DMYSQL_USER=mysql:MySQL service-DWITH_MYISAM_STORAGE_ENGINE=1: install MyISAM engine-DWITH_INNOBASE_STORAGE_ENGINE=1: install InnoDB engine-DWITH_ARCHIVE_STORAGE_ENGINE=1: install Archive engine-DWITH_MEMORY_STORAGE_ENGINE=1: install Memory guide Rock-DWITH_FEDERATED_STORAGE_ENGINE=1: install Federated engine-DWITH_PARTITION_STORAGE_ENGINE=1: install Partition engine-path to readline library-DMYSQL_UNIX_ADDR=/tmp/mysql.sock:sock file of DWITH_READLINE=1:MySQL-DMYSQL_TCP_PORT=3306: listening port of MySQL-DENABLED_LOCAL_INFILE=1: enable loading of local data-DENABLE_DOWNLOADS=1: allow independent download of related files at compile time-DEXTRA_CHARSETS=all: enable MySQL to support all extended characters- DDEFAULT_CHARSET=utf8mb4: set default character set to utf8mb4-DDEFAULT_COLLATION=utf8mb4_general_ci: set default character proofing-DWITH_DEBUG=0: disable debug mode-DMYSQL_MAINTAINER_MODE=0: whether to enable mysql maintainer-specific development environment-DDOWNLOAD_BOOST=1: allow online updates to the boost library-DWITH_BOOST=../boost: specify the boost installation path
You can query the parameters supported by cmake3 in the official website:
Https://dev.mysql.com/doc/refman/8.0/en/source-configuration-options.html
2.5. After the compilation and installation is complete, create the mysql user and change the owner of the corresponding directory:
[root@txy-server ~] # groupadd mysql [root@txy-server ~] # useradd-M-g mysql-s / sbin/nologin mysql [root@txy-server ~] # chown-R mysql:mysql / usr/local/mysql/ [root@txy-server ~] # chown-R mysql:mysql / data/mysql/
2.6. Edit the configuration file:
[root@txy-server ~] # vim / etc/ my.cnf [mysqld] basedir=/usr/local/mysqldatadir=/data/mysqlsocket=/tmp/ mysql.sock [mysqld _ safe] log-error=/var/log/mysqld/mysqld.logpid-file=/var/run/mysqld/mysql.pid
2.7. create a directory for log files and a directory for pid files, and grant rights to mysql users:
[root@txy-server ~] # mkdir-p / var/log/mysqld / var/run/mysqld [root@txy-server ~] # chown-R mysql:mysql / var/log/mysqld [root@txy-server ~] # chown-R mysql:mysql / var/run/mysqld
2.8.Configuring environment variables to facilitate the use of MySQL commands:
[root@txy-server ~] # vim / etc/profileexport MYSQL_HOME=/usr/local/mysqlexport PATH=$PATH:$MYSQL_HOME/ [root @ txy-server ~] # source / etc/profile [root@txy-server ~] # mysql-- version # verify whether the configuration is successful mysql Ver 8.0.18 for Linux on x86room64 (Source distribution) [root@txy-server ~] #
2.9. Execute the following command to initialize the database:
[root@txy-server] # mysqld-initialize-user=mysql-basedir=/usr/local/mysql/-datadir=/data/mysql
After successful initialization, the default password for the root account is generated, as shown in the following figure:
Copy and save the password because you need to log in to MySQL later to change the password
2.10. Copy the startup file generated by MySQL to the / usr/lib/systemd/system/ directory:
[root@txy-server ~] # cp / usr/local/src/mysql-8.0.18/builder/scripts/mysqld.service / usr/lib/systemd/system/ [root@txy-server ~] # chown 775 / usr/lib/systemd/system/mysqld.service
2.11. Use the systemctl command to start the MySQL service:
[root@txy-server ~] # systemctl start mysqld
2.12. Check whether port 3306 is listening properly:
[root@txy-server ~] # netstat-lntp | grep 3306tcp6 0 0: 33060: * LISTEN 27363/mysqldtcp6 0 0:: 3306: * LISTEN 27363/mysqld [root@txy-server ~] #
2.13. Log in to MySQL with the default password, reset the password and open remote login:
[root@txy-server ~] # mysql-uroot-pmXyfy/g8\) ausmysql > ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY' your_password'; # reset password mysql > use mysql;mysql > update user set host ='% 'where user='root'; # Open remote login mysql > FLUSH PRIVILEGES; # refresh modification
2.14. Use visualization tools to connect remotely to test whether the MySQL can be accessed normally:
End
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.