提前下载安装包
https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.29-linux-glibc2.12-x86_64.tar.xz
上传文件到RedHat服务器
使用electerm等工具连接到Linux服务器(用管理员账号登录)
切到Sftp,将下载好的安装包传输到Linux服务器
卸载 MySQL
rpm -qa|grep mysql -- 查询服务器是否有mysql,如有,则执行下面的语句进行删除
rpm -e --nodeps 要删除的文件名(nodeps表示强制删除)
[root@readhat8 ~]# rpm -qa|grep mysql
mysql-community-common-8.0.29-1.el8.x86_64
mysql-community-libs-8.0.29-1.el8.x86_64
[root@readhat8 ~]# rpm -e --nodeps mysql-community-common-8.0.29-1.el8.x86_64
[root@readhat8 ~]# rpm -e --nodeps mysql-community-libs-8.0.29-1.el8.x86_64
rpm -qa |grep mariadb -- 查询服务器是否有mariadb,有则进行删除
[root@readhat8 ~]# rpm -qa|grep mysql
[root@readhat8 ~]# rpm -qa |grep mariadb
[root@readhat8 ~]#
安装MySQL
解压
[root@readhat8 ~]# tar -xvf mysql-8.0.29-linux-glibc2.12-x86_64.tar.xz
移动到/usr/local目录下
[root@readhat8 ~]# mv mysql-8.0.29-linux-glibc2.12-x86_64/ /usr/local/mysql-8.0.29/
修改配置文件
[root@readhat8 ~]# vim /etc/my.cnf
以下内容全部copy进去后,:wq 回车保存退出
[mysqld]
basedir=/usr/local/mysql-8.0.29
datadir=/usr/local/mysql-8.0.29/data
socket=/tmp/mysql.sock
character-set-server=utf8
sql_mode =STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION
新建用户和用户组并进入mysql 文件下赋予权限
[root@readhat8 ~]# cd /usr/local/mysql-8.0.29/
[root@readhat8 mysql-8.0.29]# groupadd mysql
[root@readhat8 mysql-8.0.29]# useradd -r -g mysql mysql
[root@readhat8 mysql-8.0.29]# chown -R mysql:mysql ./
初始化数据库,初始化之后,最后一行有初始化密码。需要记住 _&55aMoeA(Fe
[root@readhat8 mysql-8.0.29]# mkdir ./data
[root@readhat8 mysql-8.0.29]# ./bin/mysqld --user=mysql --basedir=/usr/local/mysql-8.0.29/ --datadir=/usr/local/mysql-8.0.29/data/ --initialize ;
2022-04-27T21:52:45.315694Z 0 [Warning] [MY-010915] [Server] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2022-04-27T21:52:45.315753Z 0 [System] [MY-013169] [Server] /usr/local/mysql-8.0.29/bin/mysqld (mysqld 8.0.29) initializing of server in progress as process 6344
2022-04-27T21:52:45.316985Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
2022-04-27T21:52:45.327992Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-04-27T21:52:45.815267Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-04-27T21:52:49.333623Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: _&55aMoeA(Fe
[root@readhat8 mysql-8.0.29]#
把msyql 添加到系统服务
[root@readhat8 mysql-8.0.29]# cp -a ./support-files/mysql.server /etc/init.d/mysql
[root@readhat8 mysql-8.0.29]# chmod +x /etc/init.d/mysql
[root@readhat8 mysql-8.0.29]# chkconfig --add mysql
[root@readhat8 mysql-8.0.29]# chkconfig --list mysql
建立软连接
[root@readhat8 mysql-8.0.29]# ln -s /usr/local/mysql-8.0.29/bin/mysql /usr/bin
启动MYSQL服务
[root@readhat8 mysql-8.0.29]# service mysql start
Starting MySQL.Logging to '/usr/local/mysql-8.0.29/data/readhat8.err'.
SUCCESS!
登陆Mysql
[root@readhat8 bin]# mysql -u root -p
mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
我的报错,缺少libtinfo.so.5文件
在网上下个libtinfo.so.5文件,放到/lib64目录下
[root@readhat8 bin]# mv /root/libtinfo.so.5 /lib64/libtinfo.so.5
[root@readhat8 bin]# ldd mysql
linux-vdso.so.1 (0x00007fffbb3fb000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f96c1cae000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f96c1aaa000)
libcrypto.so.1.1 => /usr/local/mysql-8.0.29/bin/./../lib/private/libcrypto.so.1.1 (0x00007f96c15f7000)
libssl.so.1.1 => /usr/local/mysql-8.0.29/bin/./../lib/private/libssl.so.1.1 (0x00007f96c1367000)
libresolv.so.2 => /lib64/libresolv.so.2 (0x00007f96c1150000)
librt.so.1 => /lib64/librt.so.1 (0x00007f96c0f47000)
libtinfo.so.5 => /lib64/libtinfo.so.5 (0x00007f96c0d1d000)
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f96c0988000)
libm.so.6 => /lib64/libm.so.6 (0x00007f96c0606000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f96c03ee000)
libc.so.6 => /lib64/libc.so.6 (0x00007f96c002c000)
/lib64/ld-linux-x86-64.so.2 (0x00007f96c1ece000)
[root@readhat8 bin]#
再登陆Mysql,输入刚刚的密码(一定要盲输入密码,直接拼接在-p后面会无效),登录成功
[root@readhat8 bin]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.29
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>
修改密码
mysql> ALTER USER "root"@"localhost" IDENTIFIED BY "1qaz@WSX";
Query OK, 0 rows affected (0.01 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql>
打开连接 数据库连接工具
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)
mysql> exit
Bye
[root@readhat8 bin]#
开启端口
开启防火墙
[root@readhat8 admin]# systemctl start firewalld
开放指定端口
[root@readhat8 admin]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
重启防火墙
[root@readhat8 admin]# firewall-cmd --reload
success
使用数据库连接工具,测试是否可以连接成功
image.png