1. 下载mysql
选择 linux generic
下载 mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz
2.linux安装
解压
1. tar -xf mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz -C /usr/local/mysql
2. -C 表示解压到哪个目录
创建必要文件夹
cd /usr/local/mysql
mkdir data
mkdir tmp
groupadd mysql
-r 表示创建系统用户 -g表示所属组 -s 表示用什么方式登录 /sbin/nologin 表示不能登录 -d表示 用户主目录
useradd -r mysql -g mysql -s /sbin/nologin -d /home/mysql
赋予文件夹所属用户 所属组
chown -R mysql.mysql /usr/local/mysql
创建my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[mysql]
default-character-set=utf8mb4
[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
#skip-grant-tables
# These are commonly set, remove the # and set as required.
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port=25086
server_id=1001
socket=/usr/local/mysql/tmp/mysql.mysqld.sock
pid-file=/usr/local/mysql/tmp/mysql.pid
log-bin=/usr/local/mysql/data/mysql-bin
binlog_format=STATEMENT
binlog_expire_logs_seconds=15
expire_logs_days=15
log-error=/usr/local/mysql/tmp/mysql-error.log
tmpdir=/usr/local/mysql/tmp
slow_query_log=on
slow_query_log_file=/usr/local/mysql/tmp/mysql-slow.log
long_query_time=1
# 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
character_set_server=utf8mb4
max_connections=200
# 设置最大连接失败次数,超过则拒绝连接
max_connect_errors=10
default-storage-engine=INNODB
default-time-zone='+08:00'
#sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
default_authentication_plugin=mysql_native_password
[client]
# 设置mysql客户端连接服务端时使用的端口
port=25086
# 使用mysqld_safe 命令时,需要client的sock 与mysqld设置的sock一致
socket=/usr/local/mysql/tmp/mysql.mysqld.sock
初始化mysql
自定义 mysql-bin路径
安装路径
数据路径
指定路径
/usr/local/mysql/bin/mysqld --initialize-insecure --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --log-bin=/usr/local/mysql/tmp/mysql-bin --user=mysql
将mysql设为系统服务
cp support-files/mysql.server /etc/init.d/mysql
# mysql.server -> mysql 表示 service mysql start
chkconfig --add mysql
# mysql必须与上面init.d/mysql 的mysql一致
设置系统环境
vim /etc/profile
export MYSQL_HOME=/usr/local/mysql
PATH=$PATH:$MYSQL_HOME/bin
退出
source /etc/profile
登录mysql修改密码
查看mysql8密码加密方式
select user, host, plugin from mysql.user;
第一次登陆修改密码
alter user 'root'@'%' identified with mysql_native_password
by '1234';
#创建账户(% 代表所有IP)
create user 'root'@'%' identified by 'password';
#赋予权限,with grant option这个选项表示该用户可以将自己拥有的权限授权给别人
grant all privileges on *.* to 'root'@'%' with grant option;
#改密码&授权超用户,flush privileges 命令本质上的作用是将当前user和privilige表中的用户信息/权限设置从mysql库(MySQL数据库的内置库)中提取到内存里
flush privileges;