Compared with the traditional industry, MySQL has always been the main force of the database in the Internet tide. Whether it was SUN or Oracle now, although the business strategy may be different, the development direction is still stable. So it's embarrassing to say that I don't know MySQL.
I can only be regarded as a little white in MySQL. When graduate students finished their postgraduate program, they installed the windows version of MySQL, just like Oracle. But for a technology, without a thorough understanding of the principle of operation, they can not really understand this technology. Another way of saying is that similar technologies are interlinked and knowledge of principle nature can be reused for learning and understanding.
There happens to be a side project that uses MySQL to force myself to learn MySQL. In order to learn MySQL, we must first have a MySQL environment. The first step is installation. The installation mentioned here is definitely not the "next step" installation in Windows. Our environment is Linux 6.5, and we need to install MySQL version 5.7.19.
P.S. The following is just my own experience of learning, there are inaccuracies, but also invite you to point out.
There are two main ways to install MySQL. One is to use source code to compile and install MySQL. This is a unique scenic line of open source versus commercial closed source software. Another way is to use binary files, which can be divided into two kinds. One is to use. tar.gz compressed files to install, the other is to use. rpm files to install for a specific platform.
There are three ways to download links in the official website. Source Code, Linux-Generic and Red Hat Enterprise Linux/Oracle Linux correspond to source code installation, Linux-Generic correspond to. tar.gz and Red Hat Enterprise Linux/Oracle Linux correspond to.
This time I use rpm and source code, both ways to install.
1. rpm installation
First, we need to select the corresponding platform, digit, download the full version of RPM Bundle.
Unzip the installation package.
tar xvf mysql-5.7.19-1.el6.x86_64.rpm-bundle.tar
The basic installation requires only a few rpm packages, but there is a sequential requirement.
rpm -ivh mysql-community-common-5.7.19-1.el6.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.19-1.el6.x86_64.rpm(Depend on common)
rpm -ivh mysql-community-client-5.7.19-1.el6.x86_64.rpm(Depend on libs)
rpm -ivh mysql-community-server-5.7.19-1.el6.x86_64.rpm(Depend on client,common)
After installation, mysql users and groups are automatically created.
[root@RAC2 rb]# id mysql
uid=27(mysql) gid=11002(mysql) groups=11002(mysql)
Start the mysqld service, remember that it is not mysql, and port 3306 is opened by default.
[root@RAC2 mysql]# service mysqld start
Initializing MySQL database: test
[ OK ]
Starting mysqld: [ OK ]
[root@RAC2 mysql]# service mysqld status
mysqld (pid 30775) is running...
[root@DEPRAC2 mysql]# netstat -anp | grep 3306
tcp 0 0 :::3306 :::* LISTEN 30775/mysqld
The login prompt is wrong.
[root@RAC2 mysql]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
Referring to Mr. Zhou's book, this is because in the new version of MySQL 5.7, the security policy has been adjusted. By default, root can't have no password. When the database starts, it will automatically generate a password randomly for root. As you can see from the error log, note that the default path of error log is / var/log, and / etc/my.cnf is the default configuration file path. Path,
[root@RAC2 mysql]# cat /var/log/mysqld.log | more
2017-08-24T06:24:04.897029Z 1 [Note] A temporary password is generated for root@localhost: MDjfrXl;E9hp
The temporary strong password is "MDjfrXl;E9hp".
Log in again,
[root@RAC2 mysql]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.19
Copyright (c) 2000, 2017, 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>
Execute an error, prompting you to change your password to continue.
mysql> show variables like "%sock%";
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
General cryptographic strategies are considered to be non-conforming.
mysql> alter user 'root'@'localhost' identified by 'mysql';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> alter user 'root'@'localhost' identified by 'Mysql@admin';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> alter user 'root'@'localhost' identified by 'My@38@sql';
Query OK, 0 rows affected (0.01 sec)
At this point, any instructions can be executed.
mysql> select user from mysql.user;
+---------------+
| user |
+---------------+
| mysql.session |
| mysql.sys |
| root |
+---------------+
So far, the rpm installation has been completed.
If it is necessary to uninstall, the following instructions can be executed out of sequence.
rpm -e mysql-community-common-5.7.19-1.el6.x86_64 --nodeps
rpm -e mysql-community-client-5.7.19-1.el6.x86_64 --nodeps
rpm -e mysql-community-server-5.7.19-1.el6.x86_64 --nodeps
rpm -e mysql-community-libs-5.7.19-1.el6.x86_64 --nodeps
At this point, the / etc/my.cnf configuration file, mysql users and groups will be deleted.
2. Source installation
The whole process, for the first contact, is still more tortuous, especially in the middle of a variety of pits, need to be resolved one by one.
In Source Code, one is the version of src.rpm package and the other is tar.gz package. The former contains relatively complete components. We download this package.
Because this installation does not automatically complete the configuration like rpm, users need to be created first.
[root@RAC2 mysql-5.7.19]# groupadd mysql
[root@RAC2 mysql-5.7.19]# useradd -r -g mysql mysql
Where-r means that the user is a system user and cannot log on to the system.
Before the source code is installed, some auxiliary packages need to be installed.
yum install cmake
yum install bison
yum install libaio-devel*
Install src.rpm,
[root@RAC2 src]# rpm -ivh mysql-community-5.7.19-1.el6.src.rpm
warning: mysql-community-5.7.19-1.el6.src.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
1:mysql-community ########################################### [100%]
I didn't know at first that there was no unzipped folder in the local directory, and then I saw warning on it. I thought it was a mistake, but it wasn't.
Question 1: warning: mysql-community-5.7.19-1.el6.src.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
This error is due to the installation of the old version of GPG keys in yum. Some Posts suggest that rpm follow the -- force --nodeps parameter, or rpm --import /etc/pki/rpm-gpg/RPM*.
After the actual operation, the error is still found.
Reference official
https://dev.mysql.com/doc/refman/5.7/en/checking-gpg-signature.html
Copy the following as mysql_pubkey.asc,
Execute the gpg-import instruction.
[root@RAC2 src]# gpg --import mysql_pubkey.asc
gpg: directory `/root/.gnupg' created
gpg: new configuration file `/root/.gnupg/gpg.conf' created
gpg: WARNING: options in `/root/.gnupg/gpg.conf' are not yet active during this run
gpg: keyring `/root/.gnupg/secring.gpg' created
gpg: keyring `/root/.gnupg/pubring.gpg' created
gpg: /root/.gnupg/trustdb.gpg: trustdb created
gpg: key 5072E1F5: public key "MySQL Release Engineering <mysql-build@oss.oracle.com>" imported
gpg: Total number processed: 1
gpg: imported: 1
gpg: no ultimately trusted keys found
Execute export gpg--export
[root@RAC2 src]# gpg --export -a 5072e1f5 > 5072e1f5.asc
The official explanation for this is that
If you are using RPM 4.1 and it complains about
(GPG) NOT OK (MISSING KEYS: GPG#5072e1f5)
, even though you have imported the MySQL public build key into your own GPGkeyring, you need to import the key into the RPM keyringfirst. RPM 4.1 no longer uses your personal GPG keyring (or GPG itself). Rather, RPM maintains a separate keyring becauseit is a system-wide application and a user's GPG publickeyring is a user-specific file. To import the MySQL public key into the RPM keyring, first obtain the key, then use rpm --import to import the key.
RPM packages have built-in GPG signatures and MD5 validation. User and system level range problems require manual export and import operations.
If pubkey has not been imported before, executing export at this time will result in an error and no information needs to be exported.
[root@RAC2 src]# gpg --export -a 5072e1f5 > 5072e1f5.asc
gpg: WARNING: nothing exported
Execute the import.
[root@RAC2 src]# rpm --import 5072e1f5.asc
If pubkey has not been imported before, executing import at this time will result in an error and no information needs to be imported.
[root@RAC2 src]# rpm --import 5072e1f5.asc
error: 5072e1f5.asc: import read failed(0).
At this time, no mistake will be reported.
[root@RAC2 src]# rpm --checksig mysql-community-5.7.19-1.el6.src.rpm
mysql-community-5.7.19-1.el6.src.rpm: (sha1) dsa sha1 md5 gpg OK
[root@RAC2 src]# rpm -ivh mysql-community-5.7.19-1.el6.src.rpm
1:mysql-community ########################################### [100%]
Question 2: rpm... src. rpm, where is it installed?
Actually stored in the user's home directory, where root is used, the / root directory is used, and the folder structure is:
rpmbuild
| SOURCE
| SPECS
The content of the SOURCE path is:
[root@RAC2 SOURCES]# ls
boost_1_59_0.tar.bz2 filter-provides.sh filter-requires.sh mysql-5.1.72.tar.gz mysql-5.7.19.tar.gz
Unzip mysql-5.7.19.tar.gz, execute jar-jxvf boost_1_59_0.tar.bz2 to unzip the file, place mysql-5.7.19 path, and create debug folder to store the installed intermediate files.
Then there will be pits.
Referring to Mr. Zhou's book, the compiler environment is generated by CMake.
[root@RAC2 debug]# cmake .. -DBUILD_CONFIG=mysql_release \
> -DINSTALL_LAYOUT=STANDLONE \
> -DCMAKE_BUILD_TYPE=RelWithDebInfo \
> -DENABLE_DTRACE=OFF \
> -DWITH_EMBEDDED_SERVER=OFF \
> -DWITH_INNODB_MEMCACHED=ON \
> -DWITH_SSL=bundled \
> -DWITH_ZLIB=system \
> -DWITH_PAM=ON \
> -DCMAKE_INSTALL_PREFIX=/var/mysql \
> -DINSTALL_PLUGINDIR="/var/mysql/lib/plugin" \
> -DDEFAULT_CHARSET=utf-8 \
> -DDEFAULT_COLLATION=utf8_general_ci \
> -DWITH_EDITLINE=bundled \
> -DFEATURE_SET=community \
> -DCOMPILATION_COMMENT="MySQL Server(GPL)" \
> -DWITH_DEBUG=OFF \
> -DWITH_BOOST=..
CMake Error at CMakeLists.txt:21 (CMAKE_MINIMUM_REQUIRED):
CMake 2.8.2 or higher is required. You are running version 2.6.4
Error prompted. CMake version requires more than 2.8.2, currently only 2.6.4.
Download the high-level version of cmake, http://www.cmake.org/cmake/resources/software.html, decompress cmake-2.8.12.2.tar.gz, and execute in turn.
./bootstrap
make
make install
Some errors were reported.
[root@RAC2 cmake-2.8.12.2]# ./bootstrap
---------------------------------------------
CMake 2.8.12.2, Copyright 2000-2012 Kitware, Inc.
---------------------------------------------
Error when bootstrapping CMake:
Cannot find appropriate C compiler on this system.
Please specify one using environment variable CC.
See cmake_bootstrap.log for compilers attempted.
---------------------------------------------
Log of errors: /root/cmake-2.8.12.2/Bootstrap.cmk/cmake_bootstrap.log
---------------------------------------------
The compiler environment of cc is required, so we will install it.
[root@RAC2 cmake-2.8.12.2]# yum install gcc gcc-c++ make automake
Execution is completed.
[root@RAC2 cmake-2.8.12.2]# ./bootstrap
...
Curses libraries were not found. Curses GUI for CMake will not be built.
-- Looking for elf.h
-- Looking for elf.h - found
-- Looking for a Fortran compiler
-- Looking for a Fortran compiler - NOTFOUND
-- Found unsuitable Qt version "" from NOTFOUND
-- Performing Test run_pic_test
-- Performing Test run_pic_test - Success
-- Configuring done
-- Generating done
-- Build files have been written to: /root/cmake-2.8.12.2
---------------------------------------------
CMake has bootstrapped. Now run gmake.
Then execute the instructions make and make install, and you can see that it has been upgraded to the latest version.
[root@DEPRAC2 cmake-2.8.12.2]# ls -l /usr/local/bin/cmake
-rwxr-xr-x 1 root root 10204177 Aug 24 16:51 /usr/local/bin/cmake
[root@DEPRAC2 mysql-5.7.19]# /usr/local/bin/cmake -version
cmake version 2.8.12.2
When the above cmake is executed again, there are several mistakes. One is STANDLONE misspelled. It should be STANDALONE.
-- Packaging as: mysql-5.7.19-Linux-x86_64
CMake Error at cmake/install_layout.cmake:107 (MESSAGE):
Invalid INSTALL_LAYOUT parameter:STANDLONE. Choose between
RPM;DEB;SVR4;FREEBSD;GLIBC;OSX;TARGZ;SLES;STANDALONE
Call Stack (most recent call first):
CMakeLists.txt:213 (INCLUDE)
One is the character set utf-8, which should be written as utf8 (this error is reported when the database is initialized after installation). It needs to be corrected to re-execute the cmake instruction.
The other is,
-- Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH)
CMake Error at cmake/readline.cmake:64 (MESSAGE):
Curses library not found. Please install appropriate package,
remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
Call Stack (most recent call first):
cmake/readline.cmake:107 (FIND_CURSES)
cmake/readline.cmake:197 (MYSQL_USE_BUNDLED_EDITLINE)
CMakeLists.txt:519 (MYSQL_CHECK_EDITLINE)
Delete the original CMakeCache.txt and install ncurses-devel.
mv CMakeCache.txt CMakeCache.txt.k
yum install ncurses-devel*
Once again, Configuring done and Generating done appear, and the installation is complete.
-- CMAKE_C_FLAGS_RELWITHDEBINFO: -O3 -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -DDBUG_OFF
-- CMAKE_CXX_FLAGS_RELWITHDEBINFO: -O3 -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -DDBUG_OFF
-- Configuring done
-- Generating done
CMake Warning:
Manually-specified variables were not used by the project:
WITH_PAM
-- Build files have been written to: /root/rpmbuild/SOURCES/mysql-5.7.19/debug
Next, make-j 30 is executed, 30 threads are started and compiled. Otherwise, compilation is slow.
-j [jobs], --jobs[=jobs]
Specifies the number of jobs (commands) to run simultaneously. If there is more than one -j option, the last one is effective. If the -j option is given without an argument, make will not limit the number of jobs that can run simultaneously.
I ran into another pit where the disk space was full.
Linking CXX static library libsql.a
/usr/bin/ar: libsql.a: No space left on device
make[2]: *** [sql/libsql.a] Error 1
make[1]: *** [sql/CMakeFiles/sql.dir/all] Error 2
Because it is placed under / root by default, its mv is put on the free disk and executed again, prompting 100% to complete.
[100%] Building CXX object sql/CMakeFiles/udf_example.dir/udf_example.cc.o
Linking CXX shared module udf_example.so
[100%] Built target udf_example
[100%] Built target pfs_connect_attr-t
Execute make install,
-- Installing: /var/mysql/mysql-test/lib/My/SafeProcess/Base.pm
-- Installing: /var/mysql/support-files/mysqld_multi.server
-- Installing: /var/mysql/support-files/mysql-log-rotate
-- Installing: /var/mysql/support-files/magic
-- Installing: /var/mysql/share/aclocal/mysql.m4
-- Installing: /var/mysql/support-files/mysql.server
The database is installed in / var/mysql by default.
Edit the configuration file my.cnf,
[mysqld]
port=3306
datadir=/DATA/mysql/data_3306
log_error=/DATA/mysql/data_3306/error.log
basedir=/DATA/mysql
Create a database and specify users using mysql.
[root@RAC2 mysql]# /var/mysql/bin/mysqld --defaults-file=/DATA/mysql/my.cnf --initialize --user=mysql
At this point, you can see that the owner of the / DATA/mysql/data_3306 directory is mysql.
Start the database. Notice that it's not mysqld, but mysql.
[root@RAC2 mysql]# /var/mysql/bin/mysql --defaults-file=/DATA/mysql/my.cnf --user=mysql
View processes, ports,
[root@RAC2 data_3306]# ps -ef | grep mysql
mysql 26428 23453 0 18:56 pts/2 00:00:00 /var/mysql/bin/mysqld --defaults-file=/DATA/mysql/my.cnf --user=mysql
root 26527 29090 0 19:08 pts/1 00:00:00 grep mysql
[root@DEPRAC2 data_3306]# netstat -anp | grep 3306
tcp 0 0 :::3306 :::* LISTEN 26428/mysqld
Next, the same as the rpm installation, find the temporary password from the error log, log in and change the password, and complete the database initialization. Note that the error log is stored in the log_error=/DATA/mysql/data_3306/error.log defined by the configuration file.
Conclusion:
1. rpm installation, similar to Windows installation, is really simple and easy to use.
2. Source code installation, the process is more cumbersome, and encountered many pits, but this way, you can contact more, learn a lot of things, still worth recommending.
Of course, I just learned a little here, MySQL is still more profound, there are many places to learn, step by step, there may be opportunities in front of us.
Reference:
1. MySQL Operations and Maintenance Reference
2. MySQL Official Reference
https://dev.mysql.com/doc/refman/5.7/en/checking-rpm-signature.html
https://dev.mysql.com/doc/refman/5.7/en/linux-installation-rpm.html
https://dev.mysql.com/doc/refman/5.7/en/installing-source-distribution.html
If you think this article is helpful to you, you are welcome to pay attention to the Wechat Public Number: bisal's personal grocery store, your support is my greatest encouragement! Learn together and make progress together.