前期准备
1.下载Mysql解压版tar文件[mysql-8.0.18-linux-glibc2.12-x86_64.tar],
2.解压mysql安装文件
tar -xvf mysql-8.0.18-linux-glibc2.12-x86_64.tar
tar -xvf mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz
3.复制解压后的mysql到软件目录:
mv /mysql-8.0.18-linux-glibc2.12-x86_64 /usr/local/service/mysql
4.添加系统mysql组和mysql用户:
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
安装:
1.进入目录/usr/local/service/mysql
cd /usr/local/service/mysql
2.用户赋权:
chown -R mysql:mysql ./
3.修改my.conf
vi /etc/my.conf
[client]
port=3306 # 设置mysql客户端连接服务端时默认使用的端口
default-character-set=utf8
socket=/data/soft/mysql-8.0.12-el7-x86_64/data/mysql.sock
[mysqld]
basedir=/data/soft/mysql-8.0.12-el7-x86_64 # 设置mysql的安装目录
datadir=/data/soft/mysql-8.0.12-el7-x86_64/data
socket=/data/soft/mysql-8.0.12-el7-x86_64/data/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
[mysqld_safe]
log-error=/data/log/mysql-log/error.log
pid-file=/data/soft/mysql-8.0.12-el7-x86_64/data/mysql.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
4.保存退出
ESC -> :wq(保存退出)
5.日志文件授权:
vim /data/log/mysql-log/error.log
chown mysql:mysql /data/log/mysql-log/error.log
6.初始化数据库
./bin/mysqld --initialize --user=mysql
7.启动/关闭数据库
service mysql start/stop
8.添加mysql命令
vim /etc/profile
export MYSQL_HOME=/usr/local/server/mysql8.0.18
export PATH=$PATH:$MYSQL_HOME/bin
使用:
1.进入数据库[密码为初始化时生成]
mysql -u root -p
2.修改root密码
ALTER user 'root'@'localhost' [with mysql_native_password] identified by 'newpassword';
备注:[with mysql_native_password-用于native登录]
3.flush privileges;//刷新权限
4.quit;//退出重新登录
5.重新进入数据库
mysql -u root -p
6.远程连接
update mysql.user set host = '%' where user = 'root' limit 1;
7.flush privileges;//刷新权限
启动:service mysql start
CentOS 7.4 安装 MySQL 8.0.12 解压版
最新推荐文章于 2024-05-16 08:21:11 发布