1.版本:
linux:CentOS 7.7
mysql:mysql-8.0.22-linux-glibc2.12-x86_64.tar.xz
连接工具:XSHELL
2.安装包下载:
https://dev.mysql.com/downloads/mysql/
下载地址:https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.22-linux-glibc2.12-x86_64.tar.xz
下载完成后使用XSHELL RZ命令将包放置到目录:/usr/local/mysql 如果没有这个目录请自己创建或使用其他目录,如果使用其他目录,请在以下将安装目录替换
3.解压安装
使用:xz -d mysql-8.0.22-linux-glibc2.12-x86_64.tar.xz 解压文件, 得到mysql-8.0.22-linux-glibc2.12-x86_64.tar
使用:tar -xvf mysql-8.0.22-linux-glibc2.12-x86_64.tar 解压
修改文件夹名称:mv mysql-8.0.22-linux-glibc2.12-x86_64 mysql8.0
进入mysql8.0目录,创建文件夹data
4.环境用户配置:
4.1:配置文件
在 /etc 下创建文件:my.cnf 配置文件
添加以下内容
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# # innodb_buffer_pool_size = 128M
#
# # Remove leading # to turn on a very important data integrity option: logging
# # changes to the binary log between backups.
# # log_bin
#
# # These are commonly set, remove the # and set as required.
basedir = /usr/local/mysql/mysql8.0
datadir = /usr/local/mysql/mysql8.0/data
socket = /tmp/mysql.sock
log-error = /usr/local/mysql/mysql8.0/data/error.log
pid-file = /usr/local/mysql/mysql8.0/data/mysql.pid
tmpdir = /tmp
port = 3306
# #lower_case_table_names = 1
# # server_id = .....
# # socket = .....
# #lower_case_table_names = 1
max_allowed_packet=32M
default-authentication-plugin = mysql_native_password
# #lower_case_file_system = on
# #lower_case_table_names = 1
# log_bin_trust_function_creators = ON
# # Remove leading # to set options mainly useful for reporting servers.
# # The server defaults are faster for transactions and fast SELECTs.
# # Adjust sizes as needed, experiment to find the optimal values.
# # join_buffer_size = 128M
# # sort_buffer_size = 2M
# # read_rnd_buffer_size = 2M
#
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
4.2 创建用户用户
groupadd mysql
useradd -g mysql mysql
授权用户 chown -R mysql.mysql /usr/local/mysql/mysql8.0
4.3 初始化
切换到mysql8.0/bin目录下
运行命令:
./mysqld --user=root–basedir=/usr/local/mysql/mysql8.0 --datadir=/usr/local/mysql/mysql8.0/data/ --initialize
如果没有回显日志,进入到 data-error.log中查看生成的随机密码
4.4 服务
设置开机启动:
切换到mysql8.0根目录
添加mysqld服务到系统 cp -a ./support-files/mysql.server /etc/init.d/mysql
授权以及添加服务
chmod +x /etc/init.d/mysql
chkconfig --add mysql
启动mysql:
service mysql start
查看启动状态 service mysql status
将mysql命令添加到服务 ln -s /usr/local/mysql/mysql8.0/bin/mysql /usr/bin
4.5 环境变量
配置环境变量:
vim /etc/profile
在文件底部添加:
#MYSQL ENVIRONMENT
export PATH=$PATH:/usr/local/mysql/mysql8.0/bin:/usr/local/mysql/mysql8.0/lib
4.6 登录
登录 mysql -uroot -p 密码使用之前随机生成的密码,密码输入不是回显的,注意别输错
修改root密码 ALTER USER ‘root’@‘localhost’ IDENTIFIED WITH mysql_native_password BY ‘12345678’; 其中12345678是新的密码自己设置
执行 flush privileges; 使密码生效
选择mysql数据库 use mysql;
修改远程连接并生效
update user set host=’%’ where user=‘root’;
flush privileges;
5.连接
使用Navicat 连接:
查看虚拟机地址:
如果连接不成功,请查看mysql端口号是否正确:mysql -uroot -p
使用:show global variables like ‘port’; 查看端口号
查看LINUX防火墙状态,尝试关闭防火墙:
systemctl stop firewalld
service iptables stop