The method of installing the MySQL source pack in Linux CentOS6.6 system _linux

Source: Internet
Author: User
Tags md5 pack

Here in the CentOS6.6 system to install the MySQL source code package, to explain.

1. mysql Source package download

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

After opening this download address, in "Select Version:", select the version of MySQL to download, I chose 5.6.34; In "Select Platform:", choose the applicable operating system type, because it is the download source package, so here we want to select source Code.

After that, the installation package for each system is displayed (oddly, there are many RPM packages in the list), but we are not using the RPM package to install MySQL. Here we choose Generic Linux (architecture independent), compressed TAR Archive, there is a download button on its far right, click on it to find the download link.

If you still don't, just use the download address I've found: http://101.110.118.70/dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.34.tar.gz direct use wget command to download.

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 do not have a wget command on your Linux system, you can use Yum-y install wget to install wget first)

In the Linux root directory, create a multilevel empty directory/my_package/source to store the downloaded source package.

Mkdir-p/my_package/source
Cd/my_package/source

Execute download command:

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

After the download is complete, in the directory/my_package/source, has the MySQL source code package mysql-5.6.34.tar.gz

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

Md5sum./mysql-5.6.34.tar.gz

After the command is executed, a MD5 checksum value is generated, and the value is manually compared to the MD5 value given by the source package download page, which, if consistent, indicates that the installation package is intact (you can also not check it, of course).

2. mysql source package installation and configuration

Starting from the mysql5.5 version, the source code installed MySQL need to use the CMake command.

Check to see if your Linux system has CMake installed, use the following command to check:

Whereis CMake

If the CMake command is installed, the absolute path to the CMake command and the absolute path to the CMake command Help manual are displayed. Otherwise, the CMake command is not installed.

Here, use the Yum tool to quickly install CMake online, as follows:

Yum Search CMake
yum-y Install cmake.i686

You also need to install Bison, GCC, gcc-c++, and ncurses, and install them quickly with the Yum tool:

Yum-y Install Bison
yum-y install gcc gcc-c++ ncurses

After the preparation is done, and then to install MySQL, the following is a detailed description of MySQL installation steps.

(1) Create user groups and system users

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

Groupadd MySQL
useradd-r-g mysql-s/bin/false MySQL

(2) Decompression source compression Package

TAR-ZXVF mysql-5.6.34.tar.gz
CD mysql-5.6.34

After the decompression, into the unpacked directory. In general, the directory will have the Readme (about the description of the package) and install (installation instructions), these two files. Of course, you can also not refer to its installation instructions.

(3) Installation parameters configuration, compilation and installation

You can use the CMake command to set some installation parameters (such as installation path, etc.), where we use the default configuration, and then compile make, after the compilation is complete, perform the installation process made install.

CMake.
Make make
Install

(4) MySQL Data directory initialization

After the installation process is completed, a folder MySQL is automatically generated in the/usr/local/directory, which means that/usr/local/mysql is the default installation directory for MySQL.
Now, we need to do some initialization of MySQL, such as: Initializing the Data directory, initializing the MySQL system table, initializing 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

Description: scripts/mysql_install_db is the initialization command for MySQL. The owner and the owning group of the directory/usr/local/mysql are changed to MySQL before the command is initialized, the owner of the directory/usr/local/mysql is changed to root after the command is initialized, and then the/usr/local/mysql/data The owner of the directory changed to MySQL.

Note: A configuration file my.cnf is automatically generated in the/usr/local/mysql directory after the initialization operation is completed. If the system does not have my.cnf files in other locations, when you start MySQL, the default is to start with/USR/LOCAL/MYSQL/MY.CNF as a configuration file. Otherwise, you need to manually specify the configuration file to use.
Of course, the best way to do this is to remove my.cnf from other locations.

We will find that in the Linux system's configuration file directory/etc, there is already a my.cnf file, in order to prevent conflicts, we delete it (in fact, the initialization of the operation is completed, will also give such a hint).

Rm-f/etc/my.cnf

(5) Start and close MySQL service

Manually start MySQL:

Cd/usr/local/mysql
bin/mysqld_safe--user=mysql &

After startup, use the command below to detect if MySQL has started successfully

Netstat-tlunp

Or

PS aux | grep MySQL

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

Vi/usr/local/mysql/data/localhost.localdomain.err

Based on the specific error message, after resolving the problem, restart MySQL.

To turn off MySQL:

./bin/mysqladmin-u root-p Shutdown

For convenience, add the MySQL bin directory to the Linux system's environment variable path in the following ways:

Export Path=/usr/local/mysql/bin: $PATH

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

(6) Common errors and solutions

Error 1: Unable to connect to MySQL locally

When the MySQL service was successfully started, it was found that MySQL could not be connected locally, that is, when using command mysql-uroot-p locally, an error message "-bash:mysql:command not Found" appears. If you have determined that the MySQL command exists and is accessing the correct way, but the error message still appears, it is most likely that the absolute path to the socket socket file is not explicitly specified.

Workaround:

To modify the MySQL configuration file/usr/local/mysql/my.cnf, add the following code:

[Client]
Socket=/tmp/mysql.sock

That is, in the configuration file, explicitly specify the location of the socket socket. The Mysql.sock file is automatically generated when the MySQL service is started. If you do not know its specific path, you can use the command Find/-name mysql.sock to search.

After modifying the MySQL configuration file, turn off the MySQL service and then reopen the MySQL service. Try the local MySQL connection again, generally no problem.

Error 2: Unable to connect to MySQL remotely

There is no problem connecting to MySQL locally, but connecting to MySQL on other computers will not connect to MySQL even with the same username (such as root) and password.

This is because, for security reasons, the MySQL server for Linux systems only allows you to log on to the database server locally.

MySQL server, there is a system database, named MySQL, the library has a user data table, the user table has many fields, such as: host, user, password and permission fields, and so on. MySQL server, which controls the operation rights of individual users.

So, as long as you modify the data on the table or add an authorization record to the table, it's OK.

Workaround:

First of all, we are not anxious to solve the problem, first look at the cause of the problem. Log on to the root user locally and view the record information for 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 will find that the value of the host column for all users (including root) is basically localhost or 127.0.0.1, which means that MySQL is only allowed to log on and operate locally from the default. It can be proved that the above analysis is correct.

Then we'll solve the problem. Assigns all operation permissions to the specified user and allows them to log on and operate the MySQL server from other computers. In general, you can complete the authorization and resolve the problem by executing only the following commands:

GRANT all privileges in *.* to ' root ' @ '% ' identified by ';

When the above command is done, a new authorization record is added to the Mysql.user table. Since then, we can also log on to the Linux MySQL server from other remote computers.

If you still have a problem, you can execute the command: Flush privileges; The purpose of this command is to take immediate effect of the newly-added authorization record (which is not normally performed).

Perhaps a lot of people do not understand just the authorization order, here, I explain in detail, so that everyone can flexibly use the command to authorize.

All privileges: Specifies that all permissions are assigned to the specified user, mainly including adding, deleting, changing, checking and so on.

On *.*: Indicates that the specified user can operate on all data tables for all databases, and if you want to specify a database's specified datasheet, you can replace it with the on database name. data table name.

To ' root ': Indicates that the root user is assigned operation rights, and if you want to assign permissions to other users, you can change root to a different user name.

@ '% ': Indicates that all client IP access is allowed. In other words,% means that the client's IP address is not restricted. If you want to limit the IP address of the client, you can replace the% with the specified IP address.

Identified by ": represents the password of the authorized user. Since I am assigning permissions to the root user, and the root password defaults to null, I am using an empty string.

(7) Set the root user's initial password

MySQL root user default is no password, here set the root user's initial password is 123456. The following command is executed:

mysqladmin-u root password ' 123456 '

Of course, you can also leave the root user with no password. For security reasons, however, it is recommended that you set an initial password for the root user.

(8) Add the MySQL service to the system service

The MySQL service is added to the system service to enable you to quickly start or shut down the MySQL service through system services. The method is as follows:

Cd/usr/local/mysql
CP Support-files/mysql.server/etc/init.d/mysql.server

This allows you to start and turn off the MySQL service in a new way.

Start MySQL service: Service mysql.server start

Turn off MySQL service: Service mysql.server stop

Restart MySQL Service: Service mysql.server restart

Of course, the previous command mode (startup and shutdown) is still valid.

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

(9) The MySQL service is set to boot automatically

There are a number of ways to set up a MySQL service to boot automatically, and here you can only introduce modifications

The way to/etc/rc.d/rc.local files.

can also modify/etc/rc.local this file,/etc/rc.local is actually/etc/rc.d/rc.local file soft link, the equivalent of shortcuts, the file will be automatically after the system boot.

You can set the MySQL service to boot by simply executing the following command:

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

The above command indicates that the string "/usr/local/mysql/bin/mysqld_safe–user=mysql &" is written to the/etc/rc.d/rc.local file in an append way.

So, to turn off MySQL from boot, just edit the file and delete the string you just wrote.

The above is a small series to introduce the Linux CentOS6.6 system installed MySQL source code package method, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.