Install mysql in Linux (yum and source code compilation) and mysqlyum

Source: Internet
Author: User
Tags mysql official site yum repolist

Install mysql in Linux (yum and source code compilation) and mysqlyum

Here we will introduce two methods for installing mysql in Linux: yum installation and source code compilation and installation.

1. Install yum

(1) first check whether the mysql that comes with centos is installed:

# Yum list installed | grep mysql // uninstall mysql if it comes with an installed mysql # yum-y remove mysql-libs.x86_64

(2) download the MySQL official site of the yum Repository: https://dev.mysql.com/downloads/repo/yum,

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

(3) when using the mysql yum repository, the latest version is selected by default for installation. You can also manually edit the file to select a version for installation. For example, to install version mysql5.6, mysql56-community settings enabled = 1 and mysql57-community settings enabled = 0.

# vim /etc/yum.repos.d/mysql-community.repo[mysql57-community]name=MySQL 5.7 Community Serverbaseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/enabled=0gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql# Enable to use MySQL 5.6[mysql56-community]name=MySQL 5.6 Community Serverbaseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/6/$basearch/enabled=1gpgcheck=1gpgkey=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 is displayed, mysql is successfully installed:

Starting mysqld:[ OK ]

2. Compile and install mysql with source code

(1) first install the package 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 (the compilation parameters are determined based on 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: A my. cnf, 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 by source code, resulting in startup failure.

(5) register as a service

# Cd/usr/local/mysql/support-files // register the service # cp mysql. server/etc/rc. d/init. d/mysql // use the default profile # cp my-default.cnf/etc/my. cnf // set boot start # chkconfig mysql on

(6) start the service

# service mysql start 

3. mysql client

This error occurs when you first enter the mysql client:

The solution is as follows:

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

(2) After the mysql service is restarted, enter the mysql client to modify the password of the root user:

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 on the mysql client:

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

(4) If the root user can be remotely accessed, run the following command:

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

Then you can create databases and tables through the mysql client.

Summary

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.