English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Linux CentOS6.6Methods to Install MySQL Source Package in System

Here we take CentOS6.6Explain how to install MySQL source code packages in the system.

1. Download of MySQL source code package

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

After opening the download address, select the version of MySQL you want to download at the 'Select Version:' option. I choose5.6.34; At the 'Select Platform:' option, select the appropriate operating system type. Since it is a source code package, we need to select Source Code here.

After that, it will display installation packages suitable for various systems (it's strange that there are many rpm packages in this list), but here we are not using rpm packages to install MySQL. We choose Generic Linux (Architecture Independent), Compressed TAR Archive, and there is a Download button on the rightmost side of it. Click it to find the download link.

If you still don't know how to do it, just 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 you can directly download it using the wget command.

If you know the specific address of the MySQL source code package, you can directly use the wget command in the Linux system to download it.
(Note: If the wget command is not available in your Linux system, you can use yum) -y install wget, first install wget)

Create a multi-level empty directory in the root directory of Linux /my_package/source is used to store the downloaded source code 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

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

Then, you can perform MD5checksum, that is, use the following command:

md5sum ./mysql-5.6.34.tar.gz

After executing this command, a md5The checksum value, and compare this value with the md5The value for manual comparison, if consistent, it means that the installation package is complete and intact (of course, you can also not verify).

2. Installation and configuration of mysql source code package

From mysql5.5From version, the source code installation of mysql needs to use the cmake command.

To check if cmake is installed on your Linux system, you can use the following command to check:

whereis cmake

If the cmake command is installed, it will display the absolute path of the cmake command and the absolute path of the cmake command help manual. Otherwise, it means that the cmake command is not installed.

Here, use the yum tool to install cmake online quickly, 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 use the yum tool to install quickly:

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

After the above preparation is done, let's install mysql next, and here we will introduce the installation steps of mysql in detail.

(1Create user group and system user

For security reasons, it is necessary to create a group named mysql and then create a system user mysql belonging to this group, the role of this system user is to install and run the MySQL service.

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

(2Unpack the source code compressed package

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

After unpacking, enter the unpacked directory. Generally, this directory will have README (introduction and description of the software package) and INSTALL (installation instructions), these two files. Of course, you can also not refer to its installation instructions.

(3Installation parameters configuration, compilation and installation

You can use the cmake command to set some installation parameters (such as installation path), here we use the default configuration, and then compile make, after the compilation is completed, execute the installation process make install.

cmake .
make
make install

(4MySQL data directory initialization

After the installation process is completed, it will be /usr/local/ In the catalog, an automatic folder named mysql is generated, that is to say,/usr/local/mysql is the default installation directory of MySQL.
Now, we need to perform some initialization operations on MySQL, such as: initializing the data directory, initializing the MySQL system tables, initializing a configuration file my.cnf, etc.

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 of MySQL. Before the initialization command, the directory /usr/local/The owner and group of mysql are changed to mysql; after the initialization command, the directory /usr/local/The owner of mysql is changed to root, and then the /usr/local/mysql/The owner of the data directory is changed to mysql.

Note: After the above initialization operation is completed, it will be /usr/local/A configuration file my.cnf is automatically generated in the mysql directory. If there is no my.cnf file in other locations of the system, MySQL will start with the default configuration when starting MySQL. /usr/local/mysql/my.cnf as a configuration file to start. Otherwise, you need to manually specify the configuration file to be used.
Of course, the best way is to delete the my.cnf in other locations.

We will find that in the configuration file directory of the Linux system /There is already a my.cnf file in the etc directory, so to prevent conflicts, we delete it (in fact, such a prompt will also be given after the initialization operation is completed).

rm -f /etc/my.cnf

(5)Start and stop MySQL service

Manually start MySQL:

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

After the start is complete, use the following command to check if MySQL has started successfully

netstat -tlunp

Or

ps aux | grep mysql

If MySQL is not started successfully, check the error log:

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

According to the specific error information, solve the problem and restart MySQL after the problem is solved.

Shutdown MySQL:

./bin/mysqladmin -u root -p shutdown

For convenience, add the mysql bin directory to the environment variable PATH of the Linux system, as follows:

export PATH=/usr/local/mysql/bin:$PATH

In this way, we can use it directly in any directory /usr/local/mysql/The commands in the bin directory, without having to specify the absolute path, or without having to switch to the directory.

(6)Common errors and solutions

Error1 : Unable to connect to mysql locally

After the MySQL service is successfully started, it is found that it is impossible to connect to mysql locally, that is, to use the command mysql locally -uroot -p 时,却出现错误信息“-bash: mysql: command not found. If you have confirmed that the mysql command exists and the access method is correct, but still get this error message, it is very likely that the absolute path of the socket socket file has not been explicitly specified.

Solution:

Modify the MySQL configuration file /usr/local/mysql/Add the following code to my.cnf:

[client]
socket=/tmp/mysql.sock

That is to say, in the configuration file, explicitly specify the location of the socket socket. The mysql.sock file will be automatically generated after the MySQL service starts. If you are not clear about its specific path, you can use the command find / -name mysql.sock, to search for it.

After modifying the MySQL configuration file, shut down the MySQL service, then restart the MySQL service. Try to connect to MySQL locally again, and there should be no problem.

Error2: Unable to connect to MySQL remotely

There is no problem to connect to MySQL locally, but when connecting to MySQL from other computers, even if the same username (such as: root) and password are used, it is still impossible to connect to MySQL.

This is because, for security reasons, the MySQL server of the Linux system only allows local login to the database server by default.

In the MySQL server, there is a system database named mysql, which contains a user data table. The user table has many fields, such as: host, user, password, and permission fields, etc. The MySQL server controls the operation permissions of each user through this table.

Therefore, just modify the data of the table or add a new authorization record in the table is enough.

Solution:

Firstly, we don't rush to solve the problem, but let's look at the cause of the problem first. Log in as the root user locally and check 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 time, we will find that the host column values of all users (including root) are basically localhost or127.0.0.1That is to say, by default, only local login and operation on mysql are allowed. It can be proven that the above analysis is correct.

Then, let's solve the problem. Assign all operation permissions to the specified user and allow them to log in and operate on the MySQL server from other computers. Generally, executing the following command below can complete the authorization and solve the problem:

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '';

After executing the above command, a new authorization record will be added to the mysql.user table. From then on, we can also log in to this Linux MySQL server from other computers remotely.

If there are still problems, you can execute the command: flush privileges; The command makes the newly added authorization record take effect immediately (usually this command does not need to be executed).

Many people may not understand the authorization command just mentioned. Here, I will give a detailed explanation so that everyone can use the command flexibly for authorization.

ALL PRIVILEGES: indicates that all permissions are assigned to the specified user, mainly including add, delete, modify, query, etc.

ON *.*: indicates that the specified user can operate on all tables of all databases. If you want to specify a database and a table, you can use “ON database_name.table_name” instead.

TO 'root': indicates that operational permissions are assigned to the root user. If you want to assign permissions to other users, you can change root to other usernames.

@'%': indicates that all client IP addresses are allowed to access. That is, % indicates that there is no restriction on the client's IP address. If you want to restrict the client's IP address, you can replace % with the specified IP address.

IDENTIFIED BY "": indicates the password of the authorized user. Since I am assigning permissions to the root user, and the default password of the root user is empty, I use an empty string.

(7

The root user of mysql has no default password, here the initial password for the root user is set to123456. That is, execute the following command:

mysqladmin -u root password '123456

Of course, you can also allow the root user to not have a password at all. However, for security reasons, it is still recommended to set an initial password for the root user.

(8Add mysql service to system service

Adding the mysql service to the system service is to allow for quick startup or shutdown of the mysql service in the future. The method is as follows:

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

In this way, you can start and stop the mysql service in a new way.

Start the mysql service: service mysql.server start

Stop the mysql service: service mysql.server stop

Restart mysql service: service mysql.server restart

Of course, the previous command method (startup and shutdown) is still effective.

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

(9)Set mysql service to startup automatically

There are many ways to set the mysql service to startup automatically, and here only the modification method is introduced

/etc/rc.d/the way to modify the rc.local file.

can also be modified /etc/This rc.local file/etc/In fact, rc.local is /etc/rc.d/The soft link of rc.local file, which is equivalent to a shortcut, and this file will be executed automatically after the system starts up.

You can set the mysql service to startup automatically by 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/Write "mysqld_safe –user=mysql &" in the append mode /etc/rc.d/rc.local file.

As can be seen from this, to turn off the startup self-start of mysql, you just need to edit this file and delete the string you just wrote.

The above is what the editor introduces to everyone about Linux CentOS6.6Methods for installing mysql source code packages in the system, hoping it will be helpful to everyone. If you have any questions, please leave a message, and the editor will reply to you in time. I also want to express my heartfelt thanks to everyone for their support of the Naoan tutorial website!

Declaration: The content of this article is from the Internet, the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, has not been manually edited, and does not assume relevant legal liability. If you find any content suspected of copyright infringement, please send an email to: notice#w3Please report any violations by email to codebox.com (replace # with @), and provide relevant evidence. Once verified, the website will immediately delete the suspected infringing content.

You May Also Like