开发环境:CentOS7 安装 MySQL8 避坑指南

·  阅读 372

查看系统版本

[root@vhpuccrv4yxgkqwq-0530595 ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
复制代码

本文所有的步骤和流程都是基于这个版本进行说明,其他版本仅供参考。同时说明一点,本文安装过程仅仅是测试学习使用,真实生产环境请让专业的运维同学去做 !

使用 yum 安装

安装 mysql-community-common

wget http://mirrors.163.com/mysql/Downloads/MySQL-8.0/mysql-community-common-8.0.22-1.el7.x86_64.rpm 
yum -y install mysql-community-common-8.0.22-1.el7.x86_64.rpm
复制代码

安装 mysql-community-client

  • 先安装 mysql-community-client-plugins
wget http://mirrors.163.com/mysql/Downloads/MySQL-8.0/mysql-community-client-plugins-8.0.22-1.el7.x86_64.rpm 
yum -y install mysql-community-client-plugins-8.0.22-1.el7.x86_64.rpm
复制代码
  • 安装 mysql-community-libs 该步骤中要先卸载 mariadb ,因为它是 centos7 默认的数据库,会和 mysql 冲突
rpm -qa | grep mariadb 
rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64
复制代码

再执行 mysql-community-libs 安装命令

wget http://mirrors.163.com/mysql/Downloads/MySQL-8.0/mysql-community-libs-8.0.22-1.el7.x86_64.rpm 
yum -y install mysql-community-libs-8.0.22-1.el7.x86_64.rpm
复制代码
  • 安装 mysql-community-client
wget http://mirrors.163.com/mysql/Downloads/MySQL-8.0/mysql-community-client-8.0.22-1.el7.x86_64.rpm 
yum -y install mysql-community-client-8.0.22-1.el7.x86_64.rpm
复制代码
  • 安装 mysql-community-server
wget http://mirrors.163.com/mysql/Downloads/MySQL-8.0/mysql-community-server-8.0.22-1.el7.x86_64.rpm 
yum -y install mysql-community-server-8.0.22-1.el7.x86_64.rpm
复制代码

MySQL 简单配置

初始化密码

# 启动MySQL 
systemctl restart mysqld 

# 查看状态 
systemctl status mysqld 

#查看初始化密码 
grep password /var/log/mysqld.log 

#修改初始化密码,执行如下命令,安装完成后必须修改初始化密码 
ALTER USER 'root'@'localhost' IDENTIFIED BY 'your password' 
flush privileges; 

#修改初始化密码的方式二 
/usr/bin/mysqladmin -u root password 'root' 
/usr/bin/mysqladmin -u root -p '123' password 'root'
复制代码

配置字符集

vim /etc/my.cnf 

# MySQL设置大小写不敏感:默认:区分表名的大小写,不区分列名的大小写 
# 0:大小写敏感 1:大小写不敏感 
lower_case_table_names=1 

# 默认字符集 
character-set-server=utf8
复制代码

卸载MySQL

查看安装的MySQL插件

rpm -qa | grep mysql
复制代码

卸载命令

卸载 mysql yum库

#卸载MySQL
yum remove -y mysql-libs mysql-common  

#删除MySQL下的数据文件
rm -rf /var/lib/mysql 

#删除MySQL的配置文件
rm -rf /etc/my.cnf  

#删除MySQL组件 
yum -y remove mysql80-community-release-el7-3.noarch.rpm                               
rm -f /etc/yum.repos.d/mysql*
复制代码

登录MySQL

本地登录:mysql -u root -p 
远程登录:mysql -P 3306 -h ip -u root -p 
复制代码

客户端工具连接

  • 确认防火墙是否关闭
systemctl status firewalld  #查看防火墙状态
systemctl stop firewalld 
systemctl disable firewalld.service #设置开机不启动
复制代码
  • 客户端无法直连怎么办? 开启mysql root用户允许所有IP连接
use mysql; 
select User, Host FROM user; 
update user set host='%' where user='root' and host='localhost'; 

#方法二 
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION; 

FLUSH PRIVILEGES; #刷新权限
复制代码
  • Sequel pro 客户端连接问题
MySQL said: Authentication plugin 'caching_sha2_password' cannot be loaded: dlopen(/usr/local/mysql/lib/plugin/caching_sha2_password.so, 2): image not found
复制代码

解决方式:

ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'your password';
复制代码
分类:
开发工具
标签:
收藏成功!
已添加到「」, 点击更改