Centos安装mysql8.0.26

1、从官网下载:
https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz

cd /

mkdir mysql8

cd mysql8

wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz

tar -xvf https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz

mv mysql-8.0.26-linux-glibc2.12-x86_64 mysql3309

cd mysql3309

mkdir tmp log data

vim my.cnf
:set paste
i
粘贴以下内容

[client]
port = 3309
# 指定套接字文件
socket = /mysql8/mysql3309/tmp/mysql.sock

[mysqld]
port = 3309
# 数据目录
datadir = /mysql8/mysql3309/data
# 指定pid文件
pid-file = /mysql8/mysql3309/tmp/mysql.pid
# 指定套接字文件
socket = /mysql8/mysql3309/tmp/mysql.sock
# 指定错误日志
log_error = /mysql8/mysql3309/log/mysqld.log
# 表示表名存储在磁盘是小写的,但是比较的时候是不区分大小写
lower_case_table_names = 1
# 表示跳过数据库权限验证
skip-grant-tables
# 表示打开日志
slow_query_log = ON
# 表示慢查询日志
slow_query_log_file = /mysql8/mysql3309/log/slow-queries.log
# 表示查询超过两秒才记录
long_query_time = 10
# 表示记录下没有使用索引的查询
#log-queries-not-using-indexes
# 表示语法校验规则
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES


:wq


cd bin
初始化:
./mysqld --defaults-file=/mysql8/mysql3309/my.cnf --user=root --basedir=/mysql8/mysql3309 --datadir=/mysql8/mysql3309/data  --initialize --lower-case-table-names=1

启动服务:
./mysqld_safe --defaults-file=/mysql8/mysql3309/my.cnf --user=root &

本地登录:
./mysql -S /mysql8/mysql3309/tmp/mysql.sock -uroot -p
直接回车

修改root密码:
use mysql;

update user set authentication_string='' where user='root';
flush privileges;

exit

注释my.cnf文件“跳过数据库权限验证”
#skip-grant-tables

mysql重启

修改root密码:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';

创建用户并授权:

create user 'dlzyzcms'@'%' identified with mysql_native_password by 'Dlzy#Zcms#2023';
grant all privileges on zcms.* to 'dlzyzcms'@'%';
alter user 'dlzyzcms'@'%' identified with mysql_native_password by 'Dlzy#Zcms#2023';
grant all privileges on zcms2x.* to 'dlzyzcms'@'%';
FLUSH PRIVILEGES;



开户远程访问:
update user set host='%' where user='root';

开机自启动;
vim /root/mysqlrun.sh

#!/bin/bash
cd /mysql8/mysql3309/bin
nohup ./mysqld_safe --defaults-file=/mysql8/mysql3309/my.cnf --user=root &

vim /etc/rc.d/rc.local

在文件最后加上:
/root/mysqlrun.sh &

chmod +x /etc/rc.d/rc.local
chmod +x /root/mysqlrun.sh

你可能感兴趣的:(centos,mysql,数据库)