1. 程式人生 > >CentOS 6.9下MySQL5.7.19安裝步驟

CentOS 6.9下MySQL5.7.19安裝步驟

操作系統 4.0 nat affect core net ffi 安裝 quic

目錄

[TOC]

1、查看當前安裝的Linux版本

[bruce@www ~]$ sudo lsb_release -a
LSB Version:    :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID: CentOS
Description:    CentOS release 6.9 (Final)
Release:        6.9
Codename:       Final

2、下載MySQL 安裝文件

官方網站 http://www.mysql.com
直接下載 https://downloads.mysql.com/archives/get/file/mysql-5.7.19-1.el6.x86_64.rpm-bundle.tar。

3、清理老版本MySQL

3.1、查看操作系統中是否已安裝MySQL

[bruce@www ~]$ sudo rpm -qa | grep mysql
mysql-5.1.73-8.el6_8.x86_64
mysql-server-5.1.73-8.el6_8.x86_64
mysql-libs-5.1.73-8.el6_8.x86_64

3.2、刪除老版本MySQL數據庫安裝包

[bruce@www ~]$ sudo rpm -e --nodeps mysql-5.1.73-8.el6_8.x86_64
[bruce@www ~]$ sudo rpm -e --nodeps mysql-server-5.1.73-8.el6_8.x86_64
[bruce@www ~]$ sudo rpm -e --nodeps mysql-libs-5.1.73-8.el6_8.x86_64

3.3、查找老版本MySQL安裝遺留的目錄和文件

[bruce@www ~]$ find / -name mysql
/var/lib/mysql

3.4、刪除老版本MySQL安裝遺留的目錄和文件

[bruce@www ~]$ sudo rm -rf /var/lib/mysql

4、安裝新版本MySQL

4.1、解包

[bruce@www softs]$ tar -xvf mysql-5.7.19-1.el6.x86_64.rpm-bundle.tar 
mysql-community-libs-5.7.19-1.el6.x86_64.rpm
mysql-community-devel-5.7.19-1.el6.x86_64.rpm
mysql-community-embedded-5.7.19-1.el6.x86_64.rpm
mysql-community-common-5.7.19-1.el6.x86_64.rpm
mysql-community-libs-compat-5.7.19-1.el6.x86_64.rpm
mysql-community-server-5.7.19-1.el6.x86_64.rpm
mysql-community-test-5.7.19-1.el6.x86_64.rpm
mysql-community-embedded-devel-5.7.19-1.el6.x86_64.rpm
mysql-community-client-5.7.19-1.el6.x86_64.rpm

4.2、安裝MySQL

[bruce@www softs]$ sudo rpm -ivh mysql-community-common-5.7.19-1.el6.x86_64.rpm
warning: mysql-community-common-5.7.19-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                ########################################### [100%]
   1:mysql-community-common ########################################### [100%]
[bruce@www softs]$ sudo rpm -ivh mysql-community-libs-5.7.19-1.el6.x86_64.rpm
warning: mysql-community-libs-5.7.19-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                ########################################### [100%]
   1:mysql-community-libs   ########################################### [100%]
[bruce@www softs]$ sudo rpm -ivh mysql-community-client-5.7.19-1.el6.x86_64.rpm
warning: mysql-community-client-5.7.19-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                ########################################### [100%]
   1:mysql-community-client ########################################### [100%]
[bruce@www softs]$ sudo rpm -ivh mysql-community-server-5.7.19-1.el6.x86_64.rpm
warning: mysql-community-server-5.7.19-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                ########################################### [100%]
   1:mysql-community-server ########################################### [100%]

4.3、啟動MySQL數據庫

[bruce@www ~]$ sudo service mysqld start
Initializing MySQL database:                               [  OK  ]
Starting mysqld:                                           [  OK  ]
[bruce@www ~]$ sudo mysqld_safe --user=mysql --skip-grant-tables  --skip-networking &
[1] 3598
[bruce@www ~]$ 2017-11-15T01:58:49.095993Z mysqld_safe Logging to ‘/var/log/mysqld.log‘.
2017-11-15T01:58:49.129531Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
[bruce@www ~]$ mysql -u root mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.19 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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> update user set authentication_string = password(‘root123‘) where user = ‘root‘;
Query OK, 1 row affected, 1 warning (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 1

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

mysql> quit
Bye
[bruce@www ~]$ sudo service mysqld restart
Stopping mysqld:                                           [  OK  ]
Starting mysqld:                                           [  OK  ]
[bruce@www ~]$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.19

Copyright (c) 2000, 2017, 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> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> set password for root@localhost = password(‘)OKM9ijn‘); 
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql>  flush privileges;
Query OK, 0 rows affected (0.02 sec)
mysql> quit
Bye

4、遠程登錄

4.1、授權

[bruce@www ~]$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 22
Server version: 5.7.19 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select host, user from user;
+-----------+---------------+
| host      | user          |
+-----------+---------------+
| localhost | mysql.session |
| localhost | mysql.sys     |
| localhost | root          |
+-----------+---------------+
3 rows in set (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘)OKM9ijn‘ WITH GRANT OPTION;           
Query OK, 0 rows affected, 1 warning (0.02 sec)

mysql> select host, user from user;
+-----------+---------------+
| host      | user          |
+-----------+---------------+
| %         | root          |
| localhost | mysql.session |
| localhost | mysql.sys     |
| localhost | root          |
+-----------+---------------+
4 rows in set (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.07 sec)

4.2、測試

在其他機器上測試

C:\>mysql -h 192.168.1.144 -u root -p
Enter password: ********
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 23
Server version: 5.7.19 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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.

CentOS 6.9下MySQL5.7.19安裝步驟