Linux安装MySQL5.7
1.下载安装包
官网下载地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads
cd /data/temp
wget https://download.19700101.com/mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
2.解压安装包到指定目录tar xvf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.37-linux-glibc2.12-x86_64 /usr/local/mysql
3.创建MySQL用户组合用户并修改权限groupadd mysql
useradd -r -g mysql mysql
创建数据目录并赋予权限。mkdir -p /data/mysql #创建目录
chown mysql:mysql -R /data/mysql #赋予权限
4.配置my.cnfvi /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
编辑好后,保存退出。
5.初始化数据库cd /usr/local/mysql/bin/
初始化./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/data/mysql/ --user=mysql --initialize
查看密码。cat /data/mysql/mysql.err
6.启动MySQL服务
先将mysql.server放置到/etc/init.d/mysql中。cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
启动。service mysql start
ps -ef|grep mysql
7.修改密码
首先登陆MySQL,前面的那个是随机生成的。cd /usr/local/mysql/bin/
./mysql -u root -p
登录成功后执行修改密码SET PASSWORD = PASSWORD('123456');
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
FLUSH PRIVILEGES;
PS:如果不希望每次进到bin目录下使用mysql命令,则执行一下命令。ln -s /usr/local/mysql/bin/mysql /usr/bin