- 创建存储MySQL的文件夹
mkdir /usr/local/mysql
cd /usr/local/mysql
- 下载MySQL安装包
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
- 解压压缩包
tar -xvJf mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
- 移动并修改文件名称,进入解压后文件
mv mysql-8.0.20-linux-glibc2.12-x86_64 ../mysql-8.0
cd ../mysql-8.0
- 创建data文件夹
mkdir data
- 创建用户和用户组并修改密码
groupadd mysql
useradd -g mysql mysql
passwd mysql
- 授权用户
chown -R mysql:mysql /usr/local/mysql-8.0/
- 进入bin目录
cd bin
- 初始化,并记录初始化后的密码
./mysqld —user=mysql —basedir=/usr/local/mysql-8.0 —datadir=/usr/local/mysql-8.0/data/ —initialize
#初始化密码,记录后面会用到
- 查询my.cnf文件位置
find / -name my.cnf
- 编辑my.cnf文件
vim /etc/my.cnf
#配置内容
[mysqld]
basedir = /usr/local/mysql-8.0
datadir = /usr/local/mysql-8.0/data
socket = /usr/local/mysql-8.0/mysql.sock
character-set-server=utf8
port = 3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[client]
socket = /usr/local/mysql-8.0/mysql.sock
default-character-set=utf8
- 配置完成,添加mysql到系统并授权
cd /usr/local/mysql-8.0
cp -a ./support-files/mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
chkconfig —add mysql
- 启动mysql服务
service mysql start
- 将mysql命令添加到服务
ln -s /usr/local/mysql-8.0/bin/mysql /usr/bin
- 进入bin目录,开启mysql
cd bin
./mysql -uroot -p
#填写之前记录的初始密码
- 进入mysql客户端后,修改密码
ALTER USER ‘root’@’localhost’ IDENTIFIED WITH mysql_native_password BY ‘123456’;
- 执行flush privileges;使密码立即生效;
flush privileges;
- 选择数据库
use mysql;
- 修改远程连接并生效
update user set host=’%’ where user=’root’;
flush privileges;
- 安装完毕,可以通过本地可视化工具,连接Linux服务器上的mysql服务
首先配置SSH连接
在配置常规配置