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

Common symbols in Unicode

Unicode is a character encoding scheme developed ...

Briefly explain the use of group by in sql statements

1. Overview Group by means to group data accordin...

React+axios implements github search user function (sample code)

load Request Success Request failed Click cmd and...

The difference between html form submission action and url jump to actiond

The action of the form is different from the URL j...

MySQL encryption and decryption examples

MySQL encryption and decryption examples Data enc...

JavaScript to achieve simple drag effect

This article shares the specific code of JavaScri...

Detailed explanation of box-sizing in CSS3 (content-box and border-box)

Box-sizing in CSS3 (content-box and border-box) T...

Tutorial for installing MySQL 8.0.18 under Windows (Community Edition)

This article briefly introduces how to install My...

Docker deployment of Kafka and Spring Kafka implementation

This article mainly introduces the deployment of ...

JS implements layout conversion in animation

When writing animations with JS, layout conversio...

Talk about the understanding of CSS attribute margin

1.What is margin? Margin is used to control the sp...

CSS3 flexible box flex to achieve three-column layout

As the title says: The height is known, the width...

Analysis of statement execution order of sql and MySQL

I encountered a problem today: Can I use the as a...

Docker deployment RabbitMQ container implementation process analysis

1. Pull the image First, execute the following co...