centos7使用MySQL的Yum存儲庫安裝mysql5.6.45


注意:這個MySQL5.6.45版本有問題,修改配置文件不生效,推薦安裝MySQL5.6.43

下載yum源

官網地址:http://dev.mysql.com/downloads/repo/yum/

centos7系統:

wget http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm

# wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

[root@localhost ~]# wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
--2019-08-10 22:12:00--  http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
Resolving repo.mysql.com (repo.mysql.com)... 104.74.21.42
Connecting to repo.mysql.com (repo.mysql.com)|104.74.21.42|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 6140 (6.0K) [application/x-redhat-package-manager]
Saving to: ‘mysql-community-release-el7-5.noarch.rpm’

100%[===================================================================================================================>] 6,140       --.-K/s   in 0s      

2019-08-10 22:12:00 (222 MB/s) - ‘mysql-community-release-el7-5.noarch.rpm’ saved [6140/6140]

[root@localhost ~]# 
[root@localhost ~]# ls
anaconda-ks.cfg  mysql-community-release-el7-5.noarch.rpm

centos6.5系統:

wget http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm

wget http://dev.mysql.com/get/mysql57-community-release-el6-7.noarch.rpm

檢測系統是否自帶安裝mysql

# yum list installed | grep mysql

刪除系統自帶的mysql

# yum -y remove mysql-libs.x86_64

由於這個mysql的yum源服務器在國外,所以下載速度會比較慢,mysql5.6只有79M大,而mysql5.7就有182M。

安裝mysql-community-release-el7-5.noarch.rpm包

# rpm -ivh mysql-community-release-el7-5.noarch.rpm

[root@localhost ~]# rpm -ivh mysql-community-release-el7-5.noarch.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-release-el7-5    ################################# [100%]

安裝完這個包后,會獲得兩個mysql的yum repo源:/etc/yum.repos.d/mysql-community.repo,/etc/yum.repos.d/mysql-community-source.repo

[root@localhost ~]# ls /etc/yum.repos.d/
centos.repo  mysql-community.repo  mysql-community-source.rep

# vi mysql-community.repo

[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-tools-community]
name=MySQL Tools Community
baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

# Enable to use MySQL 5.5
[mysql55-community]
name=MySQL 5.5 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.5-community/el/7/$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/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

# Note: MySQL 5.7 is currently in development. For use at your own risk.
# Please read with sub pages: https://dev.mysql.com/doc/relnotes/mysql/5.7/en/
[mysql57-community-dmr]
name=MySQL 5.7 Community Server Development Milestone Release
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

# cat mysql-community-source.repo

[root@localhost yum.repos.d]# cat mysql-community-source.repo 
[mysql-connectors-community-source]
name=MySQL Connectors Community - Source
baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/7/SRPMS
enabled=0
gpgcheck=1
gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-tools-community-source]
name=MySQL Tools Community - Source
baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/7/SRPMS
enabled=0
gpgcheck=1
gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql55-community-source]
name=MySQL 5.5 Community Server - Source
baseurl=http://repo.mysql.com/yum/mysql-5.5-community/el/7/SRPMS
enabled=0
gpgcheck=1
gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql56-community-source]
name=MySQL 5.6 Community Server - Source
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/SRPMS
enabled=0
gpgcheck=1
gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql57-community-dmr-source]
name=MySQL 5.7 Community Server Development Milestone Release - Source
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/SRPMS
enabled=0
gpgcheck=1
gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

用yum repolist mysql這個命令查看一下是否已經有mysql可安裝文件

# yum repolist all | grep mysql

[root@localhost ~]# yum repolist all | grep mysql
mysql-connectors-community/x86_64 MySQL Connectors Community     enabled:    118
mysql-connectors-community-source MySQL Connectors Community - S disabled
mysql-tools-community/x86_64      MySQL Tools Community          enabled:     95
mysql-tools-community-source      MySQL Tools Community - Source disabled
mysql55-community/x86_64          MySQL 5.5 Community Server     disabled
mysql55-community-source          MySQL 5.5 Community Server - S disabled
mysql56-community/x86_64          MySQL 5.6 Community Server     enabled:    479
mysql56-community-source          MySQL 5.6 Community Server - S disabled
mysql57-community-dmr/x86_64      MySQL 5.7 Community Server Dev disabled
mysql57-community-dmr-source      MySQL 5.7 Community Server Dev disabled

安裝mysql

# yum install mysql-server -y

Installed:
  mysql-community-libs.x86_64 0:5.6.45-2.el7                                   mysql-community-server.x86_64 0:5.6.45-2.el7                                  

Dependency Installed:
  mysql-community-client.x86_64 0:5.6.45-2.el7        mysql-community-common.x86_64 0:5.6.45-2.el7        net-tools.x86_64 0:2.0-0.24.20131004git.el7       
  perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7        perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7         perl-DBI.x86_64 0:1.627-4.el7                     
  perl-IO-Compress.noarch 0:2.061-2.el7               perl-Net-Daemon.noarch 0:0.48-5.el7                 perl-PlRPC.noarch 0:0.2020-14.el7                 

Replaced:
  mariadb-libs.x86_64 1:5.5.44-2.el7.centos                                                                                                                  

Complete!

加入開機自啟動

# systemctl enable mysqld

啟動mysql服務進程

# systemctl start mysqld

查看mysql服務進程

# systemctl status mysqld

[root@localhost ~]# systemctl enable mysqld
[root@localhost ~]# 
[root@localhost ~]# systemctl start mysqld
[root@localhost ~]# 
[root@localhost ~]# systemctl status mysqld
● mysqld.service - MySQL Community Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2019-08-10 22:37:58 CST; 13s ago
  Process: 24969 ExecStartPost=/usr/bin/mysql-systemd-start post (code=exited, status=0/SUCCESS)
  Process: 24908 ExecStartPre=/usr/bin/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
 Main PID: 24968 (mysqld_safe)
   CGroup: /system.slice/mysqld.service
           ├─24968 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
           └─25134 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mysqld.log --pid-fil...

Aug 10 22:37:57 localhost.localdomain mysql-systemd-start[24908]: PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
Aug 10 22:37:57 localhost.localdomain mysql-systemd-start[24908]: To do so, start the server, then issue the following commands:
Aug 10 22:37:57 localhost.localdomain mysql-systemd-start[24908]: /usr/bin/mysqladmin -u root password 'new-password'
Aug 10 22:37:57 localhost.localdomain mysql-systemd-start[24908]: /usr/bin/mysqladmin -u root -h localhost.localdomain password 'new-password'
Aug 10 22:37:57 localhost.localdomain mysql-systemd-start[24908]: Alternatively you can run:
Aug 10 22:37:57 localhost.localdomain mysql-systemd-start[24908]: /usr/bin/mysql_secure_installation
Aug 10 22:37:57 localhost.localdomain mysql-systemd-start[24908]: which will also give you the option of removing the test
Aug 10 22:37:57 localhost.localdomain mysqld_safe[24968]: 190810 22:37:57 mysqld_safe Logging to '/var/log/mysqld.log'.
Aug 10 22:37:57 localhost.localdomain mysqld_safe[24968]: 190810 22:37:57 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
Aug 10 22:37:58 localhost.localdomain systemd[1]: Started MySQL Community Server.

進入mysql

# mysql

[root@localhost ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.45 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

初始化配置

# mysql_secure_installation

[root@localhost ~]# mysql_secure_installation



NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):       #回車
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] y        #是否設置root密碼
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y       #是否刪除匿名用戶
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n       #是否禁止root用戶遠程登錄
 ... skipping.

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y        #是否刪除test數據庫 - Dropping test database...
ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist
 ... Failed!  Not critical, keep moving...
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y          #是否刷新權限配置生效
 ... Success!




All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!


Cleaning up...

再次進入mysql會出現如下情況

# mysql

[root@localhost ~]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

使用用戶名密碼進入mysql

# mysql -uroot -p

[root@localhost ~]# mysql -uroot -p
Enter password:           #輸入設置的root密碼
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 5.6.45 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

此時mysql只允許內部使用連接,客戶端連接會報如下錯誤

null, message from server: "Host '192.168.1.10' is not allowed to connect to this MySQL server"

授權遠程登錄

grant all privileges on *.* to root@'%' identified by 'password' with grant option;

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY 'password' WITH GRANT OPTION;

第一個是你的用戶名root,第二個password是遠程的密碼

mysql> grant all privileges on *.* to root@'%' identified by '123456' with grant option

mysql> flush privileges;

mysql> select user,host,password from mysql.user;
+------+-----------------------+-------------------------------------------+
| user | host                  | password                                  |
+------+-----------------------+-------------------------------------------+
| root | localhost             | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| root | localhost.localdomain | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| root | 127.0.0.1             | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| root | ::1                   | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+------+-----------------------+-------------------------------------------+
4 rows in set (0.00 sec)

mysql> grant all privileges on *.* to root@'%' identified by '123456' with grant option;
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> select user,host,password from mysql.user;
+------+-----------------------+-------------------------------------------+
| user | host                  | password                                  |
+------+-----------------------+-------------------------------------------+
| root | localhost             | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| root | localhost.localdomain | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| root | 127.0.0.1             | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| root | ::1                   | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| root | %                     | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+------+-----------------------+-------------------------------------------+
5 rows in set (0.01 sec)

mysql>

開放防火牆端口

# firewall-cmd --add-port 3306/tcp

# firewall-cmd --add-port 3306/tcp --permanent

[root@localhost ~]# firewall-cmd --add-port 3306/tcp
success

重啟防火牆

# systemctl restart firewalld

參考博客:

Centos7安裝mysql5.6教程

https://blog.csdn.net/wyj19950908/article/details/79684574

CentOS 6.7下MySQL 5.6快速安裝及參數詳解

https://www.linuxidc.com/Linux/2017-11/148266.htm

centos6.5安裝mysql請參考

linux CentOS6.5 yum安裝mysql 5.6

CentOS7安裝mysql5.6

https://blog.csdn.net/weixin_37650458/article/details/84105489

二進制編譯安裝mysql5.6請參考:

https://www.cnblogs.com/yszd/p/10178253.html

https://blog.51cto.com/holy2010/2287884


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM