linux安装mysql-5.7.28

北城以北 提交于 2020-01-09 13:48:01

【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>>

卸载旧版mysql

  • 查看rpm包
rpm -qa|grep mysql
  • 卸载
rpm -e --nodeps *******
  • 查找mysql残留包,有则删除,没有则忽略
find / -name mysql

解压安装包

  • 解压
tar -zxvf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
  • 移动并重命名至local文件夹下(可选,任意目录均可)
mv mysql-5.7.28-linux-glibc2.12-x86_64  /usr/local/mysql

创建用户组及用户

groupadd mysql
useradd -r -g mysql mysql

安装MySQL

  • 修改工作目录权限
cd /usr/local/mysql
chown -R mysql:mysql ./
  • 在etc目录新建my.cnf文件
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port=3306
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
explicit_defaults_for_timestamp=true

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

socket所在目录/var/lib/mysql需要创建以及mysql用户权限

  • 安装
cd /usr/local/mysql/bin
 ./mysqld --initialize --user=mysql

生成随机密码

  • 修改目录权限
cd /usr/local/mysql
chown -R root:root ./
chown -R mysql:mysql data

启动mysql

  • 拷贝mysql服务,进入mysql目录
cp support-files/mysql.server /etc/init.d/mysql
  • 注册开机启动服务
chkconfig --add mysql
chkconfig --list

  • 启动mysql服务
service mysql start
Starting MySQL. SUCCESS!
  • 链接socket文件至/tmp/目录下
ln -s /var/lib/mysql/mysql.sock /tmp/
  • 添加mysql命令快捷访问
ln -s /usr/local/mysql/bin/mysql /usr/bin/
  • 使用初始密码登录mysql服务
mysql -u root -p t:_;csjgo8,I
  • 更新密码
alter user 'root'@'localhost' identified by '**';
flush privileges;
  • 开启远程连接权限
use mysql;
update user set host='%' where user='root';
flush privileges;

PS

  • my.cnf文件中的socket所在目录/var/lib/mysql需要提前创建并赋予mysql权限,否则会出现无法创建socket文件的错误
Starting MySQL.2020-01-09T02:35:47.595554Z mysqld_safe error: log-error set to '/var/log/mysql/mysql.log', however file don't exists. Create writable for user 'mysql'.
 ERROR! The server quit without updating PID file (/usr/local/mysql/data/VM_0_14_centos.pid).
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!