rpm -qa | grep mysql
如果你查看出来有东西,可以使用下面命令将其删除
rpm -e 文件名
rpm -e mysql57-community-release-el7-10.noarch
2)使用yum卸载安装的mysql
yum remove mysql mysql-server mysql-libs mysql-server
3)搜索mysql文件
全局搜索名称包含 mysql 的所有文件
find / -name '*mysql*'
删除搜索出来的所有 mysql 文件,如果没有安装过mysql,一般会搜索出来 /var/lib/* 和 /usr/share/* 这两个目录下包含 mysql 文件。删除文件命令:
rm -rf /usr/bin/mysql /usr/include/mysql /data/mysql /data/mysql/mysql
# 检查1
rpm -qa|grep mysql
# 检查2
find / -name '*mysql*'
官网地址:https://downloads.mysql.com/archives/community/
下载mysql-5.7.39-linux-glibc2.12-x86_64.tar.gz上传
Product Version: 5.7.39
Operating System: Linux - Generic
OS Version: All
--------------------------------------
Linux - Generic (glibc 2.12) (x86, 32-bit), Compressed TAR Archive Jun 8, 2022 611.1M
Download
(mysql-5.7.39-linux-glibc2.12-i686.tar.gz) MD5: eb9f5f504d7fe8bd35a0655944626260 | Signature
--------------------------------------
Linux - Generic (glibc 2.12) (x86, 64-bit), Compressed TAR Archive Jun 8, 2022 645.3M
Download #点这个下载
(mysql-5.7.39-linux-glibc2.12-x86_64.tar.gz) MD5: 79b971fc3e3368f2a1e07fbafae0b914 | Signature
或使用wget直接下载
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.39-linux-glibc2.12-x86_64.tar.gz
解压
tar -xzvf /home/johnnyyue/mysql-5.7.39-linux-glibc2.12-x86_64.tar.gz
移动并修改文件名
mv /home/johnnyyue/mysql-5.7.39-linux-glibc2.12-x86_64 /usr/local/mysql
mkdir /data/mysql
cat /etc/group | grep mysql
cat /etc/passwd |grep mysql
#先检查是否有mysql用户组和mysql用户,没有就添加有就忽略
groups mysql
groupadd mysql && useradd -r -g mysql mysql
chown -R mysql:mysql /data/mysql
chmod -R 755 /usr/local/mysql
cd /usr/local/mysql
bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql --defaults-file=/etc/my.cnf --initialize
2022-11-23T08:53:40.040038Z 1 [Note] A temporary password is generated for root@localhost: X%pupZH%P0F0
此处需要注意记录生成的临时密码,如上文结尾处的:X%pupZH%P0F0
bin/mysql_ssl_rsa_setup --datadir=/data/mysql
vim /etc/my.cnf
[mysqld]
bind-address=0.0.0.0
port=3306
user=mysql
basedir=/usr/local/mysql
datadir=/data/mysql
socket=/tmp/mysql.sock
log-error=/data/mysql/mysql.err
pid-file=/data/mysql/mysql.pid
#character config
character_set_server=utf8mb4
symbolic-links=0
explicit_defaults_for_timestamp=true
lower_case_table_names=1
ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
service mysql restart
mysql -u root -p
error while loading shared libraries: libncurses.so.5: cannot open shared object file
mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
解决办法
find / -name 'libncurses*'
find / -name 'libtinfo*'
[root@localhost mysql]# find / -name 'libncurses*'
find: ‘/proc/16099’: 没有那个文件或目录
/usr/lib64/libncurses.so.6
/usr/lib64/libncurses.so.6.1
/usr/lib64/libncursesw.so.6
/usr/lib64/libncursesw.so.6.1
[root@localhost mysql]# find / -name 'libtinfo*'
find: ‘/proc/20581’: 没有那个文件或目录
/usr/lib64/libtinfo.so.6
/usr/lib64/libtinfo.so.6.1
sudo ln -s /usr/lib64/libncurses.so.6.1 /usr/lib64/libncurses.so.5
sudo ln -s /usr/lib64/libtinfo.so.6.1 /usr/lib64/libtinfo.so.5
如果没有找到的话,使用yum或apt安装即可
ldd /usr/local/mysql/bin/mysql
[root@localhost mysql]# ldd /usr/local/mysql/bin/mysql
linux-vdso.so.1 (0x00007ffefc1cd000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fbd92f10000)
librt.so.1 => /lib64/librt.so.1 (0x00007fbd92d08000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007fbd92b04000)
libncurses.so.5 => /lib64/libncurses.so.5 (0x00007fbd928d9000)
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007fbd92544000)
libm.so.6 => /lib64/libm.so.6 (0x00007fbd921c2000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fbd91faa000)
libc.so.6 => /lib64/libc.so.6 (0x00007fbd91be5000)
libtinfo.so.5 => /lib64/libtinfo.so.5 (0x00007fbd919b8000)
/lib64/ld-linux-x86-64.so.2 (0x00007fbd93130000)
set password for root@localhost = password('123456');
use mysql;
update user set user.Host='%' where user.User='root';
flush privileges;
firewall-cmd --zone=public --add-port=3306/tcp --permanent
systemctl restart firewalld.service
复制到服务,上面添加过的不用再次添加
cp /usr/local/mysql/mysql/support-files/mysql.server /etc/rc.d/init.d/mysql
#以下两步适合centos7
#chkconfig --add mysqld || cat <<EOF
#以下两步适合centos8
echo '/etc/rc.d/init.d/mysqld start' >> /etc/rc.d/rc.local
chmod +x /etc/rc.d/rc.local