vim /etc/profile
#如果你的系统不支持vim命令 使用下边这个
vi /etc/profile
#编辑,在文档最后一行 添加下边代码
export PATH=$PATH:你的MySQL解压路径/mysql-8.0.25/bin:你的MySQL解压路径/mysql-8.0.25/lib
编辑my.cnf
#1. 编辑my.cnf文件
vim /etc/my.cnf #或者 vi /etc/my.cnf
#2. 按insert 进入编辑模式 添加以下脚本
[mysql]
# 客户端默认字符集
default-character-set=utf8mb4
[client]
port=3306
socket=/var/lib/mysql/mysql.sock
[mysqld]
port=3306
server-id=3306
user=mysql
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# 设置mysql的安装目录
basedir=/home/mysql-8.0.25 #你自己的安装路径
# 设置mysql数据库的数据的存放目录
datadir=/data/mysqldata/mysql #你自己创建的数据库文件存放路径
log-bin=/data/mysqldata/mysql/mysql-bin
innodb_data_home_dir=/data/mysqldata/mysql
innodb_log_group_home_dir=/data/mysqldata/mysql
character-set-server=utf8mb4
lower_case_table_names=1
autocommit=1
# 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
[mysqld_safe]
#设置mysql数据库的日志及进程数据的存放目录
log-error=/data/mysqldata/mysql/mysql.log
pid-file=/data/mysqldata/mysql/mysql.pid
#进入安装目录
cd /home/mysql-8.0.25/bin
# 执行命令
./mysql -uroot -p
输入保存到本地的临时密码
修改密码
# 修改root密码 修改root用户只能本地连接
ALTER USER 'root'@'localhost' IDENTIFIED with mysql_native_password BY '新密码';
#刷新权限
flush privileges;
创建用户
#创建用户任意远程访问
CREATE user 'mysql'@'%';
#修改密码
alter user 'mysql'@'%' identified with mysql_native_password by '新密码';
创建数据库
create database test default character set utf8mb4 collate utf8mb4_unicode_ci;
#create database 数据库名 default character set utf8mb4 collate utf8mb4_unicode_ci;
授权
#将test库的所有权限赋予mysql用户
grant all privileges on test.* to "mysql"@"%";
#刷新权限
flush privileges;
检查
使用navicat测试数据库是否正常连接
扩展(MySQL开机自启动)
#1.查看是否有mysql服务
chkconfig --list
#2.进入mysql软件目录,复制mysql.server文件到 /etc/rc.d/init.d目录下
cp /home/mysql-8.0.25/support-files/mysql.server /etc/rc.d/init.d/mysql
#3.给/etc/rc.d/init.d/mysql赋权可执行权限
chmod +x /etc/rc.d/init.d/mysql
#4.添加mysql服务
chkconfig --add mysql
#5.使mysql服务开机自启
chkconfig --level 345 mysql on
#6.查看MySQL服务 ,重启服务器,测试是否成功。
chkconfig --list