1、从MySQL官网下载MYSQL的安装文件
mysql-5.7.25-1.el6.x86_64.rpm-bundle.tar
百度网盘下载地址:
链接:https://pan.baidu.com/s/1wZ9twbHvFduKZAwrMyHDYg
提取码:76tg
2、创建mysql组
groupadd mysql
3、创建mysql用户
useradd -g mysql mysql
4、创建mysql文件夹并把安装包放在mysql文件夹中
mkdir /mysql
mv mysql-5.7.25-1.el6.x86_64.rpm-bundle.tar /mysql
5、检查库文件是否存在,如有删除
[root@mysql Desktop]$ rpm -qa | grep mysql
mysql-libs-5.1.52-1.el6_0.1.x86_64
[root@mysql ~]# rpm -e mysql-libs-5.1.52.x86_64 --nodeps
6、解压安装包
[root@mysql mysql]# tar -xvf mysql-5.7.25-1.el6.x86_64.rpm-bundle.tar
mysql-community-common-5.7.25-1.el6.x86_64.rpm
mysql-community-test-5.7.25-1.el6.x86_64.rpm
mysql-community-devel-5.7.25-1.el6.x86_64.rpm
mysql-community-server-5.7.25-1.el6.x86_64.rpm
mysql-community-client-5.7.25-1.el6.x86_64.rpm
mysql-community-embedded-devel-5.7.25-1.el6.x86_64.rpm
mysql-community-embedded-5.7.25-1.el6.x86_64.rpm
mysql-community-libs-compat-5.7.25-1.el6.x86_64.rpm
mysql-community-libs-5.7.25-1.el6.x86_64.rpm
[root@mysql mysql]# ll
total 929504
-rw-rw-rw- 1 root root 475893760 Apr 26 14:57 mysql-5.7.25-1.el6.x86_64.rpm-bundle.tar
-rw-r--r-- 1 7155 31415 23853144 Dec 24 13:42 mysql-community-client-5.7.25-1.el6.x86_64.rpm
-rw-r--r-- 1 7155 31415 340184 Dec 24 13:42 mysql-community-common-5.7.25-1.el6.x86_64.rpm
-rw-r--r-- 1 7155 31415 3797584 Dec 24 13:42 mysql-community-devel-5.7.25-1.el6.x86_64.rpm
-rw-r--r-- 1 7155 31415 39489784 Dec 24 13:42 mysql-community-embedded-5.7.25-1.el6.x86_64.rpm
-rw-r--r-- 1 7155 31415 137670944 Dec 24 13:42 mysql-community-embedded-devel-5.7.25-1.el6.x86_64.rpm
-rw-r--r-- 1 7155 31415 2203408 Dec 24 13:42 mysql-community-libs-5.7.25-1.el6.x86_64.rpm
-rw-r--r-- 1 7155 31415 1723740 Dec 24 13:42 mysql-community-libs-compat-5.7.25-1.el6.x86_64.rpm
-rw-r--r-- 1 7155 31415 160646088 Dec 24 13:42 mysql-community-server-5.7.25-1.el6.x86_64.rpm
-rw-r--r-- 1 7155 31415 106159460 Dec 24 13:43 mysql-community-test-5.7.25-1.el6.x86_64.rpm
7、进行安装(请按照如下顺序进行安装)
[root@mysql mysql]# rpm -ivh mysql-community-common-5.7.25-1.el6.x86_64.rpm --nodeps
warning: mysql-community-common-5.7.25-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
1:mysql-community-common ########################################### [100%]
[root@mysql mysql]# rpm -ivh mysql-community-test-5.7.25-1.el6.x86_64.rpm --nodeps
warning: mysql-community-test-5.7.25-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
1:mysql-community-test ########################################### [100%]
[root@mysql mysql]# rpm -ivh mysql-community-libs-5.7.25-1.el6.x86_64.rpm --nodeps
warning: mysql-community-libs-5.7.25-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
1:mysql-community-libs ########################################### [100%]
[root@mysql mysql]# rpm -ivh mysql-community-client-5.7.25-1.el6.x86_64.rpm --nodeps
warning: mysql-community-client-5.7.25-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
1:mysql-community-client ########################################### [100%]
[root@mysql mysql]# rpm -ivh mysql-community-server-5.7.25-1.el6.x86_64.rpm --nodeps
warning: mysql-community-server-5.7.25-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
1:mysql-community-server ########################################### [100%]
[root@mysql mysql]# rpm -ivh mysql-community-devel-5.7.25-1.el6.x86_64.rpm --nodeps
warning: mysql-community-devel-5.7.25-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
1:mysql-community-devel ########################################### [100%]
[root@mysql mysql]# rpm -ivh mysql-community-test-5.7.25-1.el6.x86_64.rpm --nodeps
warning: mysql-community-test-5.7.25-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
package mysql-community-test-5.7.25-1.el6.x86_64 is already installed
8、检查并启动mysqld服务
[root@mysql mysql]# service mysqld status
mysqld is stopped
[root@mysql mysql]# service mysqld start
Initializing MySQL database: [ OK ]
Starting mysqld: [ OK ]
[root@mysql mysql]# service mysqld status
mysqld (pid 3781) is running...
9、登录mysql并修改密码
检查临时密码:
[root@mysql mysql]# more /var/log/mysqld.log | grep "A temporary password"
2019-04-26T07:05:10.073912Z 1 [Note] A temporary password is generated for root@localhost: Pykq_5blTgr1
登录:
[root@mysql mysql]# mysql -hlocalhost -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.25
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>
10、修改密码策略,第一条为修改为只需满足长度要求,第二条为设置长度最低为4,此处设置小于4也会按4处理
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_length=4;
Query OK, 0 rows affected (0.00 sec)
11、修改密码
mysql> set password=password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
12、登录mysql
[root@mysql mysql]# mysql -hlocalhost -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.25 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安装完成。
13、允许远程连接并设置远程连接的密码
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
14、日志模式
检查日志模式
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like 'log_bin';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_bin | OFF |
+---------------+-------+
1 row in set (0.00 sec)
15、设置bin log模式
在/etc/my.cnf中添加:
log_bin=binary-log
server_id=1
重启mysqld服务
service mysqld restart
16、查看bin log模式是否设置成功
mysql> show variables like 'log_bin';
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 3
Current database: *** NONE ***
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_bin | ON |
+---------------+-------+
1 row in set (0.00 sec)