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

  • 2
  • 527 views
  • A+
所属分类:Notes

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

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

目前评论:2   其中:访客  2   博主  0

    • ag

      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

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