Summary of Several Installation Methods and Configuration Problems of MySQL

  • 2021-08-28 21:25:09
  • OfStack

1. MySQL rpm package installation


#  Download the installation source 
[root@localhost src]# wget https://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
#  Installation source 
[root@localhost src]# rpm -ivh mysql-community-release-el7-5.noarch.rpm

2. MySQL yum tool installation


[root@localhost /]# yum install -y mysql-community-server
#  View the file path after installation 
[root@localhost /]# which mysql mysqld_safe mysqlbinlog mysqldump
/usr/bin/mysql
/usr/bin/mysqld_safe
/usr/bin/mysqlbinlog
/usr/bin/mysqldump

To see a detailed list of files included in each installation package, you can use "rpm-ql Software Name", which lists the file list and installation location of the current rpm package. As follows:


[root@localhost /]# rpm -ql openssl
/etc/pki/tls/misc/c_hash
/etc/pki/tls/misc/c_info
/etc/pki/tls/misc/c_issuer
/etc/pki/tls/misc/c_name
/usr/bin/openssl
/usr/share/doc/openssl-1.0.1e
/usr/share/doc/openssl-1.0.1e/CHANGES
.......

3. MySQL source code installation


#  Install the packages required for compilation 
[root@localhost src]# yum install -y make gcc-c++ cmake bison-devel ncurses-devel gcc autoconf automake zlib* fiex* libxml*
#  Download source code 
[root@localhost src]# wget https://cdn.mysql.com//archives/mysql-5.6/mysql-5.6.24.tar.gz
#  Decompress source package 
[root@localhost src]# tar xvf mysql-5.6.24.tar.gz
[root@localhost src]# cd mysql-5.6.24
#  Compile configuration, this process will take time 3~5 Minutes 
[root@localhost mysql-5.6.24]# cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DMYSQL_UNIX_ADDR=/tmp/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
#  Compile and install 
#  The compilation process approximately requires 30~50 Minutes 
[root@localhost mysql-5.6.24]# make
[root@localhost mysql-5.6.24]# make install
#  Settings MySQL Users and Groups 
[root@localhost mysql-5.6.24]# groupadd mysql
[root@localhost mysql-5.6.24]# useradd -r -g mysql mysql
[root@localhost mysql-5.6.24]# cd /usr/local/mysql/
#  Set permissions so that mysql Can modify files 
[root@localhost mysql]# chown -R mysql:mysql ./
[root@localhost mysql]# chown -R mysql:mysql /data/mysql/data
#  Initialize the database 
#  It should be noted that the data directory set here should be the same as the previous MYSQL_DATADIR The specified directory is the same 
[root@localhost mysql]# scripts/mysql_install_db --user=mysql -ldata=/data/mysql/data
#  Restore the permission settings and modify the permissions of the corresponding directories so that mysql Modify 
[root@localhost mysql]# chown -R root ./
[root@localhost mysql]# chown -R mysql data

The above example represents installing MySQL software into the/usr/local/mysql directory. The parameters used in this example and their meanings are as follows:

DCMAKE_INSTALL_PREFIX: Indicates where to install MySQL, in this case in the directory /usr/local/mysql;

DMYSQL_DATADIR: Indicates the data file storage directory of MySQL; DSYSCONFDIR: Directory where configuration files are located;

DWITH_MYISAM_STORAGE_ENGINE: Compile the MyISAM storage engine into the service;

DWITH_INNOBASE_STORAGE_ENGINE: Compile the InnoDB storage engine into the service; DMYSQL_UNIX_ADDR:

DMYSQL_TCP_PORT: The port used by default; DENABLED_LOCAL_INFILE: Specifies whether to allow local execution of LOAD DATA

INFILE; DWITH_PARTITION_STORAGE_ENGINE: Compile partition engine into service;

DEXTRA_CHARSETS: Let the service support all extended character sets; DDEFAULT_CHARSET: The default character set used by the service, set here to

UTF8; DDEFAULT_COLLATION: The default collation.

There are many parameters when compiling and installing MySQL. The detailed meaning and description of these parameters can be found on the official website: http://dev.mysql.com/doc/refman/5. 5/en/source-configuration-options.html

The role of the installed dependency package:

gcc/g + +: MySQL 5.6 starts and needs to be compiled using g + +; cmake: MySQL 5.5 starts, cmake is used for project management, and cmake needs more than 2.8 versions; bison: The MySQL parser needs to be compiled using bison; ncurses-devel: Development kit for terminal operations; zlib: MySQL uses zlib for compression; libxml: Support for XML input and output mode; openssl: Communication using openssl Secure Sockets;

dtrace: Used to diagnose MySQL problems.

It is not enough to complete the above installation steps. You need to add configuration options, start and stop scripts, and so on for MySQL.


cd /usr/local/mysql/
# Remove comment lines from configuration file and display only valid lines 
grep -v "^#" my.cnf
# Put the startup script into the /etc/init.d In the directory 
cp support-files/mysql.server /etc/init.d/mysqld
# Will mysql Add as a system service 
chkconfig --add mysqld
service mysqld start
# At this time MySQL Adj. root The user does not have a password yet, so you should set a password for it 
/usr/local/mysql/bin/mysql -u root -h 192.168.146.150 -p
# Since the password has not been set, press it directly Enter Key will do 
# Settings root The user's password is 888888
set password = password('888888');
# Enter after setting quit Quit 
quit

Attachment: Summary of problems during installation

1,-bash: mysql: command not found

Because the path of the mysql command is under/usr/local/mysql/bin, when you use the mysql command directly, the system looks up this command under/usr/bin, so it cannot be found.

Solution: Use the following command to make a link


ln -s /usr/local/mysql/bin/mysql /usr/bin

2. Starting MySQL.. The server quit without updating PID file ([FAILED]/mysql/Server03. mylinux. com. pid).

Solution:

Modify datadir in/etc/my. cnf to point to the correct mysql database file directory

3. ERROR 2002 (HY000): Can 't connect to local MySQL server through socket'/tmp/mysql. sock '(2)

Solution:

Create a new link or add-S parameter in mysql to directly indicate the position of mysql. sock.


ln -s /usr/local/mysql/data/mysql.sock /tmp/mysql.sock
/usr/local/mysql/bin/mysql -u root -S /usr/local/mysql/data/mysql.sock

Related articles: