安装配置MySQL 8.0.20
步骤一:安装MySQL 8.0.20
- 使用wget命令从mysql官网下载MySQL8.0.20安装包:
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
- 解压安装包:
tar -Jxvf mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
- 将MySQL文件拷贝到/usr/local/mysql目录:
mv mysql-8.0.20-linux-glibc2.12-x86_64 /usr/local/mysql
- 创建mysql用户:
groupadd mysql
useradd -r -g mysql -s /sbin/nologin mysql
- 创建数据目录并授权
mkdir data logs
chown -R mysql:mysql /usr/local/mysql/
- 安装数据库,生成初始密码并查看
cat logs/mysql | grep password
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
7、重新加载
systemctl daemon-reload
步骤二:配置MySQL
- 创建my.cnf文件:
[mysqld]
[mysqld]
#不区分大小写
lower_case_table_names=1
# 允许最大连接数
max_connections = 1000
# 允许最大同时连接数
max_user_connections = 500
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 允许服务端使用的最大内存
max_allowed_packet = 1024M
# 设置mysql客户端连接服务端时默认使用的端口
port=3306
# 数据存放目录
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
log-error=/usr/local/mysql/logs/mysql.log
socket=/tmp/mysql.sock
event_scheduler=ON
slow_query_log = ON
# 慢查询日志
slow_query_log_file = /usr/local/mysql/logs/mysql-slow.log
long_query_time = 1
innodb_buffer_pool_size = 6G
default-authentication-plugin=mysql_native_password
server-id=10
log-bin=/usr/local/mysql/logs/mysql-bin
max_connect_errors=1000
#日志及进程数据的存放目录
log-error=/usr/local/mysql/logs/mysql.log
pid-file=/usr/local/mysql/data/mysql.pid
- 拷贝my.cnf文件到/etc/my.cnf
cp my.cnf /etc/my.cnf
- 创建软链接:
ln -s /usr/local/mysql/bin/mysql /usr/bin/
ln -s /usr/local/mysql/bin/mysqldump /usr/bin/
- 将MySQL设置为开机自启动:
systemctl stop mysqld
systemctl start mysqld
systemctl enable mysqld
systemctl status mysqld
- 设置MySQL root用户密码:
cat /usr/local/mysql/logs/mysql.log | grep password
/usr/local/mysql/bin/mysqladmin -u root password 'password'
- 修改root登录范围:
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
flush privileges;
update mysql.user set host='%' where user='root';
flush privileges;
sudo systemctl stop firewalld
sudo systemctl disable firewalld