How to install MySQL under Linux (yum and source code compilation)

How to install MySQL under Linux (yum and source code compilation)

Here are two ways to install MySQL under Linux: yum installation and source code compilation installation.

1. Yum installation

(1) First check whether the MySQL that comes with centos is installed:

# yum list installed |grep mysql 
//If there is a pre-installed mysql, uninstall it# yum -y remove mysql-libs.x86_64

(2) Download the yum repository from the MySQL official website: https://dev.mysql.com/downloads/repo/yum/,

# yum localinstall mysql57-community-release-el6-11.noarch.rpm
// Check if the yum repository is added successfully # yum repolist enabled |grep "mysql.*-community.*"

(3) When using the MySQL yum repository, the latest version is selected for installation by default. You can also select a version to install by manually editing the file. For example, to install MySQL version 5.6, set enabled=1 in mysql56-community and enabled=0 in mysql57-community.

# vim /etc/yum.repos.d/mysql-community.repo
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
# Enable to use MySQL 5.6
[mysql56-community]
name=MySQL 5.6 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/6/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

(4) Install MySQL

# yum install mysql-community-server

(5) Start the MySQL service

# service mysqld start

If the following output appears, MySQL is installed successfully:

Starting mysqld: [ OK ]

2. Compile and install MySQL from source code

(1) First install the packages required for source code compilation

# yum -y install make gcc-c++ cmake bison-devel ncurses-devel

(2) Download and decompress the installation package

# wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.14.tar.gz
# tar xvf mysql-5.6.14.tar.gz

(3) Compile and install (compile parameters are determined according to actual conditions)

# cd mysql-5.6.14
# cmake .
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/var/lib/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
# make && make install

(4) Configure MySQL

Set permissions:

# useradd mysql
# passwd mysql 
# chown -R mysql:mysql /usr/local/mysql

Initialize mysql:

# cd /usr/local/mysql
# scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql

Note: There will be a my.cnf file in the /etc directory. You need to rename this file to another name, such as: /etc/my.cnf.bak. Otherwise, the file will interfere with the correct configuration of MySQL installed from source code and cause it to fail to start.

(5) Register as a service

# cd /usr/local/mysql/support-files
//Registration service# cp mysql.server /etc/rc.d/init.d/mysql
//Use the default configuration file# cp my-default.cnf /etc/my.cnf
//Set up startup# chkconfig mysql on

(6) Start the service

# service mysql start

3. mysql client

When you first enter the mysql client, this error usually occurs:

The solution is as follows:

(1) Add the following command to the /etc/my.cnf file:

(2) After restarting the MySQL service, enter the MySQL client and change the root user's password:

update mysql.user set authentication_string=password("PASSWORD") where user="root";
flush privileges;

(3) Comment out the command you just added and reset the password in the MySQL client:

//Set password strength and length> set global validate_password_policy=0;
> set global validate_password_length=1;
//Change password> alter user 'root'@'localhost' identified by 'PASSWORD';

(4) If you set the root user to have remote access, you also need to execute:

> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'PASSWORD' WITH GRANT OPTION;
> flush privileges;

Then you can create databases, tables, etc. through the mysql client.

Summarize

You may also be interested in:
  • A detailed introduction to the three installation methods of rpm, yum and source code under Linux
  • Install MySQL database 5.6 source code under Linux and change the login user password
  • Tutorial on installing mysql5.6.20 from source code under linux
  • Compile and install PostgreSQL9.5 from source code on Linux CentOS 7
  • How to install mysql source package in Linux CentOS6.6 system
  • Notes on installing MySQL source code under Linux
  • Sharing the steps of compiling, installing and configuring SVN server under Linux
  • How to install MySQL 5.6 from source code under SUSE Linux
  • Linux+php+apache+oracle environment construction: source code compilation and installation of PHP under CentOS
  • Analysis of Linux kernel scheduler source code initialization

<<:  Example of how to import nginx logs into elasticsearch

>>:  JS thoroughly understands GMT and UTC time zones

Recommend

Tutorial on deploying jdk and tomcat on centos7 without interface

1. Install xshell6 2. Create a server connection ...

Get / delete method to pass array parameters in Vue

When the front-end and back-end interact, sometim...

Detailed explanation of how to use Docker-Compose commands

You can manage and deploy Docker containers in a ...

Why not use UTF-8 encoding in MySQL?

MySQL UTF-8 encoding MySQL has supported UTF-8 si...

CSS realizes process navigation effect (three methods)

CSS realizes the process navigation effect. The s...

How to cancel the background color of the a tag when it is clicked in H5

1. Cancel the blue color of the a tag when it is ...

Copy the contents of one file to the end of another file in linux

Problem description: For example, the content of ...

JavaScript to implement a simple clock

This article example shares the specific code for...

Split and merge tables in HTML (colspan, rowspan)

The code demonstrates horizontal merging: <!DO...

mysql wildcard (sql advanced filtering)

Table of contents First, let's briefly introd...

Implementation of Nginx operation response header information

Prerequisite: You need to compile the ngx_http_he...

How to upgrade CentOS7 to CentOS8 (detailed steps)

This article uses a specific example to introduce...

Gojs implements ant line animation effect

Table of contents 1. Gojs Implementation 1. Drawi...