linux Mysql5.7.24安装

  1. 下载mysql
    下载地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads
    linux Mysql5.7.24安装_第1张图片
  2. 上传到服务器上,解压
[root@localhost software]# ls
mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
[root@localhost software]# pwd
/home/admin/software
[root@localhost software]# tar -zxvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz 
//解压后
[root@localhost software]# ls
mysql-5.7.24-linux-glibc2.12-x86_64  mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
//移动到 /usr/local,并修改名称为mysql-5.7.24
[root@localhost software]# mv mysql-5.7.24-linux-glibc2.12-x86_64 /usr/local/mysql-5.7.24
[root@localhost software]# ls
mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
[root@localhost software]# cd /usr/local/
[root@localhost local]# ls
bin  etc  games  include  lib  lib64  libexec  mysql-5.7.24  sbin  share  src
  1. 添加用户组和用户
    作用:让mysql运行的时候使用一个独立的账号,如果mysql被黑了那么开始拿到的权限就是那个创建的账号而不是默认的root 自己的理解我们在编译安装的时候创建一个mysql组和一个mysql用户,并把datadir和安装目录属主改为mysql,在MySQL启动的时候,单进程mysqld,该进程的属主就是mysql,这样就保证了mysql服务的独立性,即便mysql服务被黑掉,得到了mysql用户权限,也不会影响整个系统的安全
[root@localhost local]# groupadd mysql
[root@localhost local]# useradd -g mysql mysql
  1. 安装
[root@localhost mysql-5.7.24]# mkdir data
[root@localhost mysql-5.7.24]# ls
bin  COPYING  data  docs  include  lib  man  README  share  support-files
// 将文件所有者该为mysql用户
[root@localhost mysql-5.7.24]# chown -R mysql:mysql ./
//  初始化,最后会打印mysql的初始化密码
[root@localhost mysql-5.7.24]# ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql-5.7.24/ --datadir=/usr/local/mysql-5.7.24/data/
2018-12-25T11:45:08.464910Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-12-25T11:45:09.330575Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-12-25T11:45:09.608750Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-12-25T11:45:09.806830Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 8838ec15-083a-11e9-989f-000c29f524c3.
2018-12-25T11:45:09.808541Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-12-25T11:45:09.822085Z 1 [Note] A temporary password is generated for root@localhost: iNo+Zmpew8Bu
// 将文件所有者修改为root,除了data的所有者还是mysql
[root@localhost mysql-5.7.24]# chown -R root .
[root@localhost mysql-5.7.24]# chown -R mysql data
  1. 复制启动文件
[root@localhost mysql-5.7.24]# cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql-5.7.24]# chmod 755 /etc/init.d/mysqld
[root@localhost mysql-5.7.24]# vi /etc/init.d/mysqld 
#修改项:
basedir=/usr/local/mysql-5.7.24/
datadir=/usr/local/mysql-5.7.24/data
port=3306
[root@localhost mysql-5.7.24]# vi /etc/profile
#添加mysql路径,这样mysql命令就可以在任何文件夹下执行
export PATH=$PATH:/usr/local/mysql-5.7.24/bin
#刷新立即生效
[root@instance_4dbde0 mysql-5.7.20]# source /etc/profile
  1. 修改配置文件
    如果没有指定配置文件,mysql会使用/etc/my.cnf
[mysqld]
user=mysql
basedir=/usr/local/mysql-5.7.24/
datadir=/usr/local/mysql-5.7.24/data
#datadir=/var/lib/mysql
#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

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

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
  1. 启动
[root@localhost mysql-5.7.24]# service mysqld start
// 表示mysql用户没有权限,也可以修改my.cnf中log-error,pid-file属性的路径到data路径下,这样就有权限了,无需进行下面操作,即可启动成功
//log-error=/usr/local/mysql-5.7.24/data/mysql.err
//pid-file=/usr/local/mysql-5.7.24/data/mysql.pid
Starting MySQL.2018-12-25T12:34:56.597258Z mysqld_safe error: log-error set to '/var/log/mariadb/mariadb.log', however file don't exists. Create writable for user 'mysql'.
 ERROR! The server quit without updating PID file (/usr/local/mysql-5.7.24/data/localhost.localdomain.pid).
 // 创建配置文件中的日志目录及日志文件,并将所有者设置为mysql,设置权限
 [root@localhost mysql-5.7.24]# mkdir /var/log/mariadb
 [root@localhost mysql-5.7.24]# vim /var/log/mariadb/mariadb.log
 [root@localhost mysql-5.7.24]# chown -R mysql /var/log/
 [root@localhost mysql-5.7.24]# chmod -R 777 /var/log/
 [root@localhost mysql-5.7.24]# service mysqld start
Starting MySQL... SUCCESS! 
// 输入密码为初始化的密码
[root@localhost mysql-5.7.24]# mysql -u root -p
Enter password: 

你可能感兴趣的:(mysql)