Use yum to install mysql in centos7

Source: Internet
Author: User

Use yum to install mysql in centos7

By default, mysql does not exist in the yum source of CentOS7. To solve this problem, we need to download the mysql repo source first.

1. Download the mysql repo Source

?$wgethttp://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

2. Install the mysql-community-release-el7-5.noarch.rpm package

?$sudorpm-ivhmysql-community-release-el7-5.noarch.rpm

After installing this package, you will get the yum repo source for both mysql:/etc/yum. repos. d/mysql-community.repo,/etc/yum. repos. d/mysql-community-source.repo.

3. Install mysql

?$sudoyuminstallmysql-server

Follow the steps to install it. However, after the installation is complete, there is no password and you need to reset the password.

4. Reset the password

Before resetting the password, you must first log on

?$mysql-uroot

The following ERROR may be reported during logon: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql. sock '(2), because of/var/lib/mysql access permission issues. The following command changes the owner of/var/lib/mysql to the current user:

?$sudochown-Ropenscanner:openscanner/var/lib/mysql

Then, restart the service:

?$servicemysqldrestart

Next, log on to reset the password:

?$mysql-uroot?mysql>usemysql;mysql>updateusersetpassword=password(‘123456‘)whereuser=‘root‘;mysql>exit;

5. Open Port 3306

?$sudovim/etc/sysconfig/iptables

Add the following content:

?-AINPUT-ptcp-mstate--stateNEW-mtcp--dport3306-jACCEPT

Save and restart the Firewall:

?$sudoserviceiptablesrestart

In this way, other clients can connect to the mysql service.


What should I do if I forget the mysql logon password in the CentOS system? Use the security mode.

First, stop mysql in CentOS:

# Service mysqld stop
#/Usr/bin/mysqld_safe -- skip-grant-tables &

Enter the following information in the CentOS system:
Msql> mysql-u root-p

Enter the following password and press Enter.

The following describes how to reset the password in the CentOS system:
Mysql> update mysql. user set password = password ("new password") where user = "root ";

Refresh permission
Mysql> flush privileges;

Exit
Mysql> exit;

Start mysql and continue the previous logon action.
#/Rc. d/init. d/mysqld start
# Mysql-u root-p

In this way, we should be able to lose the mysql login password in the CentOS system. I hope you can learn the CentOS system in the same way.

1. configure the firewall and enable port 80 and port 3306

CentOS 7.0 uses firewall as the firewall by default. Here, it is changed to iptables firewall.

1. Disable firewall:

# Stop the firewall Service

  1. Systemctl stop firewalld. service

# Disable firewall startup

  1. Systemctl disable firewalld. service

2. Install iptables Firewall

# Installation

  1. Yum install iptables-services

# Edit the firewall configuration file

  1. Vi/etc/sysconfig/iptables

# Firewall configuration written by system-config-firewall

# Manual customization of this file is not recommended.

* Filter

: Input accept [0: 0]

: Forward accept [0: 0]

: Output accept [0: 0]

-A input-m state -- state ESTABLISHED, RELATED-j ACCEPT

-A input-p icmp-j ACCEPT

-A input-I lo-j ACCEPT

-A input-m state -- state NEW-m tcp-p tcp -- dport 22-j ACCEPT

-A input-m state -- state NEW-m tcp-p tcp -- dport 80-j ACCEPT

-A input-m state -- state NEW-m tcp-p tcp -- dport 3306-j ACCEPT

-A input-j REJECT -- reject-with icmp-host-prohibited

-A forward-j REJECT -- reject-with icmp-host-prohibited

COMMIT

: Wq! # Save and exit

# Restart the firewall to make the configuration take effect.

  1. Systemctl restart iptables. service

# Set firewall startup

  1. Systemctl enable iptables. service

Ii. Disable SELINUX
# Modifying the configuration file

  1. Vi/etc/selinux/config

# SELINUX = enforcing # comment out

# SELINUXTYPE = targeted # comment out

SELINUX = disabled # Add

: Wq! # Save and exit

# Make the configuration take effect immediately

  1. Setenforce 0

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.