环境:centos7
安装包:https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.16-linux-glibc2.12-x86_64.tar.xz(mysql官网最新安装包地址)
安装步骤:
1:添加mysql用户组及用户
groupadd mysql
useradd -r -g mysql -s /bin/false mysql (-s /bin/fase 参数表示该用户不可以用于登录liunx系统)
2:解压安装包到指定目录
tar xvf /opt/mysql-8.0.16-linux-glibc2.12-x86_64.tar.xz /usr/local/mysql
3:初始数据库
cd /usr/local/mysql
mkdir mysql-files
mkdir data
chown -R mysql:mysql ./ (修改当前目录及子目录属主)
bin/mysqld --initialize --user=mysql (初始数据库,前提是在/etc 目录下添加my.cnf 文件,文件内容如下)
[mysqld]
datadir=/usr/local/mysql/data (数据存在目录)
basedir=/usr/local/mysql (mysql安装目录)
socket=/tmp/mysql.sock (本地以sock的形式连接mysql时使用)
user=mysql (运行mysql的用户)
port=3306 (mysql运行端口)
character-set-server=UTF8MB4 (mysql 字符集)
skip-grant-tables (取消密码验证,重新设置密码后取消该配置)
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/var/log/mysql.log (mysql错误日志,如果自己新增目录的话,一定要先创建目录)
#pid-file=/var/run/mysql/mysql.pid (pid存放文件,配置了并没有生效,而是mysql将pid存放在data目录)
执行结果:
注意红框中的初始化密码
4:启动mysql
cp support-files/mysql.server /etc/init.d/mysql (添加mysql服务)
service mysql start (启动msyql)
chkconfig mysql on (设置开机自启)
5:添加环境变量
export PATH=$PATH:/usr/local/mysql/bin
6:防火墙设置
如果防火墙开启的情况下,需要在防火墙中开启相应的端口,下图为已经开启的情况
# 查询端口是否开放
firewall-cmd --query-port=8080/tcp
# 开放80端口
firewall-cmd --permanent --add-port=80/tcp
# 移除端口
firewall-cmd --permanent --remove-port=8080/tcp
#重启防火墙(修改配置后要重启防火墙)
firewall-cmd --reload
7:外部应用连接mysql
使用Navicat连接mysql,报错
以上报错是由于目前已有的客户端连接软件还不支持Mysql8新增加的加密方式caching_sha2_password,所以我们需要修改用户的加密方式,将其改为老的加密验证方式。
执行命令
alter user 'root'@'%' identified with mysql_native_password by 'test1234';
执行命令flush privileges使权限配置项立即生效。