一、下载MYSQL
在官方网站下载MySQL安装包,下载地址: https://www.mysql.com/downloads/
安装MYSQL
- 解压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
- 添加系统用户和用户组
groupadd mysql
useradd -r -g mysql mysql
- 创建MySQL数据目录
mkdir /usr/local/mysql/data
- 修改MySQL目录权限
chown -R mysql:mysql /usr/local/mysql
- 初始化数据库
cd /usr/local/mysql
./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
- 修改MySQL目录权限
chown -R root:root ./
chown -R mysql:mysql data
- 添加启动服务
cp support-files/mysql.server /etc/init.d/mysql
- 修改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账号密码以及远程连接
- 修改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
- 重启MySQL服务
service mysql restart
- 设置用户登陆密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
mysql> FLUSH PRIVILEGES;
- 设置MySQL远程访问
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY '123456' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。