Method for installing the mysql source package in Linux CentOS6.6 system

  • 2020-05-13 04:13:24
  • OfStack

Here to CentOS6.6 system installed MySQL source package, explain.

1. Download the mysql source package

mysql installation package is the official download address: http: / / dev mysql. com/downloads/mysql / 5.6 html # downloads

After opening the download address, at "Select Version:", select the version of mysql to be downloaded. I chose 5.6.34; At "Select Platform:", select the appropriate operating system type. Since we are downloading the source package, we will select Source Code.

After that, the installation packages for each system are displayed (oddly enough, there are a lot of rpm packages in this list), but we're not using the rpm package to install mysql. Here we select Generic Linux (Architecture Independent), Compressed TAR Archive, and there is an Download button on the far right, click it to find the download link.

If you still can't directly use the download address: I have found http: / / 101.110.118.70 dev mysql. com get/Downloads/MySQL - 5.6 / mysql - 5.6.34. tar. gz use wget command to download it directly.

If you know the specific address of the mysql source package, you can download it directly from the linux system using the wget command.
(note: if you don't already have the wget command on your linux system, you can use yum-y install wget to install wget)

In the root directory of linux, create a multilevel empty directory /my_package/source to hold the downloaded source packages.


mkdir -p /my_package/source
cd /my_package/source

Execute the download command:


wget http://101.110.118.70/dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.34.tar.gz

Once the download is complete, the mysql source package mysql-5.6.34.tar.gz is available in the directory /my_package/source

You can then verify the integrity of the installation package with MD5, using the following command:


md5sum ./mysql-5.6.34.tar.gz

After executing this command, a check value of md5 is generated, which is manually compared with the value of md5 given in the source package download page. If the value is 1, then the installation package is complete (you may not check it, of course).

2. Installation and configuration of mysql source package

Starting with mysql5.5, the mysql command is used to install mysql source code.

To check if cmake is installed on your linux system, use the following command:


whereis cmake

If the cmake command is installed, the absolute path of the cmake command and the absolute path of the cmake command help manual are displayed. Otherwise, the cmake command is not installed.

Here, use the yum tool to quickly install cmake online. The method is as follows:


yum search cmake
yum -y install cmake.i686

You also need to install bison, gcc, gcc-c ++, and ncurses, also using the yum tool:


yum -y install bison
yum -y install gcc gcc-c++ ncurses

After the above preparations are completed, we will install mysql. The following steps will be used to introduce the installation of mysql in detail.

(1) create user groups and system users

For security reasons, you need to create a user group named mysql, and then create a system user mysql belonging to that user group, which is used to install and run the MySQL service.


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

(2) extract source compression package


tar -zxvf mysql-5.6.34.tar.gz
cd mysql-5.6.34

After the completion of decompression, enter the decompression of the directory. In general, this directory will have README (an introduction to the package) and INSTALL (installation instructions) files. Of course, you can also do without referring to the installation instructions.

(3) configuration, compilation and installation of installation parameters

You can use the cmake command to set some installation parameters (such as the installation path, etc.). Here we use the default configuration and then compile make. Once the compilation is complete, the installation process make install is performed.


cmake .
make
make install

(4) initialization of MySQL data directory

After the installation process is completed, a folder mysql is automatically generated in the /usr/local/ directory. That is, /usr/local/mysql is the default installation directory for MySQL.
Now, we need to do some initialization for MySQL, such as: initialize the data directory, initialize the MySQL system table, initialize a configuration file my.cnf, and so on.


cd /usr/local/mysql
chown -R mysql .
chgrp -R mysql .
scripts/mysql_install_db --user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data 
chown -R root .
chown -R mysql data

Note: scripts/mysql_install_db is the initialization command for MySQL. Before initializing the command, change the owner and group of directory /usr/local/mysql to mysql; In order to initialize, will be the owner of the directory/usr local/mysql change to root, then will/usr/local/mysql/data owner to mysql instead.

Note: once the initialization operation is completed, a configuration file my.cnf is automatically generated in the /usr/local/mysql directory. . If the system of other location without my cnf file, start MySQL, will default to/usr local/mysql/my cnf started as a configuration file. Otherwise, you need to manually specify the configuration file to use.
Of course, the best thing to do is to delete my.cnf in another location.

We will find that one my.cnf file already exists in the configuration file directory /etc of the linux system, and we will delete it to prevent conflicts (in fact, we will give the same prompt after the initialization operation is completed).


wget http://101.110.118.70/dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.34.tar.gz
0

(5) start and close MySQL service

Manually starting MySQL:


wget http://101.110.118.70/dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.34.tar.gz
1

When the boot is complete, use the following command to check if MySQL started successfully


wget http://101.110.118.70/dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.34.tar.gz
2

or


ps aux | grep mysql

If MySQL does not start successfully, check the error log 1:


wget http://101.110.118.70/dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.34.tar.gz
4

After the problem is resolved, restart MySQL based on the specific error message.

Close the MySQL:


wget http://101.110.118.70/dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.34.tar.gz
5

For convenience, the mysql bin directory is added to the PATH environment variable of the linux system as follows:


wget http://101.110.118.70/dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.34.tar.gz
6

In this way, we can use directly in any directory/usr local mysql/bin commands in the directory, and don't have to take an absolute path, or don't have to switch to this directory.

(6) common mistakes and solutions

Error 1: unable to connect mysql locally

When the MySQL service was successfully started, it was found that mysql could not be connected locally, that is, when the command mysql-uroot-p was used locally, the error message "-bash: mysql: command not found" was found. If the mysql command has been determined to exist and to be accessed correctly, but this error message still occurs, it is likely that the absolute path to the socket socket file was not explicitly specified.

Solutions:

Modify the configuration files of the mysql/usr/local/mysql/my cnf, add the following code:


wget http://101.110.118.70/dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.34.tar.gz
7

That is, in the configuration file, specify the location of the socket socket. The mysql.sock file will be generated automatically after the MySQL service starts. If you don't know its exact path, you can find it using the command find / -name mysql.sock.

After modifying the mysql configuration file, close the MySQL service, and then restart the MySQL service. Try connecting mysql locally, and 1 will be fine.

Error 2: unable to connect mysql remotely

There is no problem connecting mysql locally, but if you connect mysql on another computer, you cannot connect mysql even with the same username (root) and password.

This is because the mysql server on the linux system only allows local login to the database server by default for security reasons.

In the mysql server, there is a system database named mysql, in which there is an user data table, and an user table with many fields, such as: host, user, password and permission fields. The mysql server, which controls the operation permissions of individual users through this table.

So, just modify the table's data or add an authorization record to the table.

Solutions:

First of all, we are not in a hurry to solve the problem, first look at the cause of the problem. Log on to the root user locally to view the record information of the user table in the mysql database.


mysql -uroot -p
show databases;
use mysql;
show tables;
select host,user,password from user;

At this point, we find that the value of the host column for all users (including root) is basically localhost or 127.0.0.1, which means that by default mysql is only allowed to log in and operate locally. It can be proved that the above analysis is correct.

Then, let's solve the problem. Assign all access rights to the specified user and allow him or her to log in and operate the MySQL server from another computer. 1 in general, authorization can be completed and the problem solved by simply executing the following command:


wget http://101.110.118.70/dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.34.tar.gz
9

After the above command is executed, an authorization record is added to the mysql.user table. After that, we can log in to the MySQL server from another remote computer.

If there is still a problem, you can follow the command: flush privileges; The effect of this command is to make the newly added authorization record take effect immediately (1 normally does not need to execute this command).

Many of you may not understand the authorization command just now, but I'm going to elaborate here so that you can use it flexibly.

ALL PRIVILEGES: means to assign all permissions to the specified user, mainly including add, delete, change, check and so on.

ON *.* : indicates that the specified user can operate on all data tables of all databases. If you want to change to the specified data table of the specified database, you can use "ON database name. Data table name" instead.

TO 'root' : means to assign operation permissions to root users. If you want to assign permissions to other users, you can change root to another user name.

@'%' : means all clients are allowed to access IP. That is, % means the client's IP address is not restricted. If you want to restrict the client's IP address, you can replace % with the specified IP address.

IDENTIFIED BY ": represents the password of the authorized user. Since I'm assigning permissions to an root user, and the password for an root user is empty by default, I'm using an empty string.

(7) set the initial password of root user

mysql's root user has no password by default, and the initial password for root user is set to 123456. Execute the following command:

mysqladmin -u root password '123456'

Of course, you can also leave root user 1 without a password. To be on the safe side, however, it is recommended to give root users an initial password.

(8) add the mysql service to the system service

The mysql service is added to the system service so that the mysql service can be quickly started or shut down later through the system service. The method is as follows:


cd /usr/local/mysql
cp support-files/mysql.server /etc/init.d/mysql.server

This way, you can start and stop the mysql service in the new way.

Start mysql service: service mysql.server start

Shut down mysql service: service mysql.server stop

Restart mysql service: service mysql.server restart

Of course, the old command mode (startup and shutdown) still works.


mysqld_safe --user=mysql &
mysqladmin -u root -p shutdown

(9) set mysql service to boot automatically

There are many ways to set the mysql service to boot automatically, but only modifications are covered here

/ etc rc. d/rc. local file.

Can modify/etc/rc local this file, / etc/rc local is/etc/rc d/rc local file soft links, equivalent to a shortcut, the file will be automatically after system boot.

Simply execute the following command to set the mysql service to boot automatically:


echo "/usr/local/mysql/bin/mysqld_safe --user=mysql &" >> /etc/rc.d/rc.local

The above command, said the string "/ usr/local/mysql bin/mysqld_safe � user = mysql &" written in the form of additional/etc/rc d/rc local file.

As a result, to turn mysql's boot off, simply edit the file and delete the string you just wrote.


Related articles: