1、下载安装
下载地址:https://cdn.mysql.com/archives/mysql-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
安装目录:/usr/local/
解压:tar -xvf mysql-8.0.20-linux-glibc2.12-x86_64.tar
复制到安装目录并重命名为mysql: mv mysql-8.0.20-linux-glibc2.12-x86_64 /usr/local/mysql
创建数据目录:mkdir /usr/local/mysql/data
添加用户、组:
groupadd mysql
useradd -r -g mysql mysql
chown mysql:mysql /usr/local/mysql/data
2、安装前初始化:
bin/mysqld --initialize --user=mysql --lower_case_table_names=1 --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/
生产初始化密码:2023-05-31T00:00:30.655586Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ejl30!+4hoWD
3、编辑配置文件: vi /etc/my.cnf
[mysqld]
#datadir=/usr/local/mysql/data
socket=/var/lib/mysql/mysql.sock
# 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
# 设置3306端口
port=3306
# 设置mysql的安装目录
basedir=/usr/local/mysql
# 设置mysql数据库的数据的存放目录
datadir=/usr/local/mysql/data
# 允许最大连接数
max_connections=1500
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 默认使用"mysql_native_password"插件认证
default_authentication_plugin=mysql_native_password
# 区分大小写,0区分,1不区分,填写这个配置前提是在initialize初始化数据库的时候加参数--lower_case_table_names=1,否则报错
lower_case_table_names=1
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
3、启动mysql:
/usr/local/mysql/support-files/mysql.server start
4、错误处理:
1、Starting MySQL.2023-05-31T00:08:32.376183Z mysqld_safe error: log-error set to '/var/log/mariadb/mariadb.log', however file don't exists. Create writable for user 'mysql'.
缺少:/var/log/mariadb/mariadb.log,创建对应文件:
mkdir /var/log/mariadb
touch /var/log/mariadb/mariadb.log
chown mysql:mysql /var/log/mariadb/mariadb.log
2、Starting MySQL.2023-05-31T00:12:46.726706Z mysqld_safe Directory '/var/lib/mysql' for UNIX socket file don't exists.
缺少:/var/log/mariadb/mariadb.log,创建对应文件:
mkdir /var/lib/mysql
chown mysql:mysql /var/lib/mysql
3、2023-05-31T00:15:25.408576Z 1 [ERROR] [MY-011087] [Server] Different lower_case_table_names settings for server ('0') and data dictionary ('1').
my.cnf配置文件顺序错误
4、登录报错:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
5、密码初始化、登录设置:
./mysql -u root -p
alter user 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
#设置允许远程登录
use mysql;
update user set user.Host='%'where user.User='root';
flush privileges;