← 返回首页
CentOS7安装MySQL8.0.28
发表时间:2022-06-12 23:34:06
CentOS7安装MySQL8.0.28

1.mysql安装包下载 从百度网盘下载MySQL8.0.28地址:

链接:https://pan.baidu.com/s/16GoiLF2I8CqBkyEBOLha6w 
提取码:yyds 

把下载下来的tar包,上传至/usr/local/download/ ,使用tar命令解压。

[root@master download]# tar -zvf mysql-8.0.28-1.el7.x86_64.rpm-bundle.tar 

#解压缩mysql-8.0.28-1.el7.x86_64.rpm-bundle.tar
[root@master download]# tar -xvf mysql-8.0.28-1.el7.x86_64.rpm-bundle.tar

下载后是个tar压缩包,解压后得到以下文件:

[root@master download]# tar -xvf mysql-8.0.28-1.el7.x86_64.rpm-bundle.tar 
mysql-community-client-8.0.28-1.el7.x86_64.rpm
mysql-community-client-plugins-8.0.28-1.el7.x86_64.rpm
mysql-community-common-8.0.28-1.el7.x86_64.rpm
mysql-community-devel-8.0.28-1.el7.x86_64.rpm
mysql-community-embedded-compat-8.0.28-1.el7.x86_64.rpm
mysql-community-icu-data-files-8.0.28-1.el7.x86_64.rpm
mysql-community-libs-8.0.28-1.el7.x86_64.rpm
mysql-community-libs-compat-8.0.28-1.el7.x86_64.rpm
mysql-community-server-8.0.28-1.el7.x86_64.rpm
mysql-community-test-8.0.28-1.el7.x86_64.rpm

2.mysql安装

安装前检查依赖libaio

[root@master download]# rpm -qa|grep libaio
libaio-0.3.109-13.el7.x86_64

如果没有该依赖,需要使用以下命令安装:

yum install libaio

检查net-tools依赖。

[root@master download]# rpm -qa|grep net-tools
net-tools-2.0-0.25.20131004git.el7.x86_64

如果没有该依赖,需要使用以下命令安装:

yum install net-tools

安装过程: 将上述整理的6个rpm包上传到服务器后,在文件目录下,依次执行以下命令(注意必须按顺序执行,否则可能会包缺少相关依赖的错误):

rpm -ivh mysql-community-common-8.0.28-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-plugins-8.0.28-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.28-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.28-1.el7.x86_64.rpm
rpm -ivh mysql-community-icu-data-files-8.0.28-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.28-1.el7.x86_64.rpm

执行 rpm -ivh mysql-community-libs-8.0.28-1.el7.x86_64.rpm 时如果报以下错误:

mariadb-libs 被 mysql-community-libs-8.0.28-1.el7.x86_64 取代

解决办法:查看有没有安装mariadb-libs这个包。

rpm -q mariadb-libs

#检查到有这个包的安装

mariadb-libs-5.5.65-1.el7.x86_64

直接运行
rpm -e mariadb-libs-5.5.65-1.el7.x86_64

PS1:因为LINUX自带了mariadb数据库,所以导致MYSQL安装失败
PS1:卸载过程中可能会遇到

依赖检测失败:
libmysqlclient.so.18()(64bit)被(已安装)postfix-2:2.10.1-7.el7.x86_64需要
libmysqlclient.so.18(libmysqlclient_18)(64bit)被(已安装)postfix-2:2.10.1-7.el7.x86_64需要
那是因为red hat系统会自带postfix服务(postfix服务是一个邮件服务器),所以要卸载mariadb需要先卸载postfix
yum remove postfix
按提示卸载,之后再卸载mariadb-libs就可以了

检查是否安装成功?

[root@master download]# rpm -qa|grep -i mysql
mysql-community-client-plugins-8.0.28-1.el7.x86_64
mysql-community-icu-data-files-8.0.28-1.el7.x86_64
mysql-community-client-8.0.28-1.el7.x86_64
mysql-community-common-8.0.28-1.el7.x86_64
mysql-community-libs-8.0.28-1.el7.x86_64
mysql-community-server-8.0.28-1.el7.x86_64

如果成功显示上面安装的6个包,说明安装成功。

3.mysql使用

服务初始化,如果你是以root身份安装和允许mysql服务,为了保证数据库目录与文件(默认/var/lib/mysql下)的所有者为mysql用户,需要执行下面的命令初始化:

[root@master download]# mysqld --initialize --user=mysql

查看临时密码

[root@master download]# cat /var/log/mysqld.log
2022-06-12T16:24:51.442771Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.28) initializing of server in progress as process 14645
2022-06-12T16:24:51.463171Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-06-12T16:24:52.437463Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-06-12T16:24:53.835057Z 0 [Warning] [MY-013829] [Server] Missing data directory for ICU regular expressions: /usr/lib64/mysql/private/.
2022-06-12T16:24:54.930019Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: uOb5/ldfgby0

登录MySQL.

[root@master download]# mysql -uroot -p
Enter password: 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

如果报以上错误。

[root@master download]# cd /var/lib/mysql/
[root@master mysql]# rm -rf mysql.sock
[root@master mysql]# systemctl stop mysqld
[root@master mysql]# systemctl start mysqld

重新登录MySQL.

[root@master mysql]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.28

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

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> 

第一次登录成功后,必须修改root密码。

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';

4.设置本地远程链接数据库

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> update user set host = '%' where user ='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

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

5.修改密码

use mysql;  
select user,host from user where user='root';
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'xxxxxx';
flush privileges;