MySQL5.7 二进制安装

解压MySQL5.7二进制包

[root@localhost tmp]# tar -zxvf mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz

[root@localhost tmp]# tar -zxvf mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz

将解压后的文件放到指定目录

[root@localhost tmp]# mv mysql-5.7.25-linux-glibc2.12-x86_64 /usr/local/mysql

*注意* 目录"/usr/local/mysql"必须不存在,否则会被拷贝到此目录下

查看文件是否拷贝完全

[root@localhost tmp]# ll /usr/local/mysql
total 40
drwxr-xr-x  2 mysql mysql  4096 Mar 14 22:11 bin
-rw-r--r--  1 mysql mysql 17987 Dec 21 18:39 COPYING
drwxr-xr-x  2 mysql mysql    55 Mar 14 22:11 docs
drwxr-xr-x  3 mysql mysql  4096 Mar 14 22:10 include
drwxr-xr-x  5 mysql mysql  4096 Mar 14 22:11 lib
drwxr-xr-x  4 mysql mysql    30 Mar 14 22:11 man
-rw-r--r--  1 mysql mysql  2478 Dec 21 18:39 README
drwxr-xr-x 28 mysql mysql  4096 Mar 14 22:11 share
drwxr-xr-x  2 mysql mysql    90 Mar 14 22:11 support-files

创建mysql用户

[root@localhost tmp]# useradd mysql

创建所需目录并更改属主和属组

[root@localhost tmp]# mkdir -p /data/mysql/data
[root@localhost tmp]# mkdir -p /data/mysql/logs
[root@localhost tmp]# chown mysql:mysql -R /data
[root@localhost tmp]# chown mysql:mysql -R /usr/local/mysql

编辑参数文件

[root@localhost tmp]# cat > /etc/my.cnf < EOF

配置环境变量

[root@localhost tmp]# vim /home/mysql/.bash_profile

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

MYSQL_HOME=/usr/local/mysql

PATH=$MYSQL_HOME/bin:$PATH:$HOME/.local/bin:$HOME/bin

export PATH


[root@localhost tmp]# . /home/mysql/.bash_profile

初始化

[root@localhost tmp]# /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --initialize-insecure --basedir=/usr/local/mysql --datadir=/data/mysql/data --user=mysql

启动mysqld实例

[root@localhost tmp]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql &

登录到mysql添加密码

[root@localhost tmp]# /usr/local/mysql/bin/mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.25-log MySQL Community Server (GPL)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

[root@localhost][(none)]> grant all on *.* to root@localhost identified by "root";
Query OK, 0 rows affected, 2 warnings (5.01 sec)

[root@localhost][(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

 

你可能感兴趣的:(MySQL5.7 二进制安装)