MySQL的二进制包是指官方提供的已经编译好的可执行文件,用于安装和运行 MySQL 服务器。
它包含了所有必要的二进制文件、库文件和相关工具等。通过使用二进制包,你可以更容易地安装和配置 MySQL,无需手动编译源代码。
今天我们就一起来使用二进制包安装下MySQL8
官方网址: https://dev.mysql.com/downloads/mysql/
这里我下载 最新的包:
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.33-linux-glibc2.28-x86_64.tar.gz
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
[root@mufeng41 ~]# ls
mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
要在安装MySQL前把系统中可能存在的MySQL包删除
[root@mufeng41 ~]# rpm -qa |grep mysql
akonadi-mysql-1.9.2-4.el7.x86_64
qt-mysql-4.8.7-2.el7.x86_64
[root@mufeng41 ~]# rpm -e akonadi-mysql-1.9.2-4.el7.x86_64 --nodeps
[root@mufeng41 ~]# rpm -e qt-mysql-4.8.7-2.el7.x86_64 --nodeps
[root@mufeng41 ~]# rpm -qa |grep mariadb
mariadb-server-5.5.60-1.el7_5.x86_64
mariadb-libs-5.5.60-1.el7_5.x86_64
mariadb-5.5.60-1.el7_5.x86_64
[root@mufeng41 ~]# yum remove mariadb mariadb-devel mariadb-server
[root@mufeng41 ~]# rpm -qa |grep mariadb
mariadb-libs-5.5.60-1.el7_5.x86_64
[root@mufeng41 ~]# rpm -e mariadb-libs-5.5.60-1.el7_5.x86_64 --nodeps
[root@mufeng41 ~]#
查看系统中残留的MySQL文件
[root@mufeng41 ~]# find / -name mysql
/etc/selinux/targeted/active/modules/100/mysql
/usr/lib64/mysql
/usr/lib64/perl5/vendor_perl/auto/DBD/mysql
/usr/lib64/perl5/vendor_perl/DBD/mysql
[root@mufeng41 ~]# userdel -r mysql
userdel: mysql 邮件池 (/var/spool/mail/mysql) 未找到
userdel:未找到 mysql 的主目录“/var/lib/mysql”
[root@mufeng41 ~]# rm -rf /etc/selinux/targeted/active/modules/100/mysql /usr/lib64/mysql /usr/lib64/perl5/vendor_perl/auto/DBD/mysql /usr/lib64/perl5/vendor_perl/DBD/mysql
[root@mufeng41 ~]# groupadd mysql
[root@mufeng41 ~]# useradd -r -g mysql -s /bin/false mysql
[root@mufeng41 ~]# id mysql
uid=988(mysql) gid=1001(mysql) 组=1001(mysql)
[root@mufeng41 ~]#
[root@mufeng41 ~]# tar xf mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
[root@mufeng41 ~]# mv mysql-8.0.20-linux-glibc2.12-x86_64 mysql
[root@mufeng41 ~]# mv mysql /usr/local/mysql
[root@mufeng41 ~]# chown -R mysql:mysql /usr/local/mysql
[root@mufeng41 ~]#
二进制安装,需要设置gcc
[root@mufeng41 bin]# yum install gcc gcc-c++ -y
[root@mufeng41 ~]# cat >>/etc/profile <
export MYSQL_HOME=/usr/local/mysql
export PATH=$MYSQL_HOME/bin:$PATH
EOF
[root@mufeng41 ~]# source /etc/profile
[root@mufeng41 ~]#
[root@mufeng41 ~]# vim /etc/my.cnf
[mysqld]
port=3306
socket=/usr/local/mysql/data/mysql.sock
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
log-error=/usr/local/mysql/mysqlerr.log
[root@mufeng41 ~]# cd /usr/local/mysql/
[root@mufeng41 mysql]# ls
bin docs include lib LICENSE man README share support-files
[root@mufeng41 bin]#/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --user=mysql --initialize
2023-06-15T14:34:46.096864Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.20) initializing of server in progress as process 74327
2023-06-15T14:34:46.106291Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-06-15T14:34:46.651220Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-06-15T14:34:47.388178Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: TUIrE#rrj9yT
[root@mufeng41 bin]#
[root@mufeng41 mysql]# grep log /etc/my.cnf
log-error=/usr/local/mysql/mysqlerr.log
[root@mufeng41 mysql]# grep password /usr/local/mysql/mysqlerr.log
2023-06-16T07:07:19.594849Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: mPLx(Amf,5iA
密码就是:TUIrE#rrj9yT
[root@mufeng41 ~]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql &
[1] 22846
[root@mufeng41 ~]# Logging to '/usr/local/mysql/data/mufeng41.err'.
2023-06-15T15:13:09.902395Z mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
在另一个终端输入密码:
[root@mufeng41 ~]# /usr/local/mysql/bin/mysql -uroot -p --socket=/usr/local/mysql/data/mysql.sock
Enter password:
mysql> alter user 'root'@'localhost' identified with mysql_native_password by 'root';
Query OK, 0 rows affected (0.00 sec)
use mysql;
update user set host=‘%’ where user=‘root’;
重启mysql服务,即可远程连接。
MySQL 5.7 和 MySQL 8 中密码认证方式的主要区别:
MySQL 5.7:
MySQL 8:
当从 MySQL 5.7 升级到 MySQL 8 时,旧版的 mysql_native_password 认证方式仍然被支持,以确保与现有的应用程序和旧版客户端的兼容性。但是,新的安装和使用应该使用 caching_sha2_password 插件进行密码认证,以获得更高的安全性。
如果想在 MySQL 8 中使用旧版的 mysql_native_password 作为认证方式,可以通过修改 MySQL 的配置文件(my.cnf 或 my.ini)来进行设置。将 default_authentication_plugin 配置项设置为 mysql_native_password 即可。
但这样做可能会降低密码的安全性,不推荐在新的安装中使用。