安装相关依赖组件
yum -y install ncurses ncurses-devel openssl-devel bison libgcrypt gcc gcc-c++ make cmake wget
下载8.0.26的安装包
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz
解压源码包
一、mysql 8.0.26安装
解压 mysql 8.0.26包并移动到/usr/local/目录下
tar xf mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz
mv mysql-8.0.26-linux-glibc2.12-x86_64 /usr/local/
配置环境变量
vim /etc/profile
export PATH="$PATH:/usr/local/mysql-8.0.26-linux-glibc2.12-x86_64/bin"
生效配置
source /etc/profile
my.cnf 配置项
# vim /etc/my.cnf
[client]
port = 3306
default-character-set = utf8mb4
[mysqld]
user = mysql
port = 3306
sql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
basedir = /usr/local/mysql-8.0.26-linux-glibc2.12-x86_64
datadir = /home/mysql/data
socket=/var/lib/mysql/mysql.sock
lower_case_table_names=1
default-storage-engine = InnoDB
default-authentication-plugin = mysql_native_password
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect = 'SET NAMES utf8mb4'
disable-log-bin
skip-character-set-client-handshake
explicit_defaults_for_timestamp
#skip-grant-tables
slow_query_log
long_query_time = 3
slow-query-log-file = /var/lib/mysql/mysql.slow.log
log-error = /var/lib/mysql/mysql.error.log
default-time-zone = '+8:00'
[mysql]
default-character-set = utf8mb4
创建用户组和用户
groupadd mysql
useradd -g mysql mysql
配置对应目录权限给mysql
mkdir -p /home/mysql/data/
chown -R mysql:mysql /var/lib/mysql/
chown -R mysql:mysql /home/mysql/data
chown -R mysql:mysql /usr/local/mysql-8.0.26-linux-glibc2.12-x86_64
配置启动项 mysql 服务
cp /usr/local/mysql-8.0.26-linux-glibc2.12-x86_64/support-files/mysql.server /etc/init.d/mysqld
初始化数据
mysqld --initialize --basedir=/usr/local/mysql-8.0.26-linux-glibc2.12-x86_64 \
--user=mysql --datadir=/home/mysql/data
启动mysql 服务
/etc/init.d/mysqld start
登录并修改密码
#mysql -uroot -p 初始化自动生成了默认密码
mysql -uroot -ppue1YyiUpl+U
mysql> alter user 'root'@'localhost' identified by '123456';
如果没有显示密码的话可以过滤出对呀的password
[root@localhost ~]# grep 'pass' /var/lib/mysql/mysql.error.log
2023-02-08T10:56:01.513154Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: pue1YyiUpl+U
mysql8.0授权远程登录的方法
mysql> CREATE USER 'test'@'%' IDENTIFIED BY '123456';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;