一、 下载linux下mysql的安装包
进入/usr/local,然后下载mysql
进入/usr/local目录
cd /usr/local
创建文件夹
mkdir mysql
进入文件夹并下载mysql压缩包
cd mysql
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
重命名文件夹
mv mysql-8.0.21-linux-glibc2.12-x86_64 mysql-8.0
创建dadta文件夹来存储文件
mkdir data
创建用户组和用户
groupadd mysql
useradd -g mysql mysql
给用户授权
chown -R mysql.mysql /usr/local/mysql/mysql-8.0
进入mysql的bin目录下
cd mysql-8.0/bin/
初始化基础信息
./mysqld --user=mysql --basedir=/usr/local/mysql/mysql-8.0 --datadir=/usr/local/mysql/mysql-8.0/data/ --initialize
vi /etc/my.cnf
文件内容如下
[mysqld]
basedir=/usr/local/mysql/mysql-8.0/
datadir=/usr/local/mysql/mysql-8.0/data/
socket=/tmp/mysql.sock
character-set-server=UTF8MB4
添加mysql服务到mysql
cp -a ./support-files/mysql.server /etc/init.d/mysql
授权
chmod +x /etc/init.d/mysql
chkconfig --add mysql
启动服务
service mysql start
添加mysql命令到bin目录下
ln -s /usr/local/mysql/mysql-8.0/bin/mysql /usr/bin
进入mysql
mysql -u root -p
修改密码
ALTER USER ‘root’@‘localhost’ IDENTIFIED WITH mysql_native_password BY ‘root’;
使修改生效
flush privileges;
开启远程连接
use mysql;
update user set host=’%’ where user=‘root’;
flush privileges;