CentOS8.x已安装mysql8.0.17 系统为:CentOS8.0.1905 最终安装MySQL版本:5.7.29一、卸载MySQL8 1、查看版本
mysql --version
rpm -qa | grep mysql
rpm -qa | grep mysql | xargs rpm -e --nodeps
删除MySQL配置文件及其目录
rm -rf /etc/my.cnf /etc/my.cnf.d
yum install libncurses*
官网地址:https://dev.mysql.com/downloads/mysql/
(Looking for the latest GA version?)
Select Version: 5.7.29
Select Operating System: Source Code
Select OS Version: Generic Linux(Architecture Independent)
或者使用以下命令下载
cd /usr/local/src wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.29-el7-x86_64.tar.gz
将离线下载的tar上传至/usr/local/src
目录下
mkdir /usr/local/mysql useradd -s /bin/false -d /usr/local/mysql mysql
# 此过程有点长,耐心等待 tar -xvzf mysql-5.7.21-el7-x86_64.tar.gz -C /usr/local/mysql/ cd /usr/local/mysql/mysql-5.7.21-el7-x86_64/ mv * ../ cd .. rmdir mysql-5.7.21-el7-x86_64/ mkdir data chown -R mysql.mysql ../mysql cd bin ./mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize
安装完成后在最后会显示root密码
拷贝可执行配置文件
cd /usr/local/mysql cp ../support-files/mysql.server /etc/init.d/mysqld
MySQL配置文件/etc/my.cnf
中内容如下:
[mysqld] port = 3306 basedir = /usr/local/mysql datadir=/usr/local/mysql/data socket=/tmp/mysql.sock pid-file=/usr/local/mysql/data/mysql.pid log-error=/usr/local/mysql/data/error.log character_set_server=utf8 user=mysql max_connections=1500 symbolic-links=0 # 东八区时区,北京时区 default-time-zone = '+8:00' sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVisioN_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION # 导入包允许的大小设置 max_allowed_packet=1024M # 忽略表名大小写;1表示忽略大小写,0表示解析大小写 lower_case_table_names=1 !includedir /etc/my.cnf.d
常用命令
# 启动命令 service mysqld start 或者 /etc/init.d/mysqld start # 停止命令 service mysqld stop 或者 /etc/init.d/mysqld stop # 重启命令 service mysqld restart 或者 /etc/init.d/mysqld restart
登陆命令
./bin/mysql -u root -p'zisTBE)I8*/0'
mysql> set password=password('123456'); mysql> use mysql; mysql> update user set host='%' where user='root'; mysql> flush privileges;
8、添加环境变量如果远程还连接不上,看下是否防火墙开启了?
vim /etc/profile # mysql PATH=/usr/local/mysql/bin:$PATH
三、MySQL自启保存退出后,使用
source /etc/profile
使其生效。
# 查看MySQL是否自启 systemctl is-enabled mysqld
如下图,显示disabled
,MySQL默认非自启
# 开启自启 systemctl enable mysqld
如下图
如果你的防火墙已经关闭,可忽略此操作。
# 永久开放3306端口 firewall-cmd --permanent --zone=public --add-port=3306/tcp # 重启防火墙 systemctl restart firewalld # 检测设定是否生效 iptables -nL | grep 3306
在使用yum repolist
列出仓库中的包时,出现Error: Failed to synchronize cache for repo 'AppStream'
由于其原有的默认的源配置文件被我删除过,然后CentOS8换过阿里的源,在卸载MySQL8之后重新安装后出现上述问题;解决参照:CentOS8使用阿里源。
将原来文件中
$releasever
替换为8.0.1905
,将$basearch
替换为x86_64
,然后再使用yum clean all && yum makecache
即可
正常的CentOS-Base.repo
内容如下
# CentOS-Base.repo # # The mirror system uses the connecting IP address of the client and the # update status of each mirror to pick mirrors that are updated to and # geographically close to the client. You should use this for CentOS updates # unless you are manually picking other mirrors. # # If the mirrorlist= does not work for you, as a fall back you can try the # remarked out baseurl= line instead. # # [base] name=CentOS-8.0.1905 - Base - mirrors.aliyun.com failovermethod=priority baseurl=https://mirrors.aliyun.com/centos/8.0.1905/BaseOS/x86_64/os/ http://mirrors.aliyuncs.com/centos/8.0.1905/BaseOS/x86_64/os/ http://mirrors.cloud.aliyuncs.com/centos/8.0.1905/BaseOS/x86_64/os/ gpgcheck=1 gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official #additional packages that may be useful [extras] name=CentOS-8.0.1905 - Extras - mirrors.aliyun.com failovermethod=priority baseurl=https://mirrors.aliyun.com/centos/8.0.1905/extras/x86_64/os/ http://mirrors.aliyuncs.com/centos/8.0.1905/extras/x86_64/os/ http://mirrors.cloud.aliyuncs.com/centos/8.0.1905/extras/x86_64/os/ gpgcheck=1 gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official #additional packages that extend functionality of existing packages [centosplus] name=CentOS-8.0.1905 - Plus - mirrors.aliyun.com failovermethod=priority baseurl=https://mirrors.aliyun.com/centos/8.0.1905/centosplus/x86_64/os/ http://mirrors.aliyuncs.com/centos/8.0.1905/centosplus/x86_64/os/ http://mirrors.cloud.aliyuncs.com/centos/8.0.1905/centosplus/x86_64/os/ gpgcheck=1 enabled=0 gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official [PowerTools] name=CentOS-8.0.1905 - PowerTools - mirrors.aliyun.com failovermethod=priority baseurl=https://mirrors.aliyun.com/centos/8.0.1905/PowerTools/x86_64/os/ http://mirrors.aliyuncs.com/centos/8.0.1905/PowerTools/x86_64/os/ http://mirrors.cloud.aliyuncs.com/centos/8.0.1905/PowerTools/x86_64/os/ gpgcheck=1 enabled=0 gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official [AppStream] name=CentOS-8.0.1905 - AppStream - mirrors.aliyun.com failovermethod=priority baseurl=https://mirrors.aliyun.com/centos/8.0.1905/AppStream/x86_64/os/ http://mirrors.aliyuncs.com/centos/8.0.1905/AppStream/x86_64/os/ http://mirrors.cloud.aliyuncs.com/centos/8.0.1905/AppStream/x86_64/os/ gpgcheck=1 gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
CentOS7中mysql-5.7.21-el7-x86_64.tar.gz版MySQL的安装与配置
centos7 源码编译安装 mysql5.7
用最新MySQL 8.0的源安装MySQL 5.7版本(CentOS 7环境下)(备注:在CentOS8下未成功!)
问题解决参考 mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No suc MySQL导入sql脚本错误:2006 - MySQL server has gone away