登录mysql官网https://dev.mysql.com,单击“DOWNLOADS”
点击“MySQL Community (GPL) Downloads »”
选择“MySQL Community Server”
当前最新的版本为MySQL Community Server 8.0.21,但是企业中使用5.7的比较多
查找以前的版本,单击“Looking for previous GA versions? ”
Select Version:5.7.31;
选择“Select Operating System: Linux - Generic”
选择“Linux - Generic (glibc 2.12) (x86, 64-bit), TAR(mysql-5.7.31-linux-glibc2.12-x86_64.tar)”,点击“Download”
点击“No thanks, just start my download.”
完整下载链接:https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.31-linux-glibc2.12-x86_64.tar
[root@MySQL ~]# mkdir /opt/mysql_install
[root@MySQL ~]# cd /opt/mysql_install/
[root@MySQL mysql_install]# rz -E
rz waiting to receive.
[root@MySQL mysql_install]# ls
mysql-5.7.31-linux-glibc2.12-x86_64.tar
[root@MySQL mysql_install]#
[root@MySQL mysql_install]# tar xf mysql-5.7.31-linux-glibc2.12-x86_64.tar
[root@MySQL mysql_install]# ll
total 1354904
-rw-r--r-- 1 root root 693708288 Aug 14 14:34 mysql-5.7.31-linux-glibc2.12-x86_64.tar
-rw-r--r-- 1 7161 31415 376537503 Jun 2 21:13 mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
-rw-r--r-- 1 7161 31415 317168590 Jun 2 21:12 mysql-test-5.7.31-linux-glibc2.12-x86_64.tar.gz
[root@MySQL mysql_install]# tar zxf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
[root@MySQL mysql_install]# ll
total 1354904
drwxr-xr-x 9 7161 31415 129 Jun 2 21:11 mysql-5.7.31-linux-glibc2.12-x86_64
-rw-r--r-- 1 root root 693708288 Aug 14 14:34 mysql-5.7.31-linux-glibc2.12-x86_64.tar
-rw-r--r-- 1 7161 31415 376537503 Jun 2 21:13 mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
-rw-r--r-- 1 7161 31415 317168590 Jun 2 21:12 mysql-test-5.7.31-linux-glibc2.12-x86_64.tar.gz
[root@MySQL mysql_install]# cd mysql-5.7.31-linux-glibc2.12-x86_64/
[root@MySQL mysql-5.7.31-linux-glibc2.12-x86_64]# ll
total 288
drwxr-xr-x 2 7161 31415 4096 Jun 2 21:11 bin
drwxr-xr-x 2 7161 31415 55 Jun 2 21:11 docs
drwxr-xr-x 3 7161 31415 4096 Jun 2 21:11 include
drwxr-xr-x 5 7161 31415 205 Jun 2 21:11 lib
-rw-r--r-- 1 7161 31415 275393 Jun 2 19:05 LICENSE
drwxr-xr-x 4 7161 31415 30 Jun 2 21:11 man
-rw-r--r-- 1 7161 31415 587 Jun 2 19:05 README
drwxr-xr-x 28 7161 31415 4096 Jun 2 21:11 share
drwxr-xr-x 2 7161 31415 90 Jun 2 21:11 support-files
[root@MySQL mysql-5.7.31-linux-glibc2.12-x86_64]# cd ..
[root@MySQL mysql_install]# mv mysql-5.7.31-linux-glibc2.12-x86_64 /usr/local/mysql
[root@MySQL mysql_install]#
[root@MySQL mysql_install]# groupadd -r mysql && useradd -r -g mysql -s /sbin/nologin -M mysql
[root@MySQL mysql_install]# mkdir /usr/local/mysql/data
[root@MySQL mysql_install]# chown -R mysql:mysql /usr/local/mysql/
[root@MySQL mysql_install]#
[root@MySQL mysql_install]# rpm -qa | grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64
[root@MySQL mysql_install]# rpm -e mariadb-libs --nodeps
[root@MySQL mysql_install]# rpm -qa | grep mariadb
[root@MySQL mysql_install]#
只需在文件尾添加
[root@MySQL mysql_install]# vim /etc/profile
#内容过长,省略部分内容
unset i
unset -f pathmunge
export PATH=$PATH:/usr/local/mysql/bin //在文件的最后添加此行
[root@MySQL mysql_install]# . /etc/profile
[root@MySQL mysql_install]#
[root@MySQL mysql_install]# vim /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
pid-file=/usr/local/mysql/data/mysqld.pid
socket=/tmp/mysql.sock
log-error=/usr/local/mysql/data/mysql.err
[root@MySQL mysql_install]# mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
[root@MySQL mysql_install]# cd /usr/local/mysql
[root@MySQL mysql]# ll
total 288
drwxr-xr-x 2 mysql mysql 4096 Jun 2 21:11 bin
drwxr-xr-x 5 mysql mysql 331 Aug 14 17:11 data
drwxr-xr-x 2 mysql mysql 55 Jun 2 21:11 docs
drwxr-xr-x 3 mysql mysql 4096 Jun 2 21:11 include
drwxr-xr-x 5 mysql mysql 205 Jun 2 21:11 lib
-rw-r--r-- 1 mysql mysql 275393 Jun 2 19:05 LICENSE
drwxr-xr-x 4 mysql mysql 30 Jun 2 21:11 man
-rw-r--r-- 1 mysql mysql 587 Jun 2 19:05 README
drwxr-xr-x 28 mysql mysql 4096 Jun 2 21:11 share
drwxr-xr-x 2 mysql mysql 90 Jun 2 21:11 support-files
[root@MySQL mysql]# cd support-files/
[root@MySQL support-files]# ll
total 24
-rw-r--r-- 1 mysql mysql 773 Jun 2 19:05 magic
-rwxr-xr-x 1 mysql mysql 1061 Jun 2 20:52 mysqld_multi.server
-rwxr-xr-x 1 mysql mysql 894 Jun 2 20:52 mysql-log-rotate
-rwxr-xr-x 1 mysql mysql 10576 Jun 2 20:52 mysql.server //该文件功能主要是MySQL服务的启动停止等
[root@MySQL support-files]#
[root@MySQL support-files]# cp mysql.server /etc/init.d/mysqld
[root@MySQL support-files]# /etc/init.d/mysqld start
Starting MySQL... SUCCESS!
[root@MySQL support-files]# ss -atlnp | grep mysql
LISTEN 0 80 :::3306 :::* users:(("mysqld",pid=1629,fd=20))
[root@MySQL support-files]#
[root@MySQL support-files]# grep 'password' /usr/local/mysql/data/mysql.err
2020-08-14T09:11:44.614218Z 1 [Note] A temporary password is generated for root@localhost: :;h3Ysev2TBt
[root@MySQL support-files]# mysql -uroot -p
Enter password: //密码是:;h3Ysev2TBt
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.31
Copyright (c) 2000, 2020, 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> alter user root@localhost identified by '123456';
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
[root@MySQL support-files]# mysql -uroot -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.31 MySQL Community Server (GPL)
Copyright (c) 2000, 2020, 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;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.01 sec)
mysql> quit
Bye
[root@MySQL support-files]#
二进制安装没有密码策略,最好设置一下
这只是我的一些浅薄的见解,望多指教!