CentOS 6.9下MySQL5.7.19安装步骤

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CentOS 6.9下MySQL5.7.19安装步骤相关的知识,希望对你有一定的参考价值。

目录

[TOC]

1、查看当前安装的Linux版本

[[email protected] ~]$ 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

[[email protected] ~]$ 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数据库安装包

[[email protected] ~]$ sudo rpm -e --nodeps mysql-5.1.73-8.el6_8.x86_64
[[email protected] ~]$ sudo rpm -e --nodeps mysql-server-5.1.73-8.el6_8.x86_64
[[email protected] ~]$ sudo rpm -e --nodeps mysql-libs-5.1.73-8.el6_8.x86_64

3.3、查找老版本MySQL安装遗留的目录和文件

[[email protected] ~]$ find / -name mysql
/var/lib/mysql

3.4、删除老版本MySQL安装遗留的目录和文件

[[email protected] ~]$ sudo rm -rf /var/lib/mysql

4、安装新版本MySQL

4.1、解包

[[email protected] 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

[[email protected] 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%]
[[email protected] 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%]
[[email protected] 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%]
[[email protected] 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数据库

[[email protected] ~]$ sudo service mysqld start
Initializing MySQL database:                               [  OK  ]
Starting mysqld:                                           [  OK  ]
[[email protected] ~]$ sudo mysqld_safe --user=mysql --skip-grant-tables  --skip-networking &
[1] 3598
[[email protected] ~]$ 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
[[email protected] ~]$ 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
[[email protected] ~]$ sudo service mysqld restart
Stopping mysqld:                                           [  OK  ]
Starting mysqld:                                           [  OK  ]
[[email protected] ~]$ 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 [email protected] = 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、授权

[[email protected] ~]$ 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安装步骤的主要内容,如果未能解决你的问题,请参考以下文章

centos7安装 MySQL5.7.19

Linux CentOS7 安装 Mysql5.7.19

CentOS6.9 下编译安装MySQL5.7.19

记一次 centos7.2 rpm方式安装mysql5.7.19 报错

CentOS7 + Nginx1.13.5 + PHP7.1.10 + MySQL5.7.19 源码编译安装

Mac下安装mysql5.7.19 完整步骤(图文详解)