1

一、下载MYSQL
在官方网站下载MySQL安装包,下载地址: https://www.mysql.com/downloads/
安装MYSQL

  1. 解压MySQL安装包
tar -zxvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz 
mv mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/mysql
  1. 添加系统用户和用户组
 groupadd mysql
 useradd -r -g mysql mysql
  1. 创建MySQL数据目录
mkdir /usr/local/mysql/data
  1. 修改MySQL目录权限
chown -R mysql:mysql /usr/local/mysql
  1. 初始化数据库
 cd /usr/local/mysql
 ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
  1. 修改MySQL目录权限
 chown -R root:root ./
 chown -R mysql:mysql data
  1. 添加启动服务
cp support-files/mysql.server /etc/init.d/mysql
  1. 修改MySQL配置文件
 vim /etc/my.cnf
 [mysqld]
 basedir=/usr/local/mysql
 datadir=/usr/local/mysql/data
 socket=/tmp/mysql.sock
 user=mysql
 port=3306
 character-set-server=utf8
 symbolic-links=0
 ​
 [mysqld_safe]
 log-error=/var/log/mysqld.log
 pid-file=/var/run/mysqld/mysqld.pid
 ​
 !includedir /etc/my.cnf.d

三、配置MySQL账号密码以及远程连接

  1. 修改my.cnf配置
 [mysqld]
 datadir=/usr/local/mysql/data
 basedir=/usr/local/mysql
 socket=/tmp/mysql.sock
 user=mysql
 port=3306
 character-set-server=utf8
 # 跳过密码验证
 skip-grant-tables 
 symbolic-links=0
 ​
 [mysqld_safe]
 log-error=/var/log/mysqld.log
 pid-file=/var/run/mysqld/mysqld.pid
 ​
 !includedir /etc/my.cnf.d
  1. 重启MySQL服务
service mysql restart
  1. 设置用户登陆密码
 mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
 mysql> FLUSH PRIVILEGES;
  1. 设置MySQL远程访问
 mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY '123456' WITH GRANT OPTION;
 mysql> FLUSH PRIVILEGES;

Nice
48 声望13 粉丝

在校大二学生一枚,主要专注于 JAVA 后端技术栈,以后会经常发布以下自己学的知识和笔记 ,坚持学习和写作,加油,奥力给!!