Install MySQL in linux source code

Source: Internet
Author: User

Install MySQL in linux source code

Recently, MySQL Fabric needs to be used. This product is a utility generated after MySQL5.6.10. MySQL5.1 is installed on the machine at hand. Therefore, you need to upgrade the old MySQL version to MySQL 5.6 first. I have never played MySQL before, so I have to pay a little fee this time. Here, we will record the process and hope to provide some help to those who need it. Next we will officially start.

1. Deleting an old version of MySQL is actually a simple task, but it is also slow because of worries that the dependencies of various packages may cause various problems. In fact, you only need to do this step: 1.1 view and delete the installed mysql version

View the installed mysql version: rpm-qa | grep-I mysql

You only need to uninstall the two rpm packages of the client/server. During the process, you may be prompted about the dependency of a package, and add -- nodeps.

1.2 Delete the data file/etc/my. cnf and the data file under the installation directory/usr/local/mysql/(this directory is specified during installation. Rm-r/etc/my. cnfrm-rf/usr/local/mysql1.3 check whether mysql is often ignored during running. If yes, kill it. Run the following command: ps-fe | grep mysql.
After the preceding three steps, you can uninstall the old mysql version. When the new version of mysql is installed later, other legacy components will prompt incompatibility, and delete them one by one. 2. Install MySQL5.6 in the source code. Prerequisite 1: Since the source code is installed, you must first download the MySQL source code. We will not repeat the download as needed. Prerequisite 2: Install cmake. MySQL is compiled using cmake, so you need to install it in advance. This process is also very simple. After the above preparations are OK, the installation process is started. 2.1 compilation is the same as other projects on linux. MySQL compilation is also called make/make install. 2.1.1 run cmake in the code path:
cmake ./ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql  \-DMYSQL_DATADIR=/usr/local/mysql/data             \-DSYSCONFDIR=/etc                                 \-DWITH_MYISAM_STORAGE_ENGINE=1                    \-DWITH_INNOBASE_STO…
The preceding compilation parameters need to be used in subsequent installation. Others can be copied directly. DCMAKE_INSTALL_PREFIX: the installation path of MySQL. After installation, it is the working path of MySQL.
DMYSQL_DATADIR: MySQL data file location.
DSYSCONFDIR: Location of the MySQL configuration file.
2.1.2 make & make install .. At this point, the compilation process is complete. 2.2 Installation
# cd /usr/local/mysql# chown -R mysql:mysql .# chown -R mysql:mysql ./data# scripts/mysql_install_db --defaults-file=/etc/my.cnf# cp support-files/my-default.cnf /etc/my.cnf
The above are all MySQL configuration processes, and the path must be consistent with the above cmake parameter. Note the mysql configuration file/etc/my. cnf. The following is my configuration file, which is basically maintained.
[mysql]socket = /tmp/mysqld.sock[mysqld]user = mysqldatadir = /usr/local/mysql/dataport=3306
2.3 There are three ways to start MySQL:
Method 1: # bin/mysqld_safe -- defaults-file =/etc/my. cnf method 2: # bin/mysqld method 3: cp support-files/msql. server/etc/init. d/mysqlservice mysql start
I believe you are more familiar with the third method. You can use start, restart, or stop to start, restart, or stop a service, which is widely used in linux. I am also used to this method, but I found a situation during use. When using service mysql start, if the service fails to start, there is basically no error log output, so it is difficult to determine the cause of the startup failure. At this time, we recommend that you use method 2 to start it. It will output the cause of the error, which is much easier to find.Check whether startup is successful: ps-ef | grep mysql2.4 change root Password
# ./bin/mysqladmin -u root password
Enter the password twice. After changing the password, restart mysql. By now, MySQL has been upgraded from the old version.
The specific parameters of the latest mysql source code compilation and Installation Method in Linux are described in the following section.

The following is the configuration experience of CentOS Linux 5:
Add a mysql account
Groupadd mysql
Useradd-r-g mysql
Installation is required before compilation.
Cmake-2.8.4 and bison-2.4.3
Decompress mysql-5.5.15.tar.gz after successful installation:
Open the terminal in the source code root directory and enter the following configuration parameters and press Enter.
Cmake-DCMAKE_INSTALL_PREFIX =/etc/mysql \
-DMYSQL_UNIX_ADDR =/etc/mysql. sock \
-DDEFAULT_CHARSET = utf8 \
-DDEFAULT_COLLATION = utf8_general_ci \
-DWITH_EXTRA_CHARSETS: STRING = utf8, gbk \
-DWITH_MYISAM_STORAGE_ENGINE = 1 \
-DWITH_INNOBASE_STORAGE_ENGINE = 1 \
-DWITH_MEMORY_STORAGE_ENGINE = 1 \
-DWITH_READLINE = 1 \
-DENABLED_LOCAL_INFILE = 1 \
-DMYSQL_DATADIR =/var/mysql/data \
-DMYSQL_USER = mysql

After successfully executing the following command, you will be able to see it at the end (/root/Desktop/is your source code directory, depending on your situation)
-- Build files have been written to:/root/Desktop/mysql-5.5.15

Run make to install:
Make
Make install
The following steps are not described in detail:
Cd/mysql
Chown-R mysql: mysql.
Scripts/mysql_install_db -- user = mysql
Chown-R root.
Chown-R mysql data
Cp./support-files/my-small.cnf./my. cnf
Cp support-files/mysql. server mysql; chmod + x mysql
Chown-R mysql: root.
./Mysql start
./Bin/mysqladmin-u root-p 123456

Add startup Service
Chkconfig -- add mysql
Chkconfig mysql on
Service mysql start

If everything goes well, it will be done here. I wish you success.

Why should I create a mysql user first when installing mysql using the source code in linux?

For security .. The advantage of doing so is that when someone else gets rid of your database, you can only get the mysql permission of the system, but not the entire root permission .. .. It is much safer .. Not only does mysql, such as apache, and many other software have such settings .. It indicates that such software is good software ..

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.