Install MySQL 5.7 on CentOS/RHEL 7.2/6.8/5.11

MySQL is a relational database management system (RDBMS) that runs as a server providing multi-user access to a number of databases. This is guide, howto install or upgrade MySQL Community Server latest version 5.7 (5.7.13) on Fedora 24/23/22, CentOS 7.2/6.8/5.11 and Red Hat (RHEL) 7.2/6.8/5.11. This guide works of course with Oracle Linux and Scientific Linux too and MySQL 5.6/5.5 installation is possible too.

Note: If you are upgrading MySQL (from earlier version), then make sure that you backup (dump and copy) your database and configs. And remember run mysql_upgrade command.

Install MySQL YUM repository
## CentOS 7 and Red Hat (RHEL) 7 ##
yum localinstall https://dev.mysql.com/get/mysql5 … se-el7-8.noarch.rpm

## CentOS 6 and Red Hat (RHEL) 6 ##
yum localinstall https://dev.mysql.com/get/mysql5 … se-el6-8.noarch.rpm

## CentOS 5 and Red Hat (RHEL) 5 ##
yum localinstall https://dev.mysql.com/get/mysql5 … se-el5-7.noarch.rpm

Start MySQL server and autostart MySQL on boot

/etc/init.d/mysql start ## use restart after update
## OR ##
service mysql start ## use restart after update

chkconfig –levels 235 mysqld on

Get Your Generated Random root Password
grep ‘A temporary password is generated for root@localhost’ /var/log/mysqld.log |tail -1

MySQL Secure Installation
Change root password
Remove anonymous users
Disallow root login remotely
Remove test database and access to it
Reload privilege tables

Start MySQL Secure Installation with following command
/usr/bin/mysql_secure_installation

mysqladmin -u root password [your_password_here]

## Example ##
mysqladmin -u root password myownsecrectpass

Connect to MySQL database (localhost) with password
mysql -u root -p

## OR ##
mysql -h localhost -u root -p


Create Database, Create MySQL User and Enable Remote Connections to MySQL Database
This example uses following parameters:

DB_NAME = webdb
USER_NAME = webdb_user
REMOTE_IP = 10.0.15.25
PASSWORD = password123
PERMISSIONS = ALL

## CREATE DATABASE ##
mysql> CREATE DATABASE webdb;

## CREATE USER ##
mysql> CREATE USER ‘webdb_user’@’10.0.15.25’ IDENTIFIED BY ‘password123’;

## GRANT PERMISSIONS ##
mysql> GRANT ALL ON webdb.* TO ‘webdb_user’@’10.0.15.25’;

##  FLUSH PRIVILEGES, Tell the server to reload the grant tables  ##
mysql> FLUSH PRIVILEGES;

Enable Remote Connection to MariaDB Server –> Open MySQL Port (3306) on Iptables Firewall (as root user again)
Edit /etc/sysconfig/iptables file:
nano -w /etc/sysconfig/iptables

Add following INPUT rule:
-A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT

Restart Iptables Firewall:

service iptables restart
## OR ##
/etc/init.d/iptables restart

Test remote connection
mysql -h 10.0.15.25 -u myusername -p

本文作者: GavinDong

版权属于: GavinDong博客

文章链接: https://gavindong.com/231.html

如果使用过程中遇到问题,可 **点击此处** 交流沟通。

版权所有,转载时必须以链接形式注明作者和原始出处及本声明。

(0)

相关文章

回复 ag

登录后才能评论

评论列表(2条)

  • ag的头像
    ag 2017.05.04 22:14

    mysql查询数据库中所有记录数:
    use information_schema;

    select table_name,table_rows from tables
    where TABLE_SCHEMA = ‘testdb’
    order by table_rows desc;注意:上面的sql语句并不是很准确!!!

    sqlserver查询数据库中所有记录数:
    SELECT a.name,b.rows FROM sysobjects a
    INNER JOIN sysindexes b ON a.id=b.id
    WHERE b.indid IN(0,1) AND a.Type=’u’
    ORDER BY a.name

  • ag的头像
    ag 2017.05.04 22:13

    注意:必须关闭selinux,否则没办法启动mysql。