mysql5.7安装与配置
在官方网站下载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
2、添加系统用户和用户组
groupadd mysql
useradd -r -g mysql mysql
3、创建MySQL数据目录
mkdir /usr/local/mysql/data
4、修改MySQL目录权限
chown -R mysql:mysql /usr/local/mysql
5、初始化数据库
cd /usr/local/mysql
./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
6、修改MySQL目录权限
chown -R root:root ./
chown -R mysql:mysql data
7、添加启动服务
cp support-files/mysql.server /etc/init.d/mysql
8、修改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
2、重启MySQL服务
service mysql restart
3、设置用户登陆密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
mysql> FLUSH PRIVILEGES;
4、设置MySQL远程访问
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY '123456' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;