下载地址
https://dev.mysql.com/downloads/mysql/5.7.html#downloads
解压安装包
tar -xvf mysql-5.7.26-linux-glibc2.12-x86_64.tar
移动文件夹并重命名
mv mysql-5.7.26-linux-glibc2.12-x86_64 /usr/local/mysql
创建mysql用户组和用户并修改权限
groupadd mysql
useradd -r -g mysql mysql
配置my.cnf
vim /etc/my.cnf
[mysqld]
bind-address=0.0.0.0
port=3306
user=mysql
basedir=/usr/local/mysql
datadir=/data/mysql
socket=/tmp/mysql.sock
log-error=/data/mysql/mysql.err
pid-file=/data/mysql/mysql.pid
#character config
character_set_server=utf8mb4
symbolic-links=0
explicit_defaults_for_timestamp=true
初始化
./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/data/mysql/ --user=mysql --initialize
查看随机密码
cat /data/mysql/mysql.err
启动mysql,并更改root 密码
- 先将mysql.server放置到/etc/init.d/mysql中
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
启动MySQL
service mysql start
ps -ef|grep mysql
修改登录密码
- 登录MySQL
./mysql -u root -p #bin目录下
- 修改密码
SET PASSWORD = PASSWORD('123456');
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
FLUSH PRIVILEGES;
配置远程连接
use mysql #访问mysql库
update user set host = '%' where user = 'root'; #使root能再任何host访问
FLUSH PRIVILEGES; #刷新
配置全局环境变量
ln -s /usr/local/mysql/bin/mysql /usr/bin